Skip to content

Commit 00f10db

Browse files
authored
DEPR: correct warning message while parsing datetimes with mixed time zones if utc=False (pandas-dev#55611)
* correct message for parsing datetimes with mixed time zones * correct tests
1 parent af5fa36 commit 00f10db

File tree

7 files changed

+20
-20
lines changed

7 files changed

+20
-20
lines changed

pandas/_libs/tslib.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ cdef _array_to_datetime_object(
668668
if len(unique_timezones) > 1:
669669
warnings.warn(
670670
"In a future version of pandas, parsing datetimes with mixed time "
671-
"zones will raise a warning unless `utc=True`. "
671+
"zones will raise an error unless `utc=True`. "
672672
"Please specify `utc=True` to opt in to the new behaviour "
673673
"and silence this warning. To create a `Series` with mixed offsets and "
674674
"`object` dtype, please use `apply` and `datetime.datetime.strptime`",

pandas/core/tools/datetimes.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def _return_parsed_timezone_results(
356356
if len(non_na_timezones) > 1:
357357
warnings.warn(
358358
"In a future version of pandas, parsing datetimes with mixed time "
359-
"zones will raise a warning unless `utc=True`. Please specify `utc=True` "
359+
"zones will raise an error unless `utc=True`. Please specify `utc=True` "
360360
"to opt in to the new behaviour and silence this warning. "
361361
"To create a `Series` with mixed offsets and `object` dtype, "
362362
"please use `apply` and `datetime.datetime.strptime`",
@@ -788,7 +788,7 @@ def to_datetime(
788788
.. warning::
789789
790790
In a future version of pandas, parsing datetimes with mixed time
791-
zones will raise a warning unless `utc=True`.
791+
zones will raise an error unless `utc=True`.
792792
Please specify `utc=True` to opt in to the new behaviour
793793
and silence this warning. To create a `Series` with mixed offsets and
794794
`object` dtype, please use `apply` and `datetime.datetime.strptime`.
@@ -1023,7 +1023,7 @@ def to_datetime(
10231023
>>> pd.to_datetime(['2020-10-25 02:00 +0200',
10241024
... '2020-10-25 04:00 +0100']) # doctest: +SKIP
10251025
FutureWarning: In a future version of pandas, parsing datetimes with mixed
1026-
time zones will raise a warning unless `utc=True`. Please specify `utc=True`
1026+
time zones will raise an error unless `utc=True`. Please specify `utc=True`
10271027
to opt in to the new behaviour and silence this warning. To create a `Series`
10281028
with mixed offsets and `object` dtype, please use `apply` and
10291029
`datetime.datetime.strptime`.
@@ -1037,7 +1037,7 @@ def to_datetime(
10371037
>>> pd.to_datetime(["2020-01-01 01:00:00-01:00",
10381038
... datetime(2020, 1, 1, 3, 0)]) # doctest: +SKIP
10391039
FutureWarning: In a future version of pandas, parsing datetimes with mixed
1040-
time zones will raise a warning unless `utc=True`. Please specify `utc=True`
1040+
time zones will raise an error unless `utc=True`. Please specify `utc=True`
10411041
to opt in to the new behaviour and silence this warning. To create a `Series`
10421042
with mixed offsets and `object` dtype, please use `apply` and
10431043
`datetime.datetime.strptime`.

pandas/io/json/_json.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,7 @@ def _try_convert_to_date(self, data):
13261326
warnings.filterwarnings(
13271327
"ignore",
13281328
".*parsing datetimes with mixed time "
1329-
"zones will raise a warning",
1329+
"zones will raise an error",
13301330
category=FutureWarning,
13311331
)
13321332
new_data = to_datetime(new_data, errors="raise", unit=date_unit)

pandas/io/parsers/base_parser.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ def converter(*date_cols, col: Hashable):
11471147
with warnings.catch_warnings():
11481148
warnings.filterwarnings(
11491149
"ignore",
1150-
".*parsing datetimes with mixed time zones will raise a warning",
1150+
".*parsing datetimes with mixed time zones will raise an error",
11511151
category=FutureWarning,
11521152
)
11531153
result = tools.to_datetime(
@@ -1169,7 +1169,7 @@ def converter(*date_cols, col: Hashable):
11691169
warnings.filterwarnings(
11701170
"ignore",
11711171
".*parsing datetimes with mixed time zones "
1172-
"will raise a warning",
1172+
"will raise an error",
11731173
category=FutureWarning,
11741174
)
11751175
result = tools.to_datetime(
@@ -1187,7 +1187,7 @@ def converter(*date_cols, col: Hashable):
11871187
warnings.filterwarnings(
11881188
"ignore",
11891189
".*parsing datetimes with mixed time zones "
1190-
"will raise a warning",
1190+
"will raise an error",
11911191
category=FutureWarning,
11921192
)
11931193
return tools.to_datetime(

pandas/tests/indexes/datetimes/test_constructors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ def test_construction_index_with_mixed_timezones(self):
300300
assert not isinstance(result, DatetimeIndex)
301301

302302
msg = "DatetimeIndex has mixed timezones"
303-
msg_depr = "parsing datetimes with mixed time zones will raise a warning"
303+
msg_depr = "parsing datetimes with mixed time zones will raise an error"
304304
with pytest.raises(TypeError, match=msg):
305305
with tm.assert_produces_warning(FutureWarning, match=msg_depr):
306306
DatetimeIndex(["2013-11-02 22:00-05:00", "2013-11-03 22:00-06:00"])

pandas/tests/tools/test_to_datetime.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ def test_to_datetime_parse_tzname_or_tzoffset_utc_false_deprecated(
518518
self, fmt, dates, expected_dates
519519
):
520520
# GH 13486, 50887
521-
msg = "parsing datetimes with mixed time zones will raise a warning"
521+
msg = "parsing datetimes with mixed time zones will raise an error"
522522
with tm.assert_produces_warning(FutureWarning, match=msg):
523523
result = to_datetime(dates, format=fmt)
524524
expected = Index(expected_dates)
@@ -693,7 +693,7 @@ def test_to_datetime_mixed_datetime_and_string_with_format_mixed_offsets_utc_fal
693693
args = ["2000-01-01 01:00:00", "2000-01-01 02:00:00+00:00"]
694694
ts1 = constructor(args[0])
695695
ts2 = args[1]
696-
msg = "parsing datetimes with mixed time zones will raise a warning"
696+
msg = "parsing datetimes with mixed time zones will raise an error"
697697

698698
expected = Index(
699699
[
@@ -734,7 +734,7 @@ def test_to_datetime_mixed_datetime_and_string_with_format_mixed_offsets_utc_fal
734734
)
735735
def test_to_datetime_mixed_offsets_with_none_tz(self, fmt, expected):
736736
# https://github.com/pandas-dev/pandas/issues/50071
737-
msg = "parsing datetimes with mixed time zones will raise a warning"
737+
msg = "parsing datetimes with mixed time zones will raise an error"
738738

739739
with tm.assert_produces_warning(FutureWarning, match=msg):
740740
result = to_datetime(
@@ -1236,7 +1236,7 @@ def test_to_datetime_different_offsets(self, cache):
12361236
ts_string_2 = "March 1, 2018 12:00:00+0500"
12371237
arr = [ts_string_1] * 5 + [ts_string_2] * 5
12381238
expected = Index([parse(x) for x in arr])
1239-
msg = "parsing datetimes with mixed time zones will raise a warning"
1239+
msg = "parsing datetimes with mixed time zones will raise an error"
12401240
with tm.assert_produces_warning(FutureWarning, match=msg):
12411241
result = to_datetime(arr, cache=cache)
12421242
tm.assert_index_equal(result, expected)
@@ -1604,7 +1604,7 @@ def test_to_datetime_coerce(self):
16041604
"March 1, 2018 12:00:00+0500",
16051605
"20100240",
16061606
]
1607-
msg = "parsing datetimes with mixed time zones will raise a warning"
1607+
msg = "parsing datetimes with mixed time zones will raise an error"
16081608
with tm.assert_produces_warning(FutureWarning, match=msg):
16091609
result = to_datetime(ts_strings, errors="coerce")
16101610
expected = Index(
@@ -1689,7 +1689,7 @@ def test_iso_8601_strings_with_same_offset(self):
16891689
def test_iso_8601_strings_with_different_offsets(self):
16901690
# GH 17697, 11736, 50887
16911691
ts_strings = ["2015-11-18 15:30:00+05:30", "2015-11-18 16:30:00+06:30", NaT]
1692-
msg = "parsing datetimes with mixed time zones will raise a warning"
1692+
msg = "parsing datetimes with mixed time zones will raise an error"
16931693
with tm.assert_produces_warning(FutureWarning, match=msg):
16941694
result = to_datetime(ts_strings)
16951695
expected = np.array(
@@ -1729,7 +1729,7 @@ def test_mixed_offsets_with_native_datetime_raises(self):
17291729

17301730
now = Timestamp("now")
17311731
today = Timestamp("today")
1732-
msg = "parsing datetimes with mixed time zones will raise a warning"
1732+
msg = "parsing datetimes with mixed time zones will raise an error"
17331733
with tm.assert_produces_warning(FutureWarning, match=msg):
17341734
mixed = to_datetime(ser)
17351735
expected = Series(
@@ -1810,7 +1810,7 @@ def test_to_datetime_fixed_offset(self):
18101810
)
18111811
def test_to_datetime_mixed_offsets_with_utc_false_deprecated(self, date):
18121812
# GH 50887
1813-
msg = "parsing datetimes with mixed time zones will raise a warning"
1813+
msg = "parsing datetimes with mixed time zones will raise an error"
18141814
with tm.assert_produces_warning(FutureWarning, match=msg):
18151815
to_datetime(date, utc=False)
18161816

@@ -3680,7 +3680,7 @@ def test_to_datetime_with_empty_str_utc_false_format_mixed():
36803680

36813681
def test_to_datetime_with_empty_str_utc_false_offsets_and_format_mixed():
36823682
# GH 50887
3683-
msg = "parsing datetimes with mixed time zones will raise a warning"
3683+
msg = "parsing datetimes with mixed time zones will raise an error"
36843684

36853685
with tm.assert_produces_warning(FutureWarning, match=msg):
36863686
to_datetime(

pandas/tests/tslibs/test_array_to_datetime.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def test_parsing_different_timezone_offsets():
8585
data = ["2015-11-18 15:30:00+05:30", "2015-11-18 15:30:00+06:30"]
8686
data = np.array(data, dtype=object)
8787

88-
msg = "parsing datetimes with mixed time zones will raise a warning"
88+
msg = "parsing datetimes with mixed time zones will raise an error"
8989
with tm.assert_produces_warning(FutureWarning, match=msg):
9090
result, result_tz = tslib.array_to_datetime(data)
9191
expected = np.array(

0 commit comments

Comments
 (0)