Skip to content

Commit

Permalink
Backport PR #55611 on branch 2.1.x (DEPR: correct warning message whi…
Browse files Browse the repository at this point in the history
…le parsing datetimes with mixed time zones if utc=False) (#55613)

Backport PR #55611: DEPR: correct warning message while parsing datetimes with mixed time zones if utc=False

Co-authored-by: Natalia Mokeeva <91160475+natmokval@users.noreply.github.com>
  • Loading branch information
meeseeksmachine and natmokval committed Oct 21, 2023
1 parent 9d39df0 commit 3c1fe5c
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ cdef _array_to_datetime_object(
if len(unique_timezones) > 1:
warnings.warn(
"In a future version of pandas, parsing datetimes with mixed time "
"zones will raise a warning unless `utc=True`. "
"zones will raise an error unless `utc=True`. "
"Please specify `utc=True` to opt in to the new behaviour "
"and silence this warning. To create a `Series` with mixed offsets and "
"`object` dtype, please use `apply` and `datetime.datetime.strptime`",
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/tools/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def _return_parsed_timezone_results(
if len(non_na_timezones) > 1:
warnings.warn(
"In a future version of pandas, parsing datetimes with mixed time "
"zones will raise a warning unless `utc=True`. Please specify `utc=True` "
"zones will raise an error unless `utc=True`. Please specify `utc=True` "
"to opt in to the new behaviour and silence this warning. "
"To create a `Series` with mixed offsets and `object` dtype, "
"please use `apply` and `datetime.datetime.strptime`",
Expand Down Expand Up @@ -788,7 +788,7 @@ def to_datetime(
.. warning::
In a future version of pandas, parsing datetimes with mixed time
zones will raise a warning unless `utc=True`.
zones will raise an error unless `utc=True`.
Please specify `utc=True` to opt in to the new behaviour
and silence this warning. To create a `Series` with mixed offsets and
`object` dtype, please use `apply` and `datetime.datetime.strptime`.
Expand Down Expand Up @@ -1023,7 +1023,7 @@ def to_datetime(
>>> pd.to_datetime(['2020-10-25 02:00 +0200',
... '2020-10-25 04:00 +0100']) # doctest: +SKIP
FutureWarning: In a future version of pandas, parsing datetimes with mixed
time zones will raise a warning unless `utc=True`. Please specify `utc=True`
time zones will raise an error unless `utc=True`. Please specify `utc=True`
to opt in to the new behaviour and silence this warning. To create a `Series`
with mixed offsets and `object` dtype, please use `apply` and
`datetime.datetime.strptime`.
Expand All @@ -1037,7 +1037,7 @@ def to_datetime(
>>> pd.to_datetime(["2020-01-01 01:00:00-01:00",
... datetime(2020, 1, 1, 3, 0)]) # doctest: +SKIP
FutureWarning: In a future version of pandas, parsing datetimes with mixed
time zones will raise a warning unless `utc=True`. Please specify `utc=True`
time zones will raise an error unless `utc=True`. Please specify `utc=True`
to opt in to the new behaviour and silence this warning. To create a `Series`
with mixed offsets and `object` dtype, please use `apply` and
`datetime.datetime.strptime`.
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/json/_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,7 @@ def _try_convert_to_date(self, data):
warnings.filterwarnings(
"ignore",
".*parsing datetimes with mixed time "
"zones will raise a warning",
"zones will raise an error",
category=FutureWarning,
)
new_data = to_datetime(new_data, errors="raise", unit=date_unit)
Expand Down
6 changes: 3 additions & 3 deletions pandas/io/parsers/base_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ def converter(*date_cols, col: Hashable):
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore",
".*parsing datetimes with mixed time zones will raise a warning",
".*parsing datetimes with mixed time zones will raise an error",
category=FutureWarning,
)
result = tools.to_datetime(
Expand All @@ -1169,7 +1169,7 @@ def converter(*date_cols, col: Hashable):
warnings.filterwarnings(
"ignore",
".*parsing datetimes with mixed time zones "
"will raise a warning",
"will raise an error",
category=FutureWarning,
)
result = tools.to_datetime(
Expand All @@ -1187,7 +1187,7 @@ def converter(*date_cols, col: Hashable):
warnings.filterwarnings(
"ignore",
".*parsing datetimes with mixed time zones "
"will raise a warning",
"will raise an error",
category=FutureWarning,
)
return tools.to_datetime(
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/datetimes/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def test_construction_index_with_mixed_timezones(self):
assert not isinstance(result, DatetimeIndex)

msg = "DatetimeIndex has mixed timezones"
msg_depr = "parsing datetimes with mixed time zones will raise a warning"
msg_depr = "parsing datetimes with mixed time zones will raise an error"
with pytest.raises(TypeError, match=msg):
with tm.assert_produces_warning(FutureWarning, match=msg_depr):
DatetimeIndex(["2013-11-02 22:00-05:00", "2013-11-03 22:00-06:00"])
Expand Down
18 changes: 9 additions & 9 deletions pandas/tests/tools/test_to_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def test_to_datetime_parse_tzname_or_tzoffset_utc_false_deprecated(
self, fmt, dates, expected_dates
):
# GH 13486, 50887
msg = "parsing datetimes with mixed time zones will raise a warning"
msg = "parsing datetimes with mixed time zones will raise an error"
with tm.assert_produces_warning(FutureWarning, match=msg):
result = to_datetime(dates, format=fmt)
expected = Index(expected_dates)
Expand Down Expand Up @@ -693,7 +693,7 @@ def test_to_datetime_mixed_datetime_and_string_with_format_mixed_offsets_utc_fal
args = ["2000-01-01 01:00:00", "2000-01-01 02:00:00+00:00"]
ts1 = constructor(args[0])
ts2 = args[1]
msg = "parsing datetimes with mixed time zones will raise a warning"
msg = "parsing datetimes with mixed time zones will raise an error"

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

with tm.assert_produces_warning(FutureWarning, match=msg):
result = to_datetime(
Expand Down Expand Up @@ -1236,7 +1236,7 @@ def test_to_datetime_different_offsets(self, cache):
ts_string_2 = "March 1, 2018 12:00:00+0500"
arr = [ts_string_1] * 5 + [ts_string_2] * 5
expected = Index([parse(x) for x in arr])
msg = "parsing datetimes with mixed time zones will raise a warning"
msg = "parsing datetimes with mixed time zones will raise an error"
with tm.assert_produces_warning(FutureWarning, match=msg):
result = to_datetime(arr, cache=cache)
tm.assert_index_equal(result, expected)
Expand Down Expand Up @@ -1604,7 +1604,7 @@ def test_to_datetime_coerce(self):
"March 1, 2018 12:00:00+0500",
"20100240",
]
msg = "parsing datetimes with mixed time zones will raise a warning"
msg = "parsing datetimes with mixed time zones will raise an error"
with tm.assert_produces_warning(FutureWarning, match=msg):
result = to_datetime(ts_strings, errors="coerce")
expected = Index(
Expand Down Expand Up @@ -1689,7 +1689,7 @@ def test_iso_8601_strings_with_same_offset(self):
def test_iso_8601_strings_with_different_offsets(self):
# GH 17697, 11736, 50887
ts_strings = ["2015-11-18 15:30:00+05:30", "2015-11-18 16:30:00+06:30", NaT]
msg = "parsing datetimes with mixed time zones will raise a warning"
msg = "parsing datetimes with mixed time zones will raise an error"
with tm.assert_produces_warning(FutureWarning, match=msg):
result = to_datetime(ts_strings)
expected = np.array(
Expand Down Expand Up @@ -1729,7 +1729,7 @@ def test_mixed_offsets_with_native_datetime_raises(self):

now = Timestamp("now")
today = Timestamp("today")
msg = "parsing datetimes with mixed time zones will raise a warning"
msg = "parsing datetimes with mixed time zones will raise an error"
with tm.assert_produces_warning(FutureWarning, match=msg):
mixed = to_datetime(ser)
expected = Series(
Expand Down Expand Up @@ -1810,7 +1810,7 @@ def test_to_datetime_fixed_offset(self):
)
def test_to_datetime_mixed_offsets_with_utc_false_deprecated(self, date):
# GH 50887
msg = "parsing datetimes with mixed time zones will raise a warning"
msg = "parsing datetimes with mixed time zones will raise an error"
with tm.assert_produces_warning(FutureWarning, match=msg):
to_datetime(date, utc=False)

Expand Down Expand Up @@ -3680,7 +3680,7 @@ def test_to_datetime_with_empty_str_utc_false_format_mixed():

def test_to_datetime_with_empty_str_utc_false_offsets_and_format_mixed():
# GH 50887
msg = "parsing datetimes with mixed time zones will raise a warning"
msg = "parsing datetimes with mixed time zones will raise an error"

with tm.assert_produces_warning(FutureWarning, match=msg):
to_datetime(
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/tslibs/test_array_to_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_parsing_different_timezone_offsets():
data = ["2015-11-18 15:30:00+05:30", "2015-11-18 15:30:00+06:30"]
data = np.array(data, dtype=object)

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

0 comments on commit 3c1fe5c

Please sign in to comment.