-
Notifications
You must be signed in to change notification settings - Fork 234
data_kind: Add more tests to demonstrate the data kind of various data types #3480
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
Conversation
8021279 to
649469a
Compare
649469a to
10a7333
Compare
| >>> data_kind(data=xr.DataArray(np.arange(12))) # 1-D xarray.DataArray | ||
| 'grid' | ||
| >>> data_kind(data=xr.DataArray(np.random.rand(2, 3, 4, 5))) # 4-D xarray.DataArray | ||
| 'grid' |
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.
Erm, do we need tests to check that 1-D and 4-D xarray.DataArray are counted as grid?
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.
Not neccessary. These doctests are added to understand the current behavior of the data_kind function.
I feel 1-D xarray.DataArray should be considered as a vector and 4-D xarray.DataArray should not be recognized and we should raise an exception. Will refactor the data_kind function in a separate 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.
I feel 1-D xarray.DataArray should be considered as a vector
We already recognize an xr.Dataset composed of 1-D xarray.DataArrays as a matrix (can be treated similarly as multiple 'columns' in a Dataframe). I don't think we need to expand this logic, since they users can call .data on a 1-D xarray.DataArray to get a numpy.ndarray that can then be passed to the data parameter.
4-D xarray.DataArray should not be recognized and we should raise an exception
Logic could be something like if dataarray.ndim() >= 4: raise Error, but I don't think this is really necessary since an error would be raised by the PyGMT module anyway right?
Co-authored-by: Wei Ji <[email protected]>
weiji14
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.
Pre-approving since most of this looks good. There's some discussion about whether to check 1-D/4-D xarray.DataArrays at #3480 (comment), but not very critical and can be handled later with the actual code refactor.
Description of proposed changes
Just add more tests to help us understand the current behavior of the
data_kindfunction.As can be seen, many data types are recognized as "matrix" and
data=Noneis recognized as "vectors". Sometimes, the result data kind is counterintuitive, as first mentioned in #3351, #3369 and #2744.This PR only focuses on adding tests. Will refactor the data_kind function in separate PRs.
Please let me if there are other data types that should be tested.