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

tests for datasets with units #3447

Merged
merged 22 commits into from
Nov 9, 2019
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
53fea49
start writing the tests for dataset
keewis Oct 25, 2019
3cf2c7d
add tests for initializing Datasets
keewis Oct 26, 2019
93e75fe
add tests for aggregation methods / functions
keewis Oct 27, 2019
9591245
add tests for the ndarray methods / properties
keewis Oct 27, 2019
c84cb75
add tests for missing value handling methods
keewis Oct 29, 2019
a7891cb
add tests for comparison methods
keewis Oct 29, 2019
26c9eb9
add tests for reordering / stacking
keewis Oct 29, 2019
7eee944
add tests for indexing methods
keewis Oct 30, 2019
ad661cc
remove the commented out xfail on Dataset.squeeze
keewis Oct 30, 2019
eac43d1
add tests for head, tail and thin
keewis Oct 30, 2019
58b097a
add tests for the computation methods
keewis Oct 30, 2019
7cf5fa7
add tests for grouped operations
keewis Oct 30, 2019
f5ec8f7
Merge branch 'master' into tests-for-datasets-with-units
keewis Oct 30, 2019
1bdcf90
add tests for the content manipulation methods
keewis Oct 30, 2019
ce80520
fix reindex_like to actually expect errors where appropriate
keewis Oct 30, 2019
aac55eb
use DataArray.copy to replicate a DataArray with different data
keewis Oct 30, 2019
8081f20
add tests for repr / str
keewis Oct 30, 2019
ebb8672
remove the comment about moving the merge tests
keewis Oct 30, 2019
8be37be
construct a new data array instead of using `copy`
keewis Nov 4, 2019
10a06e0
Merge branch 'master' into tests-for-datasets-with-units
keewis Nov 7, 2019
1a7d878
update whats-new.rst
keewis Nov 7, 2019
7ab5e49
Merge branch 'master' into tests-for-datasets-with-units
keewis Nov 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add tests for head, tail and thin
keewis committed Oct 30, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit eac43d1cdffaae1fb2c4d42fb50e53b9e2b13e46
55 changes: 55 additions & 0 deletions xarray/tests/test_units.py
Original file line number Diff line number Diff line change
@@ -2685,6 +2685,61 @@ def test_loc(self, values, units, error, dtype):
result = ds.loc[{"x": values_with_units}]
assert_equal_with_units(expected, result)

@pytest.mark.xfail(
reason="indexes strip units and head / tail / thin only support integers"
)
@pytest.mark.parametrize(
"unit,error",
(
pytest.param(1, DimensionalityError, id="no_unit"),
pytest.param(
unit_registry.dimensionless, DimensionalityError, id="dimensionless"
),
pytest.param(unit_registry.s, DimensionalityError, id="incompatible_unit"),
pytest.param(unit_registry.cm, None, id="compatible_unit"),
pytest.param(unit_registry.m, None, id="identical_unit"),
),
)
@pytest.mark.parametrize(
"func",
(
method("head", x=7, y=3, z=6),
method("tail", x=7, y=3, z=6),
method("thin", x=7, y=3, z=6),
),
ids=repr,
)
def test_head_tail_thin(self, func, unit, error, dtype):
array1 = np.linspace(1, 2, 10 * 5).reshape(10, 5) * unit_registry.degK
array2 = np.linspace(1, 2, 10 * 8).reshape(10, 8) * unit_registry.Pa

coords = {
"x": np.arange(10) * unit_registry.m,
"y": np.arange(5) * unit_registry.m,
"z": np.arange(8) * unit_registry.m,
}

ds = xr.Dataset(
data_vars={
"a": xr.DataArray(data=array1, dims=("x", "y")),
"b": xr.DataArray(data=array2, dims=("x", "z")),
},
coords=coords,
)

kwargs = {name: value * unit for name, value in func.kwargs.items()}

if error is not None:
with pytest.raises(error):
func(ds, **kwargs)

return

expected = attach_units(func(strip_units(ds)), extract_units(ds))
result = func(ds, **kwargs)

assert_equal_with_units(expected, result)

@pytest.mark.parametrize(
"shape",
(