Skip to content

REF: remove unnecessary try/excepts #41744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,6 @@ def __init__(
"explicitly specify the categories order "
"by passing in a categories argument."
) from err
except ValueError as err:

# TODO(EA2D)
raise NotImplementedError(
"> 1 ndim Categorical are not supported at this time"
) from err

# we're inferring from values
dtype = CategoricalDtype(categories, dtype.ordered)
Expand Down
7 changes: 2 additions & 5 deletions pandas/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,8 @@ def is_bool_indexer(key: Any) -> bool:
elif is_bool_dtype(key.dtype):
return True
elif isinstance(key, list):
try:
arr = np.asarray(key)
return arr.dtype == np.bool_ and len(arr) == len(key)
except TypeError: # pragma: no cover
return False
arr = np.asarray(key)
return arr.dtype == np.bool_ and len(arr) == len(key)

return False

Expand Down
11 changes: 3 additions & 8 deletions pandas/core/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import numpy.ma as ma

from pandas._libs import lib
from pandas._libs.tslibs import IncompatibleFrequency
from pandas._typing import (
AnyArrayLike,
ArrayLike,
Expand Down Expand Up @@ -289,9 +288,9 @@ def array(
IntegerArray,
IntervalArray,
PandasArray,
PeriodArray,
StringArray,
TimedeltaArray,
period_array,
)

if lib.is_scalar(data):
Expand All @@ -315,12 +314,8 @@ def array(
if dtype is None:
inferred_dtype = lib.infer_dtype(data, skipna=True)
if inferred_dtype == "period":
try:
return period_array(data, copy=copy)
except IncompatibleFrequency:
# We may have a mixture of frequencies.
# We choose to return an ndarray, rather than raising.
pass
return PeriodArray._from_sequence(data, copy=copy)

elif inferred_dtype == "interval":
try:
return IntervalArray(data, copy=copy)
Expand Down
7 changes: 2 additions & 5 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6468,11 +6468,8 @@ def _maybe_cast_data_without_dtype(subarr: np.ndarray) -> ArrayLike:
tda = TimedeltaArray._from_sequence(subarr, copy=False)
return tda
elif inferred == "period":
try:
parr = PeriodArray._from_sequence(subarr)
return parr
except IncompatibleFrequency:
pass
parr = PeriodArray._from_sequence(subarr)
return parr

return subarr

Expand Down