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..7051f2b02fe03 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 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]: # numpy 1.18(dev) changed isinf and isnan to not raise on dt64/tfd64