Skip to content

Commit

Permalink
Address more warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerkclark committed Jun 9, 2024
1 parent 891fd6e commit ed23adc
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ def test_roundtrip_string_encoded_characters(self) -> None:
assert actual["x"].encoding["_Encoding"] == "ascii"

def test_roundtrip_numpy_datetime_data(self) -> None:
times = pd.to_datetime(["2000-01-01", "2000-01-02", "NaT"])
times = pd.to_datetime(["2000-01-01", "2000-01-02", "NaT"], unit="ns")
expected = Dataset({"t": ("t", times), "t0": times[0]})
kwargs = {"encoding": {"t0": {"units": "days since 1950-01-01"}}}
with self.roundtrip(expected, save_kwargs=kwargs) as actual:
Expand Down
8 changes: 6 additions & 2 deletions xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -3647,7 +3647,9 @@ def test_to_and_from_dict_with_time_dim(self) -> None:
t = pd.date_range("20130101", periods=10)
lat = [77.7, 83.2, 76]
da = DataArray(x, {"t": t, "lat": lat}, dims=["t", "lat"])
roundtripped = DataArray.from_dict(da.to_dict())
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message="Converting non-nanosecond")
roundtripped = DataArray.from_dict(da.to_dict())
assert_identical(da, roundtripped)

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

def test_to_dict_with_numpy_attrs(self) -> None:
Expand Down
7 changes: 3 additions & 4 deletions xarray/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ def test_groupby_da_datetime() -> None:
times = pd.date_range("2000-01-01", periods=4)
foo = xr.DataArray([1, 2, 3, 4], coords=dict(time=times), dims="time")
# create test index
dd = times.to_pydatetime()
reference_dates = [dd[0], dd[2]]
reference_dates = [times[0], times[2]]
labels = reference_dates[0:1] * 2 + reference_dates[1:2] * 2
ind = xr.DataArray(
labels, coords=dict(time=times), dims="time", name="reference_date"
Expand Down Expand Up @@ -566,7 +565,7 @@ def test_da_groupby_assign_coords() -> None:
coords={
"z": ["a", "b", "c", "a", "b", "c"],
"x": [1, 1, 1, 2, 2, 3, 4, 5, 3, 4],
"t": xr.date_range("2001-01-01", freq="ME", periods=24, use_cftime=False),
"t": xr.date_range("2001-01-01", freq="MS", periods=24, use_cftime=False),
"month": ("t", list(range(1, 13)) * 2),
},
)
Expand Down Expand Up @@ -1881,7 +1880,7 @@ def test_resample_first(self) -> None:
array = Dataset({"time": times})["time"]
actual = array.resample(time="1D").last()
expected_times = pd.to_datetime(
["2000-01-01T18", "2000-01-02T18", "2000-01-03T06"]
["2000-01-01T18", "2000-01-02T18", "2000-01-03T06"], unit="ns"
)
expected = DataArray(expected_times, [("time", times[::4])], name="time")
assert_identical(expected, actual)
Expand Down
7 changes: 3 additions & 4 deletions xarray/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import math
from collections.abc import Generator, Hashable
from copy import copy
from datetime import date, datetime, timedelta
from datetime import date, timedelta
from typing import Any, Callable, Literal

import numpy as np
Expand Down Expand Up @@ -2912,9 +2912,8 @@ def setUp(self) -> None:
"""
month = np.arange(1, 13, 1)
data = np.sin(2 * np.pi * month / 12.0)

darray = DataArray(data, dims=["time"])
darray.coords["time"] = np.array([datetime(2017, m, 1) for m in month])
times = pd.date_range(start="2017-01-01", freq="ME", periods=12)
darray = DataArray(data, dims=["time"], coords=[times])

self.darray = darray

Expand Down
8 changes: 5 additions & 3 deletions xarray/tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ def test_index_and_concat_datetime(self):
# regression test for #125
date_range = pd.date_range("2011-09-01", periods=10)
for dates in [date_range, date_range.values, date_range.to_pydatetime()]:
expected = self.cls("t", dates)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message="Converting non-nanosecond")
expected = self.cls("t", dates)
for times in [
[expected[i] for i in range(10)],
[expected[i : (i + 1)] for i in range(10)],
Expand Down Expand Up @@ -2942,8 +2944,8 @@ def test_from_pint_wrapping_dask(self, Var):
(np.array([np.datetime64("2000-01-01", "ns")]), False),
(np.array([np.datetime64("2000-01-01", "s")]), True),
(pd.date_range("2000", periods=1), False),
(datetime(2000, 1, 1), False),
(np.array([datetime(2000, 1, 1)]), False),
(datetime(2000, 1, 1), True),
(np.array([datetime(2000, 1, 1)]), True),
(pd.date_range("2000", periods=1, tz=pytz.timezone("America/New_York")), False),
(
pd.Series(
Expand Down

0 comments on commit ed23adc

Please sign in to comment.