Skip to content

Commit aa4d86a

Browse files
jbrockmendelKevin D Smith
authored and
Kevin D Smith
committed
REF: _convert_for_op -> _validate_fill_value (pandas-dev#36318)
1 parent 23ab7fc commit aa4d86a

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

pandas/core/indexes/base.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -4047,9 +4047,10 @@ def _to_safe_for_reshape(self):
40474047
"""
40484048
return self
40494049

4050-
def _convert_for_op(self, value):
4050+
def _validate_fill_value(self, value):
40514051
"""
4052-
Convert value to be insertable to ndarray.
4052+
Check if the value can be inserted into our array, and convert
4053+
it to an appropriate native type if necessary.
40534054
"""
40544055
return value
40554056

@@ -4228,7 +4229,8 @@ def putmask(self, mask, value):
42284229
"""
42294230
values = self.values.copy()
42304231
try:
4231-
np.putmask(values, mask, self._convert_for_op(value))
4232+
converted = self._validate_fill_value(value)
4233+
np.putmask(values, mask, converted)
42324234
if is_period_dtype(self.dtype):
42334235
# .values cast to object, so we need to cast back
42344236
values = type(self)(values)._data

pandas/core/indexes/datetimes.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,11 @@ def __reduce__(self):
325325
d.update(self._get_attributes_dict())
326326
return _new_DatetimeIndex, (type(self), d), None
327327

328-
def _convert_for_op(self, value):
328+
def _validate_fill_value(self, value):
329329
"""
330330
Convert value to be insertable to ndarray.
331331
"""
332-
if self._has_same_tz(value):
333-
return Timestamp(value).asm8
334-
raise ValueError("Passed item and index have different timezone")
332+
return self._data._validate_setitem_value(value)
335333

336334
def _is_comparable_dtype(self, dtype: DtypeObj) -> bool:
337335
"""

pandas/core/indexes/numeric.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def _shallow_copy(self, values=None, name: Label = lib.no_default):
116116
return Float64Index._simple_new(values, name=name)
117117
return super()._shallow_copy(values=values, name=name)
118118

119-
def _convert_for_op(self, value):
119+
def _validate_fill_value(self, value):
120120
"""
121121
Convert value to be insertable to ndarray.
122122
"""

0 commit comments

Comments
 (0)