-
Notifications
You must be signed in to change notification settings - Fork 229
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
Changes from 2 commits
10a7333
4cf80a9
69cf33d
13ec03f
6d1e93f
e80215a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -222,30 +222,72 @@ def data_kind( | |
|
||
Examples | ||
-------- | ||
>>> import io | ||
>>> from pathlib import Path | ||
>>> import numpy as np | ||
>>> import pandas as pd | ||
>>> import xarray as xr | ||
>>> import pathlib | ||
>>> import io | ||
>>> data_kind(data=None) | ||
'vectors' | ||
>>> data_kind(data=np.arange(10).reshape((5, 2))) | ||
'matrix' | ||
>>> data_kind(data="my-data-file.txt") | ||
'file' | ||
>>> data_kind(data=pathlib.Path("my-data-file.txt")) | ||
'file' | ||
|
||
The "arg" kind: | ||
|
||
>>> [data_kind(data=data, required=False) for data in (2, 2.0, True, False)] | ||
['arg', 'arg', 'arg', 'arg'] | ||
>>> data_kind(data=None, required=False) | ||
'arg' | ||
>>> data_kind(data=2.0, required=False) | ||
'arg' | ||
>>> data_kind(data=True, required=False) | ||
'arg' | ||
>>> data_kind(data=xr.DataArray(np.random.rand(4, 3))) | ||
|
||
The "file" kind: | ||
|
||
>>> [data_kind(data=data) for data in ("file.txt", ("file1.txt", "file2.txt"))] | ||
['file', 'file'] | ||
>>> data_kind(data=Path("file.txt")) | ||
'file' | ||
>>> data_kind(data=(Path("file1.txt", "file2.txt"))) | ||
'file' | ||
|
||
The "grid" kind: | ||
|
||
>>> data_kind(data=xr.DataArray(np.random.rand(4, 3))) # 2-D xarray.DataArray | ||
'grid' | ||
>>> 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' | ||
Comment on lines
+249
to
252
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We already recognize an
Logic could be something like |
||
>>> data_kind(data=xr.DataArray(np.random.rand(3, 4, 5))) | ||
|
||
The "image" kind: | ||
|
||
>>> data_kind(data=xr.DataArray(np.random.rand(3, 4, 5))) # 3-D xarray.DataArray | ||
'image' | ||
|
||
The "stringio"`` kind: | ||
|
||
>>> data_kind(data=io.StringIO("TEXT1\nTEXT23\n")) | ||
'stringio' | ||
|
||
The "matrix"`` kind: | ||
|
||
>>> data_kind(data=np.arange(10)) # 1-D numpy.ndarray | ||
'matrix' | ||
>>> data_kind(data=np.arange(10).reshape((5, 2))) # 2-D numpy.ndarray | ||
'matrix' | ||
>>> data_kind(data=np.arange(60).reshape((3, 4, 5))) # 3-D numpy.ndarray | ||
'matrix' | ||
>>> data_kind(xr.DataArray(np.arange(12), name="x").to_dataset()) # xarray.Dataset | ||
'matrix' | ||
>>> data_kind(data=[1, 2, 3]) # 1-D sequence | ||
'matrix' | ||
>>> data_kind(data=[[1, 2, 3], [4, 5, 6]]) # sequence of sequences | ||
'matrix' | ||
>>> data_kind(data={"x": [1, 2, 3], "y": [4, 5, 6]}) # dictionary | ||
'matrix' | ||
>>> data_kind(data=pd.DataFrame({"x": [1, 2, 3], "y": [4, 5, 6]})) # pd.DataFrame | ||
'matrix' | ||
>>> data_kind(data=pd.Series([1, 2, 3], name="x")) # pd.Series | ||
'matrix' | ||
|
||
The "vectors" kind: | ||
|
||
>>> data_kind(data=None) | ||
'vectors' | ||
""" | ||
kind: Literal[ | ||
"arg", "file", "geojson", "grid", "image", "matrix", "stringio", "vectors" | ||
|
Uh oh!
There was an error while loading. Please reload this page.