Skip to content

Catch IntervalIndex.itemsize deprecation warning in tests and remove IntervalArray.itemsize #22149

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
Aug 1, 2018
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
4 changes: 0 additions & 4 deletions pandas/core/arrays/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,10 +688,6 @@ def size(self):
def shape(self):
return self.left.shape

@property
def itemsize(self):
return self.left.itemsize + self.right.itemsize

def take(self, indices, allow_fill=False, fill_value=None, axis=None,
**kwargs):
"""
Expand Down
10 changes: 8 additions & 2 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,14 @@ def shape(self):

@property
def itemsize(self):
# Avoid materializing ndarray[Interval]
return self._data.itemsize
msg = ('IntervalIndex.itemsize is deprecated and will be removed in '
'a future version')
warnings.warn(msg, FutureWarning, stacklevel=2)

# supress the warning from the underlying left/right itemsize
with warnings.catch_warnings():
warnings.simplefilter('ignore')
return self.left.itemsize + self.right.itemsize

def __len__(self):
return len(self.left)
Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/indexes/interval/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,9 +989,11 @@ def test_itemsize(self):
# GH 19209
left = np.arange(0, 4, dtype='i8')
right = np.arange(1, 5, dtype='i8')

result = IntervalIndex.from_arrays(left, right).itemsize
expected = 16 # 8 * 2

with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
result = IntervalIndex.from_arrays(left, right).itemsize

assert result == expected

@pytest.mark.parametrize('new_closed', [
Expand Down