Skip to content
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
35 changes: 12 additions & 23 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,14 @@ def func(intvidx_self, other, sort=False):
)
@accessor.delegate_names(
delegate=IntervalArray,
accessors=["__array__", "overlaps", "contains", "__len__", "set_closed"],
accessors=[
"__array__",
"overlaps",
"contains",
"__len__",
"set_closed",
"to_tuples",
],
typ="method",
overwrite=True,
)
Expand Down Expand Up @@ -393,25 +400,6 @@ def __contains__(self, key) -> bool:
except KeyError:
return False

@Appender(
_interval_shared_docs["to_tuples"]
% dict(
return_type="Index",
examples="""
Examples
--------
>>> idx = pd.IntervalIndex.from_arrays([0, np.nan, 2], [1, np.nan, 3])
>>> idx.to_tuples()
Index([(0.0, 1.0), (nan, nan), (2.0, 3.0)], dtype='object')
>>> idx.to_tuples(na_tuple=False)
Index([(0.0, 1.0), nan, (2.0, 3.0)], dtype='object')
""",
)
)
Copy link
Member

Choose a reason for hiding this comment

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

By removing this, the docstring of IntervalIndex.to_tuples is now no longer correct (and misses the example).

The delegation mechanism will need a way to change docstrings?

def to_tuples(self, na_tuple=True):
tuples = self._data.to_tuples(na_tuple=na_tuple)
return Index(tuples)

@cache_readonly
def _multiindex(self):
return MultiIndex.from_arrays([self.left, self.right], names=["left", "right"])
Expand Down Expand Up @@ -1004,8 +992,7 @@ def take(self, indices, axis=0, allow_fill=True, fill_value=None, **kwargs):
result = self._data.take(
indices, axis=axis, allow_fill=allow_fill, fill_value=fill_value, **kwargs
)
attributes = self._get_attributes_dict()
return self._simple_new(result, **attributes)
return self._shallow_copy(result)

def __getitem__(self, value):
result = self._data[value]
Expand Down Expand Up @@ -1206,7 +1193,9 @@ def _delegate_method(self, name, *args, **kwargs):
res = method(*args, **kwargs)
if is_scalar(res) or name in self._raw_inherit:
return res
return type(self)(res, name=self.name)
if isinstance(res, IntervalArray):
return type(self)._simple_new(res, name=self.name)
return Index(res)


IntervalIndex._add_logical_methods_disabled()
Expand Down