|
37 | 37 | assert_identical, |
38 | 38 | assert_no_warnings, |
39 | 39 | has_dask_ge_2024_11_0, |
| 40 | + has_pandas_3, |
40 | 41 | raise_if_dask_computes, |
41 | 42 | requires_bottleneck, |
42 | 43 | requires_cupy, |
@@ -208,8 +209,11 @@ def test_index_0d_datetime(self): |
208 | 209 | x = self.cls(["x"], [np.datetime64(d)]) |
209 | 210 | self._assertIndexedLikeNDArray(x, np.datetime64(d), "datetime64[us]") |
210 | 211 |
|
| 212 | + expected_unit = "us" if has_pandas_3 else "ns" |
211 | 213 | x = self.cls(["x"], pd.DatetimeIndex([d])) |
212 | | - self._assertIndexedLikeNDArray(x, np.datetime64(d), "datetime64[ns]") |
| 214 | + self._assertIndexedLikeNDArray( |
| 215 | + x, np.datetime64(d), f"datetime64[{expected_unit}]" |
| 216 | + ) |
213 | 217 |
|
214 | 218 | def test_index_0d_timedelta64(self): |
215 | 219 | td = timedelta(hours=1) |
@@ -283,7 +287,10 @@ def test_0d_time_data(self): |
283 | 287 | (dt64_data.values.astype("datetime64[m]"), "s"), |
284 | 288 | (dt64_data.values.astype("datetime64[s]"), "s"), |
285 | 289 | (dt64_data.values.astype("datetime64[ps]"), "ns"), |
286 | | - (dt64_data.to_pydatetime(), "ns"), |
| 290 | + ( |
| 291 | + dt64_data.to_pydatetime(), |
| 292 | + "us" if has_pandas_3 else "ns", |
| 293 | + ), |
287 | 294 | ], |
288 | 295 | ) |
289 | 296 | def test_datetime64_conversion(self, values, unit): |
@@ -1071,8 +1078,14 @@ def test_numpy_same_methods(self): |
1071 | 1078 | "values, unit", |
1072 | 1079 | [ |
1073 | 1080 | (np.datetime64("2000-01-01"), "s"), |
1074 | | - (pd.Timestamp("2000-01-01T00"), "ns"), |
1075 | | - (datetime(2000, 1, 1), "ns"), |
| 1081 | + ( |
| 1082 | + pd.Timestamp("2000-01-01T00"), |
| 1083 | + "s" if has_pandas_3 else "ns", |
| 1084 | + ), |
| 1085 | + ( |
| 1086 | + datetime(2000, 1, 1), |
| 1087 | + "us" if has_pandas_3 else "ns", |
| 1088 | + ), |
1076 | 1089 | (np.datetime64("2000-01-01T00:00:00.1234567891"), "ns"), |
1077 | 1090 | ], |
1078 | 1091 | ) |
@@ -1109,8 +1122,9 @@ def test_0d_str(self): |
1109 | 1122 |
|
1110 | 1123 | def test_0d_datetime(self): |
1111 | 1124 | v = Variable([], pd.Timestamp("2000-01-01")) |
1112 | | - assert v.dtype == np.dtype("datetime64[ns]") |
1113 | | - assert v.values == np.datetime64("2000-01-01", "ns") |
| 1125 | + expected_unit = "s" if has_pandas_3 else "ns" |
| 1126 | + assert v.dtype == np.dtype(f"datetime64[{expected_unit}]") |
| 1127 | + assert v.values == np.datetime64("2000-01-01", expected_unit) |
1114 | 1128 |
|
1115 | 1129 | @pytest.mark.parametrize( |
1116 | 1130 | "values, unit", [(pd.to_timedelta("1s"), "ns"), (np.timedelta64(1, "s"), "s")] |
@@ -2654,11 +2668,14 @@ def test_datetime(self): |
2654 | 2668 | assert np.dtype("datetime64[ns]") == actual.dtype |
2655 | 2669 | assert expected is source_ndarray(np.asarray(actual)) |
2656 | 2670 |
|
2657 | | - expected = np.datetime64("2000-01-01", "ns") |
| 2671 | + expected = np.datetime64( |
| 2672 | + "2000-01-01", |
| 2673 | + "us" if has_pandas_3 else "ns", |
| 2674 | + ) |
2658 | 2675 | actual = as_compatible_data(datetime(2000, 1, 1)) |
2659 | 2676 | assert np.asarray(expected) == actual |
2660 | 2677 | assert np.ndarray is type(actual) |
2661 | | - assert np.dtype("datetime64[ns]") == actual.dtype |
| 2678 | + assert expected.dtype == actual.dtype |
2662 | 2679 |
|
2663 | 2680 | def test_tz_datetime(self) -> None: |
2664 | 2681 | tz = pytz.timezone("America/New_York") |
@@ -2980,8 +2997,14 @@ def test_from_pint_wrapping_dask(self, Var): |
2980 | 2997 | (np.array([np.datetime64("2000-01-01", "ns")]), "ns"), |
2981 | 2998 | (np.array([np.datetime64("2000-01-01", "s")]), "s"), |
2982 | 2999 | (pd.date_range("2000", periods=1), "ns"), |
2983 | | - (datetime(2000, 1, 1), "ns"), |
2984 | | - (np.array([datetime(2000, 1, 1)]), "ns"), |
| 3000 | + ( |
| 3001 | + datetime(2000, 1, 1), |
| 3002 | + "us" if has_pandas_3 else "ns", |
| 3003 | + ), |
| 3004 | + ( |
| 3005 | + np.array([datetime(2000, 1, 1)]), |
| 3006 | + "us" if has_pandas_3 else "ns", |
| 3007 | + ), |
2985 | 3008 | (pd.date_range("2000", periods=1, tz=pytz.timezone("America/New_York")), "ns"), |
2986 | 3009 | ( |
2987 | 3010 | pd.Series( |
|
0 commit comments