Skip to content

Commit 4ed1bc2

Browse files
authored
REF: remove unnecessary try/excepts (#41744)
1 parent 9afda72 commit 4ed1bc2

File tree

4 files changed

+7
-24
lines changed

4 files changed

+7
-24
lines changed

pandas/core/arrays/categorical.py

-6
Original file line numberDiff line numberDiff line change
@@ -439,12 +439,6 @@ def __init__(
439439
"explicitly specify the categories order "
440440
"by passing in a categories argument."
441441
) from err
442-
except ValueError as err:
443-
444-
# TODO(EA2D)
445-
raise NotImplementedError(
446-
"> 1 ndim Categorical are not supported at this time"
447-
) from err
448442

449443
# we're inferring from values
450444
dtype = CategoricalDtype(categories, dtype.ordered)

pandas/core/common.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,8 @@ def is_bool_indexer(key: Any) -> bool:
142142
elif is_bool_dtype(key.dtype):
143143
return True
144144
elif isinstance(key, list):
145-
try:
146-
arr = np.asarray(key)
147-
return arr.dtype == np.bool_ and len(arr) == len(key)
148-
except TypeError: # pragma: no cover
149-
return False
145+
arr = np.asarray(key)
146+
return arr.dtype == np.bool_ and len(arr) == len(key)
150147

151148
return False
152149

pandas/core/construction.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import numpy.ma as ma
1818

1919
from pandas._libs import lib
20-
from pandas._libs.tslibs import IncompatibleFrequency
2120
from pandas._typing import (
2221
AnyArrayLike,
2322
ArrayLike,
@@ -289,9 +288,9 @@ def array(
289288
IntegerArray,
290289
IntervalArray,
291290
PandasArray,
291+
PeriodArray,
292292
StringArray,
293293
TimedeltaArray,
294-
period_array,
295294
)
296295

297296
if lib.is_scalar(data):
@@ -315,12 +314,8 @@ def array(
315314
if dtype is None:
316315
inferred_dtype = lib.infer_dtype(data, skipna=True)
317316
if inferred_dtype == "period":
318-
try:
319-
return period_array(data, copy=copy)
320-
except IncompatibleFrequency:
321-
# We may have a mixture of frequencies.
322-
# We choose to return an ndarray, rather than raising.
323-
pass
317+
return PeriodArray._from_sequence(data, copy=copy)
318+
324319
elif inferred_dtype == "interval":
325320
try:
326321
return IntervalArray(data, copy=copy)

pandas/core/indexes/base.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -6468,11 +6468,8 @@ def _maybe_cast_data_without_dtype(subarr: np.ndarray) -> ArrayLike:
64686468
tda = TimedeltaArray._from_sequence(subarr, copy=False)
64696469
return tda
64706470
elif inferred == "period":
6471-
try:
6472-
parr = PeriodArray._from_sequence(subarr)
6473-
return parr
6474-
except IncompatibleFrequency:
6475-
pass
6471+
parr = PeriodArray._from_sequence(subarr)
6472+
return parr
64766473

64776474
return subarr
64786475

0 commit comments

Comments
 (0)