Skip to content

TST: Avoid DeprecationWarnings #22646

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 4 commits into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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: 4 additions & 0 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2047,6 +2047,10 @@ def __getitem__(self, key):
promote = self._shallow_copy

if is_scalar(key):
if is_float(key) and key == int(key):
# avoid numpy(?) DeprecationWarning about non-integer
# number passed
key = int(key)
return getitem(key)

if isinstance(key, slice):
Expand Down
4 changes: 4 additions & 0 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,10 @@ def __setstate__(self, state):

def __getitem__(self, key):
if is_scalar(key):
if lib.is_float(key) and key == int(key):
# Avoid DeprecationWarning for non-integer number indexer
Copy link
Contributor

Choose a reason for hiding this comment

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

we do this a number of times in the indexing code

i think we have a function

maybe_convert_to_int_indexer iirc

if not can u make one

Copy link
Member Author

Choose a reason for hiding this comment

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

Index._convert_scalar_indexer looks like a candidate; need to check where it is called.

Copy link
Member Author

Choose a reason for hiding this comment

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

I take it back. core.common is right next to is_bool_indexer is the place for this.

key = int(key)

retval = []
for lev, lab in zip(self.levels, self.labels):
if lab[key] == -1:
Expand Down
8 changes: 6 additions & 2 deletions pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,10 +1033,14 @@ def css_bar(start, end, color):
def css(x):
if pd.isna(x):
return ''

# avoid deprecated indexing `colors[x > zero]`
color = colors[1] if x > zero else colors[0]

if align == 'left':
return css_bar(0, x, colors[x > zero])
return css_bar(0, x, color)
else:
return css_bar(min(x, zero), max(x, zero), colors[x > zero])
return css_bar(min(x, zero), max(x, zero), color)

if s.ndim == 1:
return [css(x) for x in normed]
Expand Down
2 changes: 1 addition & 1 deletion pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2431,7 +2431,7 @@ def assert_raises_regex(_exception, _regexp, _callable=None,

You can also use this in a with statement.

>>> with assert_raises_regex(TypeError, 'unsupported operand type\(s\)'):
>>> with assert_raises_regex(TypeError, r'unsupported operand type\(s\)'):
... 1 + {}
>>> with assert_raises_regex(TypeError, 'banana'):
... 'apple'[0] = 'b'
Expand Down