From 399324a5fadf3dd8e5756f40e3242dbd6bfe9884 Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 7 Dec 2021 12:44:00 -0800 Subject: [PATCH 1/3] TST: fix 217 incorrect skips --- pandas/core/indexes/datetimelike.py | 2 -- pandas/tests/arrays/test_datetimelike.py | 16 ++++++++++------ pandas/tests/scalar/test_nat.py | 4 ++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index 104bce0369d37..731efdc3b17f0 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -92,8 +92,6 @@ class DatetimeIndexOpsMixin(NDArrayBackedExtensionIndex): freq: BaseOffset | None freqstr: str | None _resolution_obj: Resolution - _bool_ops: list[str] = [] - _field_ops: list[str] = [] # error: "Callable[[Any], Any]" has no attribute "fget" hasnans = cast( diff --git a/pandas/tests/arrays/test_datetimelike.py b/pandas/tests/arrays/test_datetimelike.py index a5d622b78ff39..7484fdccf4937 100644 --- a/pandas/tests/arrays/test_datetimelike.py +++ b/pandas/tests/arrays/test_datetimelike.py @@ -814,7 +814,7 @@ def test_to_period_2d(self, arr1d): expected = arr1d.to_period("D").reshape(1, -1) tm.assert_period_array_equal(result, expected) - @pytest.mark.parametrize("propname", DatetimeIndex._bool_ops) + @pytest.mark.parametrize("propname", DatetimeArray._bool_ops) def test_bool_properties(self, arr1d, propname): # in this case _bool_ops is just `is_leap_year` dti = self.index_cls(arr1d) @@ -826,16 +826,20 @@ def test_bool_properties(self, arr1d, propname): tm.assert_numpy_array_equal(result, expected) - @pytest.mark.parametrize("propname", DatetimeIndex._field_ops) + @pytest.mark.parametrize("propname", DatetimeArray._field_ops) def test_int_properties(self, arr1d, propname): + warn = None + msg = "weekofyear and week have been deprecated, please use" if propname in ["week", "weekofyear"]: # GH#33595 Deprecate week and weekofyear - return + warn = FutureWarning + dti = self.index_cls(arr1d) arr = arr1d - result = getattr(arr, propname) - expected = np.array(getattr(dti, propname), dtype=result.dtype) + with tm.assert_produces_warning(warn, match=msg): + result = getattr(arr, propname) + expected = np.array(getattr(dti, propname), dtype=result.dtype) tm.assert_numpy_array_equal(result, expected) @@ -979,7 +983,7 @@ def test_total_seconds(self, timedelta_index): tm.assert_numpy_array_equal(result, expected.values) - @pytest.mark.parametrize("propname", TimedeltaIndex._field_ops) + @pytest.mark.parametrize("propname", TimedeltaArray._field_ops) def test_int_properties(self, timedelta_index, propname): tdi = timedelta_index arr = TimedeltaArray(tdi) diff --git a/pandas/tests/scalar/test_nat.py b/pandas/tests/scalar/test_nat.py index f2c2985827a4f..cfb3b504f7a79 100644 --- a/pandas/tests/scalar/test_nat.py +++ b/pandas/tests/scalar/test_nat.py @@ -38,7 +38,7 @@ "nat,idx", [ (Timestamp("NaT"), DatetimeArray), - (Timedelta("NaT"), TimedeltaIndex), + (Timedelta("NaT"), TimedeltaArray), (Period("NaT", freq="M"), PeriodArray), ], ) @@ -68,7 +68,7 @@ def test_nat_fields(nat, idx): def test_nat_vector_field_access(): idx = DatetimeIndex(["1/1/2000", None, None, "1/4/2000"]) - for field in DatetimeIndex._field_ops: + for field in DatetimeArray._field_ops: # weekday is a property of DTI, but a method # on NaT/Timestamp for compat with datetime if field == "weekday": From 0edb3ee358e6c84fcee4731c799aff8065846c14 Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 7 Dec 2021 16:15:08 -0800 Subject: [PATCH 2/3] Fix kludge for 32 bit/windows --- pandas/tests/extension/base/dim2.py | 36 +++++++++++------------------ 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/pandas/tests/extension/base/dim2.py b/pandas/tests/extension/base/dim2.py index aebb6233ba777..d86d43b0ef9e6 100644 --- a/pandas/tests/extension/base/dim2.py +++ b/pandas/tests/extension/base/dim2.py @@ -5,12 +5,9 @@ import pytest from pandas._libs.missing import is_matching_na -from pandas.compat import ( - IS64, - is_platform_windows, -) import pandas as pd +from pandas.core.arrays.integer import INT_STR_TO_DTYPE from pandas.tests.extension.base.base import BaseExtensionTests @@ -203,29 +200,22 @@ def test_reductions_2d_axis0(self, data, method, request): else: raise AssertionError("Both reductions should raise or neither") + def get_reduction_result_dtype(dtype): + # windows and 32bit builds will in some cases have int32/uint32 + # where other builds will have int64/uint64. + if dtype.itemsize == 8: + return dtype + elif dtype.kind in "ib": + return INT_STR_TO_DTYPE[np.dtype(int).name] + else: + # i.e. dtype.kind == "u" + return INT_STR_TO_DTYPE[np.dtype(np.uint).name] + if method in ["mean", "median", "sum", "prod"]: # std and var are not dtype-preserving expected = data if method in ["sum", "prod"] and data.dtype.kind in "iub": - # FIXME: kludge - if data.dtype.kind in ["i", "b"]: - if is_platform_windows() or not IS64: - # FIXME: kludge for 32bit builds - if result.dtype.itemsize == 4: - dtype = pd.Int32Dtype() - else: - dtype = pd.Int64Dtype() - else: - dtype = pd.Int64Dtype() - elif data.dtype.kind == "u": - if is_platform_windows() or not IS64: - # FIXME: kludge for 32bit builds - if result.dtype.itemsize == 4: - dtype = pd.UInt32Dtype() - else: - dtype = pd.UInt64Dtype() - else: - dtype = pd.UInt64Dtype() + dtype = get_reduction_result_dtype(data.dtype) expected = data.astype(dtype) if data.dtype.kind == "b" and method in ["sum", "prod"]: From 50bb84edf12e43db921095c63fa2fa4bb914ecc0 Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 7 Dec 2021 16:36:19 -0800 Subject: [PATCH 3/3] comment --- pandas/tests/arrays/floating/test_construction.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/arrays/floating/test_construction.py b/pandas/tests/arrays/floating/test_construction.py index 7749e138ccbea..169b23c31f863 100644 --- a/pandas/tests/arrays/floating/test_construction.py +++ b/pandas/tests/arrays/floating/test_construction.py @@ -61,6 +61,7 @@ def test_floating_array_disallows_float16(request): ): # the locale condition may need to be refined; this fails on # the CI in the ZH_CN build + # https://github.com/numpy/numpy/issues/20512 mark = pytest.mark.xfail(reason="numpy does not raise on np.dtype('Float16')") request.node.add_marker(mark)