From 26bfde954c369a6a0fb5097925e8a3f7b1e6035b Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 22 Jan 2020 21:35:39 -0800 Subject: [PATCH 1/2] TST: add tzaware case to indices fixture --- pandas/tests/indexes/common.py | 14 ++++++++++++++ pandas/tests/indexes/conftest.py | 1 + pandas/tests/indexes/test_numpy_compat.py | 3 +++ 3 files changed, 18 insertions(+) diff --git a/pandas/tests/indexes/common.py b/pandas/tests/indexes/common.py index f3ebe8313d0c6..dbfa39ef690f5 100644 --- a/pandas/tests/indexes/common.py +++ b/pandas/tests/indexes/common.py @@ -6,6 +6,7 @@ from pandas._libs.tslib import iNaT +from pandas.core.dtypes.common import is_datetime64tz_dtype from pandas.core.dtypes.dtypes import CategoricalDtype import pandas as pd @@ -301,6 +302,9 @@ def test_ensure_copied_data(self, indices): index_type = type(indices) result = index_type(indices.values, copy=True, **init_kwargs) + if is_datetime64tz_dtype(indices.dtype): + result = result.tz_localize("UTC").tz_convert(indices.tz) + tm.assert_index_equal(indices, result) tm.assert_numpy_array_equal( indices._ndarray_values, result._ndarray_values, check_same="copy" @@ -464,6 +468,11 @@ def test_intersection_base(self, indices): intersect = first.intersection(second) assert tm.equalContents(intersect, second) + if is_datetime64tz_dtype(indices.dtype): + # The second.values below will drop tz, so the rest of this test + # is not applicable. + return + # GH 10149 cases = [klass(second.values) for klass in [np.array, Series, list]] for case in cases: @@ -482,6 +491,11 @@ def test_union_base(self, indices): union = first.union(second) assert tm.equalContents(union, everything) + if is_datetime64tz_dtype(indices.dtype): + # The second.values below will drop tz, so the rest of this test + # is not applicable. + return + # GH 10149 cases = [klass(second.values) for klass in [np.array, Series, list]] for case in cases: diff --git a/pandas/tests/indexes/conftest.py b/pandas/tests/indexes/conftest.py index b1dcf0ed9b44b..8e0366138f71e 100644 --- a/pandas/tests/indexes/conftest.py +++ b/pandas/tests/indexes/conftest.py @@ -7,6 +7,7 @@ "unicode": tm.makeUnicodeIndex(100), "string": tm.makeStringIndex(100), "datetime": tm.makeDateIndex(100), + "datetime-tz": tm.makeDateIndex(100, tz="US/Pacific"), "period": tm.makePeriodIndex(100), "timedelta": tm.makeTimedeltaIndex(100), "int": tm.makeIntIndex(100), diff --git a/pandas/tests/indexes/test_numpy_compat.py b/pandas/tests/indexes/test_numpy_compat.py index 583556656ac87..654a84bd5d59c 100644 --- a/pandas/tests/indexes/test_numpy_compat.py +++ b/pandas/tests/indexes/test_numpy_compat.py @@ -81,6 +81,9 @@ def test_numpy_ufuncs_other(indices, func): idx = indices if isinstance(idx, (DatetimeIndex, TimedeltaIndex)): + if isinstance(idx, DatetimeIndex) and idx.tz is not None: + if func is np.isfinite: + pytest.xfail(reason="__array_ufunc__ is not defined") if not _np_version_under1p18 and func in [np.isfinite, np.isinf, np.isnan]: # numpy 1.18(dev) changed isinf and isnan to not raise on dt64/tfd64 From 32c744f4e95e04e1f336fbe25d9ec5337a463c1a Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 22 Jan 2020 21:54:42 -0800 Subject: [PATCH 2/2] npdev fix --- pandas/tests/indexes/test_numpy_compat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/indexes/test_numpy_compat.py b/pandas/tests/indexes/test_numpy_compat.py index 654a84bd5d59c..7051f2b02fe03 100644 --- a/pandas/tests/indexes/test_numpy_compat.py +++ b/pandas/tests/indexes/test_numpy_compat.py @@ -82,7 +82,7 @@ def test_numpy_ufuncs_other(indices, func): idx = indices if isinstance(idx, (DatetimeIndex, TimedeltaIndex)): if isinstance(idx, DatetimeIndex) and idx.tz is not None: - if func is np.isfinite: + if func in [np.isfinite, np.isnan, np.isinf]: pytest.xfail(reason="__array_ufunc__ is not defined") if not _np_version_under1p18 and func in [np.isfinite, np.isinf, np.isnan]: