-
Notifications
You must be signed in to change notification settings - Fork 23
Raise ValueError upon attempt to create data-less Data
#491
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
Raise ValueError upon attempt to create data-less Data
#491
Conversation
davidhassell
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good. Thanks.
| # case of 'default' Data i.e. if no parameters are specified. | ||
| cf.Data(0, "s") | ||
| cf.Data(array=np.arange(5)) | ||
| cf.Data(source=self.filename) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An interesting choice of source (i.e. a string), but it certainly proves the test :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I didn't realise this was an abnormal usage! What is a source argument meant to be, precisely (a file handle or similar I am guessing based on a quick look at some other usage across the codebase?). It's not actually documented (specifically, no type given or indicated) right now:
Lines 300 to 304 in d9d34be
| source: optional | |
| Initialize the data values and metadata (such as | |
| units, mask hardness, etc.) from the data of | |
| *source*. All other arguments, with the exception of | |
| *copy*, are ignored. |
so maybe we can update that docstring description now in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Sadie, source can be anything that sufficiently duck types to the class of the object being instantiated. "Sufficiently" meaning that it'll take what it can and ignore what it can't, hence setting it to a string doesn't fail - it just doesn't provide much content (strings don't have dask arrays, etc.). It very commonly used in copy methods, which set source=self.
All cfdm and cf-python classes have a source parameter (because they all inherit from cfdm.core.Container, which has one), so we should perhaps consider improving this docstring in another PR ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying David. That all makes sense.
... so we should perhaps consider improving this docstring in another PR ...
Good idea. I'll raise an Issue linking to this thread, update the line in question to specify something normal and sensible for the source parameter, and merge the PR.
|
(One of the CI jobs has failed due to multiple |
Closes #378.