Skip to content

Commit f5aa542

Browse files
jbrockmendeljreback
authored andcommitted
TST: add tzaware case to indices fixture (#31241)
1 parent 9a4cf3b commit f5aa542

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

pandas/tests/indexes/common.py

+14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from pandas._libs.tslib import iNaT
88

9+
from pandas.core.dtypes.common import is_datetime64tz_dtype
910
from pandas.core.dtypes.dtypes import CategoricalDtype
1011

1112
import pandas as pd
@@ -301,6 +302,9 @@ def test_ensure_copied_data(self, indices):
301302

302303
index_type = type(indices)
303304
result = index_type(indices.values, copy=True, **init_kwargs)
305+
if is_datetime64tz_dtype(indices.dtype):
306+
result = result.tz_localize("UTC").tz_convert(indices.tz)
307+
304308
tm.assert_index_equal(indices, result)
305309
tm.assert_numpy_array_equal(
306310
indices._ndarray_values, result._ndarray_values, check_same="copy"
@@ -464,6 +468,11 @@ def test_intersection_base(self, indices):
464468
intersect = first.intersection(second)
465469
assert tm.equalContents(intersect, second)
466470

471+
if is_datetime64tz_dtype(indices.dtype):
472+
# The second.values below will drop tz, so the rest of this test
473+
# is not applicable.
474+
return
475+
467476
# GH 10149
468477
cases = [klass(second.values) for klass in [np.array, Series, list]]
469478
for case in cases:
@@ -482,6 +491,11 @@ def test_union_base(self, indices):
482491
union = first.union(second)
483492
assert tm.equalContents(union, everything)
484493

494+
if is_datetime64tz_dtype(indices.dtype):
495+
# The second.values below will drop tz, so the rest of this test
496+
# is not applicable.
497+
return
498+
485499
# GH 10149
486500
cases = [klass(second.values) for klass in [np.array, Series, list]]
487501
for case in cases:

pandas/tests/indexes/conftest.py

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"unicode": tm.makeUnicodeIndex(100),
88
"string": tm.makeStringIndex(100),
99
"datetime": tm.makeDateIndex(100),
10+
"datetime-tz": tm.makeDateIndex(100, tz="US/Pacific"),
1011
"period": tm.makePeriodIndex(100),
1112
"timedelta": tm.makeTimedeltaIndex(100),
1213
"int": tm.makeIntIndex(100),

pandas/tests/indexes/test_numpy_compat.py

+3
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ def test_numpy_ufuncs_other(indices, func):
8181

8282
idx = indices
8383
if isinstance(idx, (DatetimeIndex, TimedeltaIndex)):
84+
if isinstance(idx, DatetimeIndex) and idx.tz is not None:
85+
if func in [np.isfinite, np.isnan, np.isinf]:
86+
pytest.xfail(reason="__array_ufunc__ is not defined")
8487

8588
if not _np_version_under1p18 and func in [np.isfinite, np.isinf, np.isnan]:
8689
# numpy 1.18(dev) changed isinf and isnan to not raise on dt64/tfd64

0 commit comments

Comments
 (0)