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

iris.coords.Coord() gives me a TypeError #3967

Closed
valeriupredoi opened this issue Jan 28, 2021 · 8 comments
Closed

iris.coords.Coord() gives me a TypeError #3967

valeriupredoi opened this issue Jan 28, 2021 · 8 comments
Assignees
Labels
Good First Issue A good issue to take on if you're just getting started with Iris development Type: Documentation
Milestone

Comments

@valeriupredoi
Copy link

📰 Custom Issue

Hey guys, me again 😁 Silly question - I have this snippet:

import iris
print(iris.__version__)
import numpy as np

lat_coord = iris.coords.Coord(
    np.linspace(-90.0, 90.0, 100), var_name='lat',
    standard_name='latitude', long_name='latitude', units='degrees')

and in iris=3.0.1 gives me this malarkey:

/home/valeriu/miniconda3/envs/iris31/lib/python3.9/site-packages/iris/config.py:139: UserWarning: Ignoring config item 'Resources':'test_data_dir' (section:option) as '/home/h05/itwl/projects/git/iris-test-data/test_data' is not a valid directory path.
  warnings.warn(msg.format(section, option, c_path))
3.0.1
Traceback (most recent call last):
  File "/home/valeriu/ESMValTool/testcoord.py", line 5, in <module>
    lat_coord = iris.coords.Coord(
TypeError: Can't instantiate abstract class Coord with abstract method __init__

and in iris=2.4.0 it runs a-ok, with no warnings. First off, I don't understand the warning, it seems to be pointing to a location that's got nothing to do with me 😁 Second, why is it not constructing my coordinate? Looking at the latest documentation it seems support should be as previous version? Cheers muchly in advance, as usual, for great support 🍺

@bjlittle
Copy link
Member

bjlittle commented Jan 28, 2021

@valeriupredoi This is now the correct behavour.

The iris.coords.Coord is a base class and has now been made abstract i.e., you cannot create an instance of it, because you shouldn't.

Prior to iris 3.0.0 that wasn't the case. Essentially up to iris 2.4.0 we were allowing you to do the wrong thing. We've disallowed that now, for very good reasons.

You can only create a iris.coords.DimCoord or a iris.coords.AuxCoord. That's is.

@bjlittle
Copy link
Member

@valeriupredoi Does this help?

So either do:

lat_coord = iris.coords.DimCoord(
    np.linspace(-90.0, 90.0, 100), var_name='lat',
    standard_name='latitude', long_name='latitude', units='degrees')

or:

lat_coord = iris.coords.AuxCoord(
    np.linspace(-90.0, 90.0, 100), var_name='lat',
    standard_name='latitude', long_name='latitude', units='degrees')

@valeriupredoi
Copy link
Author

terrific! Cheers muchly @bjlittle - I would encourage you to either remove it from the latest API documentation or mention this explicitily there, I looked for this and the first point of entry was the API documentation 👍

@bjlittle
Copy link
Member

@valeriupredoi Will do - anything to stop confusion 👍

@bjlittle
Copy link
Member

I'll keep this issue open until it's followed up with a suitable documentation change to clarify the abstract base class nature of iris.coords.Coord since iris 3.0.0

@bjlittle bjlittle added this to the v3.1.0 milestone Jan 28, 2021
@valeriupredoi
Copy link
Author

great! this is a pretty well-used function and changing its behaviour should have a few bright neon lights attached to it - at least for people like me that always forget the API and consult the manual oftentimes 😁

@bjlittle bjlittle added Good First Issue A good issue to take on if you're just getting started with Iris development and removed Status: Won't Fix labels Jan 28, 2021
@bjlittle
Copy link
Member

@valeriupredoi This issue has been closed by #3971.

The iris.coords.Coord doc-string has been updated to provide clarification that it is an abstract base class, and it is not possible to create an instance of it 👍

@valeriupredoi
Copy link
Author

cheers @bjlittle 🍺

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue A good issue to take on if you're just getting started with Iris development Type: Documentation
Projects
None yet
Development

No branches or pull requests

2 participants