Skip to content

CLN: de-duplicate validator #37458

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 3 commits into from
Oct 30, 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
17 changes: 5 additions & 12 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,10 +602,9 @@ def _validate_listlike(self, value, allow_object: bool = False):
pass

elif not type(self)._is_recognized_dtype(value.dtype):
raise TypeError(
f"value should be a '{self._scalar_type.__name__}', 'NaT', "
f"or array of those. Got '{type(value).__name__}' instead."
)
msg = self._validation_error_message(value, True)
Copy link
Member

Choose a reason for hiding this comment

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

Nice de-duplication.
I suggest using the named argument allow_listlike=True for clarity.
Otherwise, looks good to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jbrockmendel yeah might be more clear (but ok to do in next cleanup PR)

raise TypeError(msg)

return value

def _validate_searchsorted_value(self, value):
Expand All @@ -624,19 +623,13 @@ def _validate_setitem_value(self, value):

return self._unbox(value, setitem=True)

_validate_where_value = _validate_setitem_value

def _validate_insert_value(self, value):
value = self._validate_scalar(value)

return self._unbox(value, setitem=True)

def _validate_where_value(self, other):
if not is_list_like(other):
other = self._validate_scalar(other, True)
else:
other = self._validate_listlike(other)

return self._unbox(other, setitem=True)

def _unbox(
self, other, setitem: bool = False
) -> Union[np.int64, np.datetime64, np.timedelta64, np.ndarray]:
Expand Down