-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Change UInt64Index._na_value from 0 to np.nan #18401
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -251,7 +251,7 @@ def __new__(cls, data=None, dtype=None, copy=False, name=None, | |
# then coerce to integer. | ||
try: | ||
return cls._try_convert_to_int_index( | ||
data, copy, name) | ||
data, copy, name, dtype) | ||
except ValueError: | ||
pass | ||
|
||
|
@@ -307,7 +307,7 @@ def __new__(cls, data=None, dtype=None, copy=False, name=None, | |
if inferred == 'integer': | ||
try: | ||
return cls._try_convert_to_int_index( | ||
subarr, copy, name) | ||
subarr, copy, name, dtype) | ||
except ValueError: | ||
pass | ||
|
||
|
@@ -664,7 +664,7 @@ def ravel(self, order='C'): | |
|
||
# construction helpers | ||
@classmethod | ||
def _try_convert_to_int_index(cls, data, copy, name): | ||
def _try_convert_to_int_index(cls, data, copy, name, dtype): | ||
""" | ||
Attempt to convert an array of data into an integer index. | ||
|
||
|
@@ -685,15 +685,18 @@ def _try_convert_to_int_index(cls, data, copy, name): | |
""" | ||
|
||
from .numeric import Int64Index, UInt64Index | ||
try: | ||
res = data.astype('i8', copy=False) | ||
if (res == data).all(): | ||
return Int64Index(res, copy=copy, name=name) | ||
except (OverflowError, TypeError, ValueError): | ||
pass | ||
if not is_unsigned_integer_dtype(dtype): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a comment here (eg. about why we don't convert for uint) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
# skip int64 conversion attempt if uint-like dtype is passed, as | ||
# this could return Int64Index when UInt64Index is what's desrired | ||
try: | ||
res = data.astype('i8', copy=False) | ||
if (res == data).all(): | ||
return Int64Index(res, copy=copy, name=name) | ||
except (OverflowError, TypeError, ValueError): | ||
pass | ||
|
||
# Conversion to int64 failed (possibly due to | ||
# overflow), so let's try now with uint64. | ||
# Conversion to int64 failed (possibly due to overflow) or was skipped, | ||
# so let's try now with uint64. | ||
try: | ||
res = data.astype('u8', copy=False) | ||
if (res == data).all(): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
|
||
import numpy as np | ||
|
||
from pandas import Categorical, IntervalIndex, compat, notna | ||
from pandas import Categorical, IntervalIndex, compat | ||
from pandas.util.testing import assert_almost_equal | ||
import pandas.core.config as cf | ||
import pandas as pd | ||
|
@@ -269,28 +269,19 @@ def f(x): | |
ordered=False) | ||
tm.assert_index_equal(result, exp) | ||
|
||
def test_where(self): | ||
@pytest.mark.parametrize('klass', [list, tuple, np.array, pd.Series]) | ||
def test_where(self, klass): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should prob move all of the test_where tests to test_base and use the indices fixture to avoid the code repetition (new issue though) |
||
i = self.create_index() | ||
result = i.where(notna(i)) | ||
cond = [True] * len(i) | ||
expected = i | ||
result = i.where(klass(cond)) | ||
tm.assert_index_equal(result, expected) | ||
|
||
i2 = pd.CategoricalIndex([np.nan, np.nan] + i[2:].tolist(), | ||
categories=i.categories) | ||
result = i.where(notna(i2)) | ||
expected = i2 | ||
tm.assert_index_equal(result, expected) | ||
|
||
def test_where_array_like(self): | ||
i = self.create_index() | ||
cond = [False] + [True] * (len(i) - 1) | ||
klasses = [list, tuple, np.array, pd.Series] | ||
expected = pd.CategoricalIndex([np.nan] + i[1:].tolist(), | ||
categories=i.categories) | ||
|
||
for klass in klasses: | ||
result = i.where(klass(cond)) | ||
tm.assert_index_equal(result, expected) | ||
expected = CategoricalIndex([np.nan] + i[1:].tolist(), | ||
categories=i.categories) | ||
result = i.where(klass(cond)) | ||
tm.assert_index_equal(result, expected) | ||
|
||
def test_append(self): | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
18398 as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a separate entry for 18398 under "Backwards incompatible API changes"