Skip to content

PERF: custom ops for RangeIndex.[all|any|__contains__] #26617

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
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Rabased and added typing
  • Loading branch information
topper-123 committed Jun 5, 2019
commit 1e92983e86068014ef99c1443e4c6b3cc791cadc
7 changes: 4 additions & 3 deletions pandas/core/indexes/range.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import timedelta
import operator
from sys import getsizeof
from typing import Union
import warnings

import numpy as np
Expand Down Expand Up @@ -334,7 +335,7 @@ def is_monotonic_decreasing(self):
def has_duplicates(self):
return False

def __contains__(self, key):
def __contains__(self, key: Union[int, np.integer]) -> bool:
hash(key)
try:
key = ensure_python_int(key)
Expand Down Expand Up @@ -648,10 +649,10 @@ def __floordiv__(self, other):
return self._simple_new(start, start + 1, 1, name=self.name)
return self._int64index // other

def all(self):
def all(self) -> bool:
return 0 not in self._range

def any(self):
def any(self) -> bool:
return any(self._range)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/test_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def test_dtype(self):
def test_cached_data(self):
# GH 26565, GH26617
# Calling RangeIndex._data caches an int64 array of the same length at
# self._cached_data. This tests whether _cached_data has been set.
# self._cached_data. This test checks whether _cached_data has been set
idx = RangeIndex(0, 100, 10)

assert idx._cached_data is None
Expand Down