Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
andersy005 committed Jul 26, 2023
1 parent 07c9301 commit 5a9f36f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 67 deletions.
40 changes: 15 additions & 25 deletions xarray/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import numpy as np
import pandas as pd
from packaging.version import Version

try:
if sys.version_info >= (3, 11):
Expand Down Expand Up @@ -248,27 +247,18 @@ def copy(
]


if Version(np.__version__) >= Version("1.22.0"):
QuantileMethods = Literal[
"inverted_cdf",
"averaged_inverted_cdf",
"closest_observation",
"interpolated_inverted_cdf",
"hazen",
"weibull",
"linear",
"median_unbiased",
"normal_unbiased",
"lower",
"higher",
"midpoint",
"nearest",
]
else:
QuantileMethods = Literal[ # type: ignore[misc]
"linear",
"lower",
"higher",
"midpoint",
"nearest",
]
QuantileMethods = Literal[
"inverted_cdf",
"averaged_inverted_cdf",
"closest_observation",
"interpolated_inverted_cdf",
"hazen",
"weibull",
"linear",
"median_unbiased",
"normal_unbiased",
"lower",
"higher",
"midpoint",
"nearest",
]
8 changes: 1 addition & 7 deletions xarray/tests/test_cftimeindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import numpy as np
import pandas as pd
import pytest
from packaging.version import Version

import xarray as xr
from xarray.coding.cftimeindex import (
Expand All @@ -33,12 +32,7 @@
# cftime 1.5.2 renames "gregorian" to "standard"
standard_or_gregorian = ""
if has_cftime:
import cftime

if Version(cftime.__version__) >= Version("1.5.2"):
standard_or_gregorian = "standard"
else:
standard_or_gregorian = "gregorian"
standard_or_gregorian = "standard"


def date_dict(year=None, month=None, day=None, hour=None, minute=None, second=None):
Expand Down
5 changes: 1 addition & 4 deletions xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -2848,10 +2848,7 @@ def test_quantile_method(self, method) -> None:
q = [0.25, 0.5, 0.75]
actual = DataArray(self.va).quantile(q, method=method)

if Version(np.__version__) >= Version("1.22.0"):
expected = np.nanquantile(self.dv.values, np.array(q), method=method)
else:
expected = np.nanquantile(self.dv.values, np.array(q), interpolation=method)
expected = np.nanquantile(self.dv.values, np.array(q), method=method)

np.testing.assert_allclose(actual.values, expected)

Expand Down
9 changes: 0 additions & 9 deletions xarray/tests/test_distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import numpy as np
import pytest
from packaging.version import Version

if TYPE_CHECKING:
import dask
Expand Down Expand Up @@ -194,10 +193,6 @@ def test_dask_distributed_zarr_integration_test(
assert_allclose(original, computed)


@pytest.mark.xfail(
condition=Version(distributed.__version__) < Version("2022.02.0"),
reason="https://github.com/dask/distributed/pull/5739",
)
@gen_cluster(client=True)
async def test_async(c, s, a, b) -> None:
x = create_test_data()
Expand Down Expand Up @@ -230,10 +225,6 @@ def test_hdf5_lock() -> None:
assert isinstance(HDF5_LOCK, dask.utils.SerializableLock)


@pytest.mark.xfail(
condition=Version(distributed.__version__) < Version("2022.02.0"),
reason="https://github.com/dask/distributed/pull/5739",
)
@gen_cluster(client=True)
async def test_serializable_locks(c, s, a, b) -> None:
def f(x, lock=None):
Expand Down
17 changes: 0 additions & 17 deletions xarray/tests/test_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import numpy as np
import pandas as pd
import pytest
from packaging.version import Version

import xarray as xr
from xarray import DataArray, Dataset, set_options
Expand Down Expand Up @@ -391,14 +390,6 @@ class TestDataArrayRollingExp:
@pytest.mark.parametrize("backend", ["numpy"], indirect=True)
@pytest.mark.parametrize("func", ["mean", "sum"])
def test_rolling_exp_runs(self, da, dim, window_type, window, func) -> None:
import numbagg

if (
Version(getattr(numbagg, "__version__", "0.1.0")) < Version("0.2.1")
and func == "sum"
):
pytest.skip("rolling_exp.sum requires numbagg 0.2.1")

da = da.where(da > 0.2)

rolling_exp = da.rolling_exp(window_type=window_type, **{dim: window})
Expand Down Expand Up @@ -430,14 +421,6 @@ def test_rolling_exp_mean_pandas(self, da, dim, window_type, window) -> None:
@pytest.mark.parametrize("backend", ["numpy"], indirect=True)
@pytest.mark.parametrize("func", ["mean", "sum"])
def test_rolling_exp_keep_attrs(self, da, func) -> None:
import numbagg

if (
Version(getattr(numbagg, "__version__", "0.1.0")) < Version("0.2.1")
and func == "sum"
):
pytest.skip("rolling_exp.sum requires numbagg 0.2.1")

attrs = {"attrs": "da"}
da.attrs = attrs

Expand Down
6 changes: 1 addition & 5 deletions xarray/tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import pandas as pd
import pytest
import pytz
from packaging.version import Version

from xarray import DataArray, Dataset, IndexVariable, Variable, set_options
from xarray.core import dtypes, duck_array_ops, indexing
Expand Down Expand Up @@ -1832,10 +1831,7 @@ def test_quantile_method(self, method, use_dask) -> None:
q = np.array([0.25, 0.5, 0.75])
actual = v.quantile(q, dim="y", method=method)

if Version(np.__version__) >= Version("1.22"):
expected = np.nanquantile(self.d, q, axis=1, method=method)
else:
expected = np.nanquantile(self.d, q, axis=1, interpolation=method)
expected = np.nanquantile(self.d, q, axis=1, method=method)

if use_dask:
assert isinstance(actual.data, dask_array_type)
Expand Down

0 comments on commit 5a9f36f

Please sign in to comment.