Skip to content

TST: add tzaware case to indices fixture #31241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pandas/tests/indexes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/indexes/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 3 additions & 0 deletions pandas/tests/indexes/test_numpy_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down