Skip to content

Conversation

@sadielbartholomew
Copy link
Member

Closes #378.

Copy link
Collaborator

@davidhassell davidhassell left a 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)
Copy link
Collaborator

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 :)

Copy link
Member Author

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:

cf-python/cf/data/data.py

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?

Copy link
Collaborator

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 ...

Copy link
Member Author

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.

@sadielbartholomew
Copy link
Member Author

(One of the CI jobs has failed due to multiple OSError: Can't read non-existent file type errors, which seems unrelated so I will look into separately.)

@sadielbartholomew sadielbartholomew merged commit 09fdb71 into NCAS-CMS:lama-to-dask Nov 10, 2022
@sadielbartholomew sadielbartholomew deleted the lama-to-dask-empty-data-i378 branch November 10, 2022 13:39
@davidhassell davidhassell added this to the 3.14.0 milestone Nov 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants