From 2f668ab4aacb85f69ffbc35b746676f72d7e0841 Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 31 May 2021 08:10:49 -0700 Subject: [PATCH] REF: remove unnecessary try/excepts --- pandas/core/arrays/categorical.py | 6 ------ pandas/core/common.py | 7 ++----- pandas/core/construction.py | 15 ++++----------- pandas/core/indexes/base.py | 7 ++----- 4 files changed, 8 insertions(+), 27 deletions(-) diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 95d9409b265ce..47779dd6dba25 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -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) diff --git a/pandas/core/common.py b/pandas/core/common.py index 04ff2d2c4618f..c0e44a437f59e 100644 --- a/pandas/core/common.py +++ b/pandas/core/common.py @@ -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 diff --git a/pandas/core/construction.py b/pandas/core/construction.py index 92f94f4424ee8..b06e102d57ca0 100644 --- a/pandas/core/construction.py +++ b/pandas/core/construction.py @@ -17,10 +17,7 @@ import numpy.ma as ma from pandas._libs import lib -from pandas._libs.tslibs import ( - IncompatibleFrequency, - OutOfBoundsDatetime, -) +from pandas._libs.tslibs import OutOfBoundsDatetime from pandas._typing import ( AnyArrayLike, ArrayLike, @@ -292,9 +289,9 @@ def array( IntegerArray, IntervalArray, PandasArray, + PeriodArray, StringArray, TimedeltaArray, - period_array, ) if lib.is_scalar(data): @@ -318,12 +315,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) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 2a50ebd959ace..11f4da02c0d2f 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -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