Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,7 @@
pass

def test_encoding_kwarg_dates(self) -> None:
ds = Dataset({"t": pd.date_range("2000-01-01", periods=3)})
ds = Dataset({"t": pd.date_range("2000-01-01", periods=3, unit="ns")})
units = "days since 1900-01-01"
kwargs = dict(encoding={"t": {"units": units}})
with self.roundtrip(ds, save_kwargs=kwargs) as actual:
Expand Down Expand Up @@ -6574,7 +6574,7 @@
session.cache.clear()
url = "https://test.opendap.org/opendap/hyrax/data/nc/coads_climatology.nc"

ds = open_dataset(

Check failure on line 6577 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313 (flaky)

test_batchdap4_downloads[dap4] Failed: Timeout (>180.0s) from pytest-timeout.

Check failure on line 6577 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313 (flaky)

test_batchdap4_downloads[dap2] Failed: Timeout (>180.0s) from pytest-timeout.
url.replace("https", protocol),
session=session,
engine="pydap",
Expand Down
14 changes: 10 additions & 4 deletions xarray/tests/test_cftimeindex_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
)
from xarray.coding.cftimeindex import CFTimeIndex
from xarray.core.resample_cftime import CFTimeGrouper
from xarray.core.types import PDDatetimeUnitOptions
from xarray.tests import has_pandas_3

cftime = pytest.importorskip("cftime")
Expand Down Expand Up @@ -141,7 +142,7 @@ def test_resample_with_tick_resample_freq(freqs, closed, label, offset) -> None:
origin = "start"

