Skip to content

CLN: de-duplicate IntervalArray validators #36653

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
Oct 1, 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
19 changes: 6 additions & 13 deletions pandas/core/arrays/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,15 +852,15 @@ def _validate_fill_value(self, value):
return self._validate_scalar(value)

def _validate_fillna_value(self, value):
if not isinstance(value, Interval):
# This mirrors Datetimelike._validate_fill_value
try:
return self._validate_scalar(value)
except ValueError as err:
msg = (
"'IntervalArray.fillna' only supports filling with a "
f"scalar 'pandas.Interval'. Got a '{type(value).__name__}' instead."
)
raise TypeError(msg)

self._check_closed_matches(value, name="value")
return value.left, value.right
raise TypeError(msg) from err

def _validate_insert_value(self, value):
return self._validate_scalar(value)
Expand All @@ -887,14 +887,7 @@ def _validate_setitem_value(self, value):
value_left, value_right = value.left, value.right

else:
try:
# list-like of intervals
array = IntervalArray(value)
value_left, value_right = array.left, array.right
except TypeError as err:
# wrong type: not interval or NA
msg = f"'value' should be an interval type, got {type(value)} instead."
raise TypeError(msg) from err
return self._validate_listlike(value)

if needs_float_conversion:
raise ValueError("Cannot set float NaN to integer-backed IntervalArray")
Expand Down