Skip to content

CLN: Fix exception causes in datetimelike.py #32164

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 1 commit into from
Feb 25, 2020
Merged
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
8 changes: 5 additions & 3 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,8 +775,10 @@ def searchsorted(self, value, side="left", sorter=None):
if isinstance(value, str):
try:
value = self._scalar_from_string(value)
except ValueError:
raise TypeError("searchsorted requires compatible dtype or scalar")
except ValueError as e:
raise TypeError(
"searchsorted requires compatible dtype or scalar"
) from e
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: can you make this "err" instead of "e"; i really dont like 1-letter names

Copy link
Member

@gfyoung gfyoung Feb 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh...I would leave it alone for this PR. I understand having an aesthetic preference, but e (as an exception variable name) is strewn all over the place in this file, and I don't see why we should nitpick this one instance and hold this PR up because of that.

If we have a generally accepted (for this repository) a stylistic preference for variable names for exceptions, then fine, but I'm not aware of that at this point.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yah, not a deal-breaker. i think of this as a "if you have to push another commit anyway, this would be nice"


elif is_valid_nat_for_dtype(value, self.dtype):
value = NaT
Expand Down Expand Up @@ -1039,7 +1041,7 @@ def _validate_frequency(cls, index, freq, **kwargs):
raise ValueError(
f"Inferred frequency {inferred} from passed values "
f"does not conform to passed frequency {freq.freqstr}"
)
) from e

# monotonicity/uniqueness properties are called via frequencies.infer_freq,
# see GH#23789
Expand Down