Skip to content

Commit c42f143

Browse files
committed
add catch_warnings to converter
1 parent b01c3ef commit c42f143

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

pandas/io/parsers/base_parser.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,22 +1165,38 @@ def converter(*date_cols, col: Hashable):
11651165
return result._values
11661166
else:
11671167
try:
1168-
result = tools.to_datetime(
1169-
date_parser(*(unpack_if_single_element(arg) for arg in date_cols)),
1170-
errors="ignore",
1171-
cache=cache_dates,
1172-
)
1168+
with warnings.catch_warnings():
1169+
warnings.filterwarnings(
1170+
"ignore",
1171+
".*parsing datetimes with mixed time zones "
1172+
"will raise a warning",
1173+
category=FutureWarning,
1174+
)
1175+
result = tools.to_datetime(
1176+
date_parser(
1177+
*(unpack_if_single_element(arg) for arg in date_cols)
1178+
),
1179+
errors="ignore",
1180+
cache=cache_dates,
1181+
)
11731182
if isinstance(result, datetime.datetime):
11741183
raise Exception("scalar parser")
11751184
return result
11761185
except Exception:
1177-
return tools.to_datetime(
1178-
parsing.try_parse_dates(
1179-
parsing.concat_date_cols(date_cols),
1180-
parser=date_parser,
1181-
),
1182-
errors="ignore",
1183-
)
1186+
with warnings.catch_warnings():
1187+
warnings.filterwarnings(
1188+
"ignore",
1189+
".*parsing datetimes with mixed time zones "
1190+
"will raise a warning",
1191+
category=FutureWarning,
1192+
)
1193+
return tools.to_datetime(
1194+
parsing.try_parse_dates(
1195+
parsing.concat_date_cols(date_cols),
1196+
parser=date_parser,
1197+
),
1198+
errors="ignore",
1199+
)
11841200

11851201
return converter
11861202

0 commit comments

Comments
 (0)