-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Address latest pandas-related upstream test failures #9081
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
Changes from 4 commits
891fd6e
bd875d3
616c179
1a3bdf6
334d118
36a005a
85c95a1
d181b97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we have this pattern in multiple modules, it might be worth adding the code as a special context manager to from contextlib import contextmanager
import warnings
@contextmanager
def ignore_warnings(category=None, pattern=None):
if category is None and pattern is None:
raise ValueError("need at least one of category and pattern")
try:
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message=pattern, category=category)
yield
finally:
pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks—I ended up switching to marking these tests with |
||
assert_identical(da, roundtripped) | ||
|
||
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: | |
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: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I can tell, whether |
||
labels = reference_dates[0:1] * 2 + reference_dates[1:2] * 2 | ||
ind = xr.DataArray( | ||
labels, coords=dict(time=times), dims="time", name="reference_date" | ||
|
@@ -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) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use of |
||
|
||
self.darray = darray | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ | |
assert_equal, | ||
assert_identical, | ||
assert_no_warnings, | ||
has_pandas_3, | ||
raise_if_dask_computes, | ||
requires_bottleneck, | ||
requires_cupy, | ||
|
@@ -256,7 +257,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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is needed since |
||
for times in [ | ||
[expected[i] for i in range(10)], | ||
[expected[i : (i + 1)] for i in range(10)], | ||
|
@@ -2942,8 +2945,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), has_pandas_3), | ||
(np.array([datetime(2000, 1, 1)]), has_pandas_3), | ||
Comment on lines
+2947
to
+2948
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With pandas 3, |
||
(pd.date_range("2000", periods=1, tz=pytz.timezone("America/New_York")), False), | ||
( | ||
pd.Series( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pandas.to_datetime
will infer the precision from the input in pandas 3, so we explicitly specify the desired precision now.