diff --git a/pandas/core/indexes/accessors.py b/pandas/core/indexes/accessors.py index 11b6cb2ca3ed4..cc8ecc0e64684 100644 --- a/pandas/core/indexes/accessors.py +++ b/pandas/core/indexes/accessors.py @@ -326,18 +326,15 @@ def __new__(cls, data): if orig is not None: data = Series(orig.values.categories, name=orig.name, copy=False) - try: - if is_datetime64_dtype(data.dtype): - return DatetimeProperties(data, orig) - elif is_datetime64tz_dtype(data.dtype): - return DatetimeProperties(data, orig) - elif is_timedelta64_dtype(data.dtype): - return TimedeltaProperties(data, orig) - elif is_period_arraylike(data): - return PeriodProperties(data, orig) - elif is_datetime_arraylike(data): - return DatetimeProperties(data, orig) - except Exception: - pass # we raise an attribute error anyway + if is_datetime64_dtype(data.dtype): + return DatetimeProperties(data, orig) + elif is_datetime64tz_dtype(data.dtype): + return DatetimeProperties(data, orig) + elif is_timedelta64_dtype(data.dtype): + return TimedeltaProperties(data, orig) + elif is_period_arraylike(data): + return PeriodProperties(data, orig) + elif is_datetime_arraylike(data): + return DatetimeProperties(data, orig) raise AttributeError("Can only use .dt accessor with datetimelike values") diff --git a/pandas/core/indexes/frozen.py b/pandas/core/indexes/frozen.py index 329456e25bded..a6c39d049c50c 100644 --- a/pandas/core/indexes/frozen.py +++ b/pandas/core/indexes/frozen.py @@ -70,12 +70,7 @@ def difference(self, other): # TODO: Consider deprecating these in favor of `union` (xref gh-15506) __add__ = __iadd__ = union - # Python 2 compat - def __getslice__(self, i, j): - return self.__class__(super().__getslice__(i, j)) - def __getitem__(self, n): - # Python 3 compat if isinstance(n, slice): return self.__class__(super().__getitem__(n)) return super().__getitem__(n) diff --git a/pandas/io/common.py b/pandas/io/common.py index ac8dee8467370..0bbac8a8b7c1c 100644 --- a/pandas/io/common.py +++ b/pandas/io/common.py @@ -90,7 +90,8 @@ def __next__(self): def _is_url(url) -> bool: - """Check to see if a URL has a valid protocol. + """ + Check to see if a URL has a valid protocol. Parameters ---------- @@ -101,10 +102,9 @@ def _is_url(url) -> bool: isurl : bool If `url` has a valid protocol return True otherwise False. """ - try: - return parse_url(url).scheme in _VALID_URLS - except Exception: + if not isinstance(url, str): return False + return parse_url(url).scheme in _VALID_URLS def _expand_user( @@ -171,18 +171,16 @@ def _stringify_path( def is_s3_url(url) -> bool: """Check for an s3, s3n, or s3a url""" - try: - return parse_url(url).scheme in ["s3", "s3n", "s3a"] - except Exception: + if not isinstance(url, str): return False + return parse_url(url).scheme in ["s3", "s3n", "s3a"] def is_gcs_url(url) -> bool: """Check for a gcs url""" - try: - return parse_url(url).scheme in ["gcs", "gs"] - except Exception: + if not isinstance(url, str): return False + return parse_url(url).scheme in ["gcs", "gs"] def urlopen(*args, **kwargs): diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index a3ff837bc7f52..72f1adf0aad3d 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -1064,7 +1064,6 @@ def _clean_options(self, options, engine): ) if result.get(arg, depr_default) != depr_default: - # raise Exception(result.get(arg, depr_default), depr_default) depr_warning += msg + "\n\n" else: result[arg] = parser_default diff --git a/pandas/io/pickle.py b/pandas/io/pickle.py index 4e390de87fc60..4b9a52a1fb8f3 100644 --- a/pandas/io/pickle.py +++ b/pandas/io/pickle.py @@ -153,10 +153,10 @@ def read_pickle(path, compression="infer"): # We want to silence any warnings about, e.g. moved modules. warnings.simplefilter("ignore", Warning) return pickle.load(f) - except Exception: # noqa: E722 + except Exception: try: return pc.load(f, encoding=None) - except Exception: # noqa: E722 + except Exception: return pc.load(f, encoding="latin1") finally: f.close()