|
9 | 9 | import pytest
|
10 | 10 |
|
11 | 11 | import xarray as xr
|
12 |
| -from xarray.tests import has_pandas_3 |
13 | 12 |
|
14 | 13 | pytest.importorskip("hypothesis")
|
15 | 14 | import hypothesis.extra.numpy as npst # isort:skip
|
|
25 | 24 |
|
26 | 25 | numeric_series = numeric_dtypes.flatmap(lambda dt: pdst.series(dtype=dt))
|
27 | 26 |
|
| 27 | + |
| 28 | +@st.composite |
| 29 | +def dataframe_strategy(draw): |
| 30 | + tz = draw(st.timezones()) |
| 31 | + dtype = pd.DatetimeTZDtype(unit="ns", tz=tz) |
| 32 | + |
| 33 | + datetimes = st.datetimes( |
| 34 | + min_value=pd.Timestamp("1677-09-21T00:12:43.145224193"), |
| 35 | + max_value=pd.Timestamp("2262-04-11T23:47:16.854775807"), |
| 36 | + timezones=st.just(tz), |
| 37 | + ) |
| 38 | + |
| 39 | + df = pdst.data_frames( |
| 40 | + [ |
| 41 | + pdst.column("datetime_col", elements=datetimes), |
| 42 | + pdst.column("other_col", elements=st.integers()), |
| 43 | + ], |
| 44 | + index=pdst.range_indexes(min_size=1, max_size=10), |
| 45 | + ) |
| 46 | + return draw(df).astype({"datetime_col": dtype}) |
| 47 | + |
| 48 | + |
28 | 49 | an_array = npst.arrays(
|
29 | 50 | dtype=numeric_dtypes,
|
30 | 51 | shape=npst.array_shapes(max_dims=2), # can only convert 1D/2D to pandas
|
31 | 52 | )
|
32 | 53 |
|
33 | 54 |
|
34 |
| -datetime_with_tz_strategy = st.datetimes(timezones=st.timezones()) |
35 |
| -dataframe_strategy = pdst.data_frames( |
36 |
| - [ |
37 |
| - pdst.column("datetime_col", elements=datetime_with_tz_strategy), |
38 |
| - pdst.column("other_col", elements=st.integers()), |
39 |
| - ], |
40 |
| - index=pdst.range_indexes(min_size=1, max_size=10), |
41 |
| -) |
42 |
| - |
43 |
| - |
44 | 55 | @st.composite
|
45 | 56 | def datasets_1d_vars(draw) -> xr.Dataset:
|
46 | 57 | """Generate datasets with only 1D variables
|
@@ -111,11 +122,7 @@ def test_roundtrip_pandas_dataframe(df) -> None:
|
111 | 122 | xr.testing.assert_identical(arr, roundtripped.to_xarray())
|
112 | 123 |
|
113 | 124 |
|
114 |
| -@pytest.mark.skipif( |
115 |
| - has_pandas_3, |
116 |
| - reason="fails to roundtrip on pandas 3 (see https://github.com/pydata/xarray/issues/9098)", |
117 |
| -) |
118 |
| -@given(df=dataframe_strategy) |
| 125 | +@given(df=dataframe_strategy()) |
119 | 126 | def test_roundtrip_pandas_dataframe_datetime(df) -> None:
|
120 | 127 | # Need to name the indexes, otherwise Xarray names them 'dim_0', 'dim_1'.
|
121 | 128 | df.index.name = "rows"
|
|
0 commit comments