Skip to content

Commit 56c8b84

Browse files
committed
catch warning
1 parent 83f3ca1 commit 56c8b84

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

pandas/tests/indexing/test_coercion.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,7 @@ def test_replace_series_datetime_tz(self, how, to_key, from_key, replacer):
11771177
assert obj.dtype == from_key
11781178

11791179
result = obj.replace(replacer)
1180+
11801181
exp = pd.Series(self.rep[to_key], index=index, name="yyy")
11811182
assert exp.dtype == to_key
11821183

@@ -1197,7 +1198,21 @@ def test_replace_series_datetime_datetime(self, how, to_key, from_key, replacer)
11971198
obj = pd.Series(self.rep[from_key], index=index, name="yyy")
11981199
assert obj.dtype == from_key
11991200

1200-
result = obj.replace(replacer)
1201+
warn = None
1202+
rep_ser = pd.Series(replacer)
1203+
if (
1204+
isinstance(obj.dtype, pd.DatetimeTZDtype)
1205+
and isinstance(rep_ser.dtype, pd.DatetimeTZDtype)
1206+
and obj.dtype != rep_ser.dtype
1207+
):
1208+
# mismatched tz DatetimeArray behavior will change to cast
1209+
# for setitem-like methods with mismatched tzs
1210+
warn = FutureWarning
1211+
1212+
msg = "explicitly cast to object"
1213+
with tm.assert_produces_warning(warn, match=msg):
1214+
result = obj.replace(replacer)
1215+
12011216
exp = pd.Series(self.rep[to_key], index=index, name="yyy")
12021217
assert exp.dtype == to_key
12031218

0 commit comments

Comments
 (0)