Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: move iris.cube.Cube to iris.Cube #891

Open
shoyer opened this issue Dec 17, 2013 · 10 comments
Open

Proposal: move iris.cube.Cube to iris.Cube #891

shoyer opened this issue Dec 17, 2013 · 10 comments

Comments

@shoyer
Copy link
Contributor

shoyer commented Dec 17, 2013

I find myself constructing a lot of cubes and cubelists manually when I implement new functions to manipulate cubes.

Since these are core API objects, I suggest they should be moved from iris.cube.Cube and iris.cube.CubeList to iris.Cube and iris.CubeList (via an import statement in /lib/iris/__init__.py). This would be consistent with many other Python libraries (e.g., Pandas), for which the core API is also usually exposed at the top level.

As a library user, it's just easier not to need to know about the structure of Iris's code to find a class or function. I can see a case for consolidating other functions into a broader namespace as well, but Cube and CubeList are the worse offenders (in my view). In my view, exposing submodules in a library's API should be done with caution, and only when it is clearly easier for library users.

@pelson
Copy link
Member

pelson commented Dec 18, 2013

I can see the benefit of doing this, but the real problem for me is documenting it. Perhaps if iris.Cube existed in our documentation and simply linked to the iris.cube.Cube documentation then that might be a way to go.

Other than that, nice suggestion - it is something that has crossed my mind more than once.

@esc24
Copy link
Member

esc24 commented Dec 18, 2013

It's crossed my mind too. iris.Constraint comes to mind as an example where we've done it. I know shapely does this kind of thing (e.g. shapely.geometry.Polygon and shapely.geometry.polygon.Polygon). However, I find this confusing and I like namespaces. I'm wary of there not being one and only one obvious way to do it. That said, if we keep the list of top level objects to an absolute minimum I can see why it's appealing.

@shoyer
Copy link
Contributor Author

shoyer commented Dec 18, 2013

I think the multiple paths is pretty common and unlikely to be confusing as long as the documentation keeps things straight. For example, you can also find np.array in np.core.multiarray.array.

I agree that the main challenge here is documentation, so perhaps I will leave this to those more familiar with Iris's documentation generator. It should definitely be possible to document iris.Cube and not iris.cube.Cube, since so many other packages manage to do it. The code patch will simply be adding from iris.cube import Cube, CubeList, CubeMetadata to /lib/iris/__init__.py (and adding them to the __all__ list).

@rhattersley
Copy link
Member

The code patch will simply be adding from iris.cube import Cube, CubeList, CubeMetadata to /lib/iris/init.py (and adding them to the all list).

I was concerned about circular imports (they've bitten us before!) but I gave it a quick go and it was fine.

@bblay
Copy link
Contributor

bblay commented Jan 22, 2014

👍 nicer code

@trexfeathers trexfeathers added the Good First Issue A good issue to take on if you're just getting started with Iris development label Sep 25, 2020
@rcomer rcomer mentioned this issue Jun 4, 2021
@rcomer
Copy link
Member

rcomer commented Oct 2, 2021

Do we still want to do this? Intuitively, it would undo some of the import speed gains from #4174.

@trexfeathers
Copy link
Contributor

Do we still want to do this? Intuitively, it would undo some of the import speed gains from #4174.

It seems unlikely that this desire is limited to Cube. We've previously discussed making all commonly used API available at the top level, taking inspiration from Numpy (#3429 (comment)).

So I don't think this can be easily dismissed, nor can it be easily completed!

@rcomer rcomer removed the Good First Issue A good issue to take on if you're just getting started with Iris development label Oct 5, 2021
@pp-mo
Copy link
Member

pp-mo commented Oct 6, 2021

@trexfeathers it would undo some of the import speed gains from #4174.

I don't think this is a practical issue in itself : If you're using Iris at all, you will be using cubes, so the additional cost of "import iris.cube" is one that every reasonable usage will get anyway.
The only difference is in the "headline figure" import time : for me, that goes from ~0.1 secs to ~0.6secs.

Test timings on my machine :

imports timing
import iris 0.1 secs
import iris.coords 0.4 secs
import iris.cube 0.7 secs
import iris.cube; import iris.coords 0.7 secs

@trexfeathers
Copy link
Contributor

Part of a larger conversation:

Copy link
Contributor

In order to maintain a backlog of relevant issues, we automatically label them as stale after 500 days of inactivity.

If this issue is still important to you, then please comment on this issue and the stale label will be removed.

Otherwise this issue will be automatically closed in 28 days time.

@github-actions github-actions bot added the Stale A stale issue/pull-request label Apr 26, 2024
@trexfeathers trexfeathers removed the Stale A stale issue/pull-request label Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

9 participants