Skip to content

REF: _convert_for_op -> _validate_fill_value #36318

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
Sep 13, 2020
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
8 changes: 5 additions & 3 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4047,9 +4047,10 @@ def _to_safe_for_reshape(self):
"""
return self

def _convert_for_op(self, value):
def _validate_fill_value(self, value):
"""
Convert value to be insertable to ndarray.
Check if the value can be inserted into our array, and convert
it to an appropriate native type if necessary.
"""
return value

Expand Down Expand Up @@ -4228,7 +4229,8 @@ def putmask(self, mask, value):
"""
values = self.values.copy()
try:
np.putmask(values, mask, self._convert_for_op(value))
converted = self._validate_fill_value(value)
np.putmask(values, mask, converted)
if is_period_dtype(self.dtype):
# .values cast to object, so we need to cast back
values = type(self)(values)._data
Expand Down
6 changes: 2 additions & 4 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,11 @@ def __reduce__(self):
d.update(self._get_attributes_dict())
return _new_DatetimeIndex, (type(self), d), None

def _convert_for_op(self, value):
def _validate_fill_value(self, value):
"""
Convert value to be insertable to ndarray.
"""
if self._has_same_tz(value):
return Timestamp(value).asm8
raise ValueError("Passed item and index have different timezone")
return self._data._validate_setitem_value(value)

def _is_comparable_dtype(self, dtype: DtypeObj) -> bool:
"""
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def _shallow_copy(self, values=None, name: Label = lib.no_default):
return Float64Index._simple_new(values, name=name)
return super()._shallow_copy(values=values, name=name)

def _convert_for_op(self, value):
def _validate_fill_value(self, value):
"""
Convert value to be insertable to ndarray.
"""
Expand Down