Skip to content

CLN: Exception catching in io #28349

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
Sep 9, 2019
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
23 changes: 10 additions & 13 deletions pandas/core/indexes/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
5 changes: 0 additions & 5 deletions pandas/core/indexes/frozen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 8 additions & 10 deletions pandas/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand All @@ -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(
Expand Down Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down