Skip to content

REF: De-duplicate ExtensionIndex._validate_fill_value #39923

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 21, 2021
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
6 changes: 0 additions & 6 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,12 +627,6 @@ def insert(self, loc: int, item):
result._data._freq = self._get_insert_freq(loc, item)
return result

def _validate_fill_value(self, value):
"""
Convert value to be insertable to ndarray.
"""
return self._data._validate_setitem_value(value)

# --------------------------------------------------------------------
# Join/Set Methods

Expand Down
14 changes: 10 additions & 4 deletions pandas/core/indexes/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import (
List,
TypeVar,
Union,
)

import numpy as np
Expand All @@ -25,7 +26,7 @@
ABCSeries,
)

from pandas.core.arrays import ExtensionArray
from pandas.core.arrays import IntervalArray
from pandas.core.arrays._mixins import NDArrayBackedExtensionArray
from pandas.core.indexers import deprecate_ndim_indexing
from pandas.core.indexes.base import Index
Expand Down Expand Up @@ -216,7 +217,7 @@ class ExtensionIndex(Index):
# The base class already passes through to _data:
# size, __len__, dtype

_data: ExtensionArray
_data: Union[IntervalArray, NDArrayBackedExtensionArray]

__eq__ = _make_wrapped_comparison_op("__eq__")
__ne__ = _make_wrapped_comparison_op("__ne__")
Expand All @@ -240,8 +241,7 @@ def __getitem__(self, key):
return type(self)(result, name=self.name)
# Unpack to ndarray for MPL compat

# error: "ExtensionArray" has no attribute "_data"
result = result._data # type: ignore[attr-defined]
result = result._ndarray

# Includes cases where we get a 2D ndarray back for MPL compat
deprecate_ndim_indexing(result)
Expand Down Expand Up @@ -276,6 +276,12 @@ def insert(self, loc: int, item):
# ExtensionIndex subclasses must override Index.insert
raise AbstractMethodError(self)

def _validate_fill_value(self, value):
"""
Convert value to be insertable to underlying array.
"""
return self._data._validate_setitem_value(value)

def _get_unique_index(self):
if self.is_unique:
return self
Expand Down
3 changes: 0 additions & 3 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1036,9 +1036,6 @@ def func(self, other, sort=sort):

# --------------------------------------------------------------------

def _validate_fill_value(self, value):
return self._data._validate_setitem_value(value)

@property
def _is_all_dates(self) -> bool:
"""
Expand Down