Skip to content

Commit ed23adc

Browse files
committed
Address more warnings
1 parent 891fd6e commit ed23adc

File tree

5 files changed

+18
-14
lines changed

5 files changed

+18
-14
lines changed

xarray/tests/test_backends.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ def test_roundtrip_string_encoded_characters(self) -> None:
529529
assert actual["x"].encoding["_Encoding"] == "ascii"
530530

531531
def test_roundtrip_numpy_datetime_data(self) -> None:
532-
times = pd.to_datetime(["2000-01-01", "2000-01-02", "NaT"])
532+
times = pd.to_datetime(["2000-01-01", "2000-01-02", "NaT"], unit="ns")
533533
expected = Dataset({"t": ("t", times), "t0": times[0]})
534534
kwargs = {"encoding": {"t0": {"units": "days since 1950-01-01"}}}
535535
with self.roundtrip(expected, save_kwargs=kwargs) as actual:

xarray/tests/test_dataarray.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -3647,7 +3647,9 @@ def test_to_and_from_dict_with_time_dim(self) -> None:
36473647
t = pd.date_range("20130101", periods=10)
36483648
lat = [77.7, 83.2, 76]
36493649
da = DataArray(x, {"t": t, "lat": lat}, dims=["t", "lat"])
3650-
roundtripped = DataArray.from_dict(da.to_dict())
3650+
with warnings.catch_warnings():
3651+
warnings.filterwarnings("ignore", message="Converting non-nanosecond")
3652+
roundtripped = DataArray.from_dict(da.to_dict())
36513653
assert_identical(da, roundtripped)
36523654

36533655
def test_to_and_from_dict_with_nan_nat(self) -> None:
@@ -3657,7 +3659,9 @@ def test_to_and_from_dict_with_nan_nat(self) -> None:
36573659
t[2] = np.nan
36583660
lat = [77.7, 83.2, 76]
36593661
da = DataArray(y, {"t": t, "lat": lat}, dims=["t", "lat"])
3660-
roundtripped = DataArray.from_dict(da.to_dict())
3662+
with warnings.catch_warnings():
3663+
warnings.filterwarnings("ignore", message="Converting non-nanosecond")
3664+
roundtripped = DataArray.from_dict(da.to_dict())
36613665
assert_identical(da, roundtripped)
36623666

36633667
def test_to_dict_with_numpy_attrs(self) -> None:

xarray/tests/test_groupby.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ def test_groupby_da_datetime() -> None:
139139
times = pd.date_range("2000-01-01", periods=4)
140140
foo = xr.DataArray([1, 2, 3, 4], coords=dict(time=times), dims="time")
141141
# create test index
142-
dd = times.to_pydatetime()
143-
reference_dates = [dd[0], dd[2]]
142+
reference_dates = [times[0], times[2]]
144143
labels = reference_dates[0:1] * 2 + reference_dates[1:2] * 2
145144
ind = xr.DataArray(
146145
labels, coords=dict(time=times), dims="time", name="reference_date"
@@ -566,7 +565,7 @@ def test_da_groupby_assign_coords() -> None:
566565
coords={
567566
"z": ["a", "b", "c", "a", "b", "c"],
568567
"x": [1, 1, 1, 2, 2, 3, 4, 5, 3, 4],
569-
"t": xr.date_range("2001-01-01", freq="ME", periods=24, use_cftime=False),
568+
"t": xr.date_range("2001-01-01", freq="MS", periods=24, use_cftime=False),
570569
"month": ("t", list(range(1, 13)) * 2),
571570
},
572571
)
@@ -1881,7 +1880,7 @@ def test_resample_first(self) -> None:
18811880
array = Dataset({"time": times})["time"]
18821881
actual = array.resample(time="1D").last()
18831882
expected_times = pd.to_datetime(
1884-
["2000-01-01T18", "2000-01-02T18", "2000-01-03T06"]
1883+
["2000-01-01T18", "2000-01-02T18", "2000-01-03T06"], unit="ns"
18851884
)
18861885
expected = DataArray(expected_times, [("time", times[::4])], name="time")
18871886
assert_identical(expected, actual)

xarray/tests/test_plot.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import math
66
from collections.abc import Generator, Hashable
77
from copy import copy
8-
from datetime import date, datetime, timedelta
8+
from datetime import date, timedelta
99
from typing import Any, Callable, Literal
1010

1111
import numpy as np
@@ -2912,9 +2912,8 @@ def setUp(self) -> None:
29122912
"""
29132913
month = np.arange(1, 13, 1)
29142914
data = np.sin(2 * np.pi * month / 12.0)
2915-
2916-
darray = DataArray(data, dims=["time"])
2917-
darray.coords["time"] = np.array([datetime(2017, m, 1) for m in month])
2915+
times = pd.date_range(start="2017-01-01", freq="ME", periods=12)
2916+
darray = DataArray(data, dims=["time"], coords=[times])
29182917

29192918
self.darray = darray
29202919

xarray/tests/test_variable.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,9 @@ def test_index_and_concat_datetime(self):
256256
# regression test for #125
257257
date_range = pd.date_range("2011-09-01", periods=10)
258258
for dates in [date_range, date_range.values, date_range.to_pydatetime()]:
259-
expected = self.cls("t", dates)
259+
with warnings.catch_warnings():
260+
warnings.filterwarnings("ignore", message="Converting non-nanosecond")
261+
expected = self.cls("t", dates)
260262
for times in [
261263
[expected[i] for i in range(10)],
262264
[expected[i : (i + 1)] for i in range(10)],
@@ -2942,8 +2944,8 @@ def test_from_pint_wrapping_dask(self, Var):
29422944
(np.array([np.datetime64("2000-01-01", "ns")]), False),
29432945
(np.array([np.datetime64("2000-01-01", "s")]), True),
29442946
(pd.date_range("2000", periods=1), False),
2945-
(datetime(2000, 1, 1), False),
2946-
(np.array([datetime(2000, 1, 1)]), False),
2947+
(datetime(2000, 1, 1), True),
2948+
(np.array([datetime(2000, 1, 1)]), True),
29472949
(pd.date_range("2000", periods=1, tz=pytz.timezone("America/New_York")), False),
29482950
(
29492951
pd.Series(

0 commit comments

Comments
 (0)