datetime_index = pd.date_range(
start=start, periods=5, freq=_new_to_legacy_freq(initial_freq)
start=start, periods=5, freq=_new_to_legacy_freq(initial_freq), unit="ns"
)
cftime_index = xr.date_range(
start=start, periods=5, freq=initial_freq, use_cftime=True
Expand Down Expand Up @@ -178,7 +179,7 @@ def test_resample_with_non_tick_resample_freq(freqs, closed, label) -> None:
origin = "start_day"

datetime_index = pd.date_range(
start=start, periods=5, freq=_new_to_legacy_freq(initial_freq)
start=start, periods=5, freq=_new_to_legacy_freq(initial_freq), unit="ns"
)
cftime_index = xr.date_range(
start=start, periods=5, freq=initial_freq, use_cftime=True
Expand Down Expand Up @@ -231,7 +232,9 @@ def test_calendars(calendar: str) -> None:
calendar=calendar,
use_cftime=True,
)
pd_index = pd.date_range(start="2004-01-01T12:07:01", periods=7, freq="3D")
pd_index = pd.date_range(
start="2004-01-01T12:07:01", periods=7, freq="3D", unit="ns"
)
da_cftime = da(xr_index).resample(time=freq, closed=closed, label=label).mean()
da_datetime = da(pd_index).resample(time=freq, closed=closed, label=label).mean()
# TODO (benbovy - flexible indexes): update when CFTimeIndex is a xarray Index subclass
Expand All @@ -245,6 +248,7 @@ class DateRangeKwargs(TypedDict):
start: str
periods: int
freq: str
unit: PDDatetimeUnitOptions


@pytest.mark.parametrize("closed", ["left", "right"])
Expand All @@ -256,7 +260,9 @@ class DateRangeKwargs(TypedDict):
def test_origin(closed, origin) -> None:
initial_freq, resample_freq = ("3h", "9h")
start = "1969-12-31T12:07:01"
index_kwargs: DateRangeKwargs = dict(start=start, periods=12, freq=initial_freq)
index_kwargs: DateRangeKwargs = dict(
start=start, periods=12, freq=initial_freq, unit="ns"
)
datetime_index = pd.date_range(**index_kwargs)
cftime_index = xr.date_range(**index_kwargs, use_cftime=True)
da_datetimeindex = da(datetime_index)
Expand Down
4 changes: 2 additions & 2 deletions xarray/tests/test_conventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def test_dataset(self) -> None:
expected = Dataset(
{"foo": ("t", [0, 0, 0], {"units": "bar"})},
{
"t": pd.date_range("2000-01-01", periods=3),
"t": pd.date_range("2000-01-01", periods=3, unit="ns"),
"y": ("t", [5.0, 10.0, np.nan]),
},
)
Expand Down Expand Up @@ -422,7 +422,7 @@ def test_decode_cf_with_drop_variables(self) -> None:
)
expected = Dataset(
{
"t": pd.date_range("2000-01-01", periods=3),
"t": pd.date_range("2000-01-01", periods=3, unit="ns"),
"foo": (
("t", "x"),
[[0, 0, 0], [1, 1, 1], [2, 2, 2]],
Expand Down
4 changes: 2 additions & 2 deletions xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -7002,7 +7002,7 @@ def test_to_and_from_iris(self) -> None:
# to iris
coord_dict: dict[Hashable, Any] = {}
coord_dict["distance"] = ("distance", [-2, 2], {"units": "meters"})
coord_dict["time"] = ("time", pd.date_range("2000-01-01", periods=3))
coord_dict["time"] = ("time", pd.date_range("2000-01-01", periods=3, unit="ns"))
coord_dict["height"] = 10
coord_dict["distance2"] = ("distance", [0, 1], {"foo": "bar"})
coord_dict["time2"] = (("distance", "time"), [[0, 1, 2], [2, 3, 4]])
Expand Down Expand Up @@ -7073,7 +7073,7 @@ def test_to_and_from_iris_dask(self) -> None:

coord_dict: dict[Hashable, Any] = {}
coord_dict["distance"] = ("distance", [-2, 2], {"units": "meters"})
coord_dict["time"] = ("time", pd.date_range("2000-01-01", periods=3))
coord_dict["time"] = ("time", pd.date_range("2000-01-01", periods=3, unit="ns"))
coord_dict["height"] = 10
coord_dict["distance2"] = ("distance", [0, 1], {"foo": "bar"})
coord_dict["time2"] = (("distance", "time"), [[0, 1, 2], [2, 3, 4]])
Expand Down
12 changes: 7 additions & 5 deletions xarray/tests/test_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import xarray as xr
from xarray.core import formatting
from xarray.core.indexes import Index
from xarray.tests import requires_cftime, requires_dask, requires_netCDF4
from xarray.tests import has_pandas_3, requires_cftime, requires_dask, requires_netCDF4


class CustomIndex(Index):
Expand Down Expand Up @@ -297,6 +297,7 @@ def test_diff_array_repr(self) -> None:
)

byteorder = "<" if sys.byteorder == "little" else ">"
str_dtype = "str" if has_pandas_3 else "object"
expected = dedent(
f"""\
Left and right DataArray objects are not identical
Expand All @@ -317,8 +318,8 @@ def test_diff_array_repr(self) -> None:
label (x) int64 16B 1 2
Indexes only on the left object: ['y']
Differing indexes:
L x Index(['a', 'b'], dtype='object', name='x')
R x Index(['a', 'c'], dtype='object', name='x')
L x Index(['a', 'b'], dtype='{str_dtype}', name='x')
R x Index(['a', 'c'], dtype='{str_dtype}', name='x')
Differing attributes:
L units: m
R units: kg
Expand Down Expand Up @@ -501,6 +502,7 @@ def test_diff_dataset_repr(self) -> None:
)

byteorder = "<" if sys.byteorder == "little" else ">"
str_dtype = "str" if has_pandas_3 else "object"
expected = dedent(
f"""\
Left and right Dataset objects are not identical
Expand All @@ -525,8 +527,8 @@ def test_diff_dataset_repr(self) -> None:
var2 (x) int64 16B 3 4
Indexes only on the left object: ['y']
Differing indexes:
L x Index(['a', 'b'], dtype='object', name='x')
R x Index(['a', 'c'], dtype='object', name='x')
L x Index(['a', 'b'], dtype='{str_dtype}', name='x')
R x Index(['a', 'c'], dtype='{str_dtype}', name='x')
Differing attributes:
L title: mytitle
R title: newtitle
Expand Down
Loading