Skip to content

Commit 5cb5cf9

Browse files
committed
CLN: rewrite try/except/pass using contextlib.suppress
1 parent 009ffa8 commit 5cb5cf9

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

pandas/core/dtypes/cast.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Routines for casting.
33
"""
44

5+
from contextlib import suppress
56
from datetime import date, datetime, timedelta
67
from typing import (
78
TYPE_CHECKING,
@@ -191,12 +192,10 @@ def maybe_downcast_to_dtype(result, dtype: Dtype):
191192
# TODO(DatetimeArray): merge with previous elif
192193
from pandas.core.arrays import PeriodArray
193194

194-
try:
195-
return PeriodArray(result, freq=dtype.freq)
196-
except TypeError:
195+
with suppress(TypeError):
197196
# e.g. TypeError: int() argument must be a string, a
198197
# bytes-like object or a number, not 'Period
199-
pass
198+
return PeriodArray(result, freq=dtype.freq)
200199

201200
return result
202201

0 commit comments

Comments
 (0)