Skip to content

Commit 04ea51d

Browse files
CLN: small clean-up of IntervalIndex (pandas-dev#22956)
1 parent b0f9a10 commit 04ea51d

File tree

2 files changed

+9
-47
lines changed

2 files changed

+9
-47
lines changed

pandas/core/arrays/interval.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,7 @@ class IntervalArray(IntervalMixin, ExtensionArray):
108108
_na_value = _fill_value = np.nan
109109

110110
def __new__(cls, data, closed=None, dtype=None, copy=False,
111-
fastpath=False, verify_integrity=True):
112-
113-
if fastpath:
114-
return cls._simple_new(data.left, data.right, closed,
115-
copy=copy, dtype=dtype,
116-
verify_integrity=False)
111+
verify_integrity=True):
117112

118113
if isinstance(data, ABCSeries) and is_interval_dtype(data):
119114
data = data.values

pandas/core/indexes/interval.py

+8-41
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,13 @@ class IntervalIndex(IntervalMixin, Index):
146146
_mask = None
147147

148148
def __new__(cls, data, closed=None, dtype=None, copy=False,
149-
name=None, fastpath=False, verify_integrity=True):
150-
151-
if fastpath:
152-
return cls._simple_new(data, name)
149+
name=None, verify_integrity=True):
153150

154151
if name is None and hasattr(data, 'name'):
155152
name = data.name
156153

157154
with rewrite_exception("IntervalArray", cls.__name__):
158155
array = IntervalArray(data, closed=closed, copy=copy, dtype=dtype,
159-
fastpath=fastpath,
160156
verify_integrity=verify_integrity)
161157

162158
return cls._simple_new(array, name)
@@ -187,14 +183,6 @@ def _shallow_copy(self, left=None, right=None, **kwargs):
187183
attributes.update(kwargs)
188184
return self._simple_new(result, **attributes)
189185

190-
@cache_readonly
191-
def hasnans(self):
192-
"""
193-
Return if the IntervalIndex has any nans; enables various performance
194-
speedups
195-
"""
196-
return self._isnan.any()
197-
198186
@cache_readonly
199187
def _isnan(self):
200188
"""Return a mask indicating if each value is NA"""
@@ -206,10 +194,6 @@ def _isnan(self):
206194
def _engine(self):
207195
return IntervalTree(self.left, self.right, closed=self.closed)
208196

209-
@property
210-
def _constructor(self):
211-
return type(self)
212-
213197
def __contains__(self, key):
214198
"""
215199
return a boolean if this key is IN the index
@@ -394,18 +378,7 @@ def _values(self):
394378

395379
@cache_readonly
396380
def _ndarray_values(self):
397-
left = self.left
398-
right = self.right
399-
mask = self._isnan
400-
closed = self.closed
401-
402-
result = np.empty(len(left), dtype=object)
403-
for i in range(len(left)):
404-
if mask[i]:
405-
result[i] = np.nan
406-
else:
407-
result[i] = Interval(left[i], right[i], closed)
408-
return result
381+
return np.array(self._data)
409382

410383
def __array__(self, result=None):
411384
""" the array interface, return my values """
@@ -892,18 +865,12 @@ def take(self, indices, axis=0, allow_fill=True,
892865
return self._simple_new(result, **attributes)
893866

894867
def __getitem__(self, value):
895-
mask = self._isnan[value]
896-
if is_scalar(mask) and mask:
897-
return self._na_value
898-
899-
left = self.left[value]
900-
right = self.right[value]
901-
902-
# scalar
903-
if not isinstance(left, Index):
904-
return Interval(left, right, self.closed)
905-
906-
return self._shallow_copy(left, right)
868+
result = self._data[value]
869+
if isinstance(result, IntervalArray):
870+
return self._shallow_copy(result)
871+
else:
872+
# scalar
873+
return result
907874

908875
# __repr__ associated methods are based on MultiIndex
909876

0 commit comments

Comments
 (0)