-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Implement unique+array parts of 24024 #24527
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fcb3ade
update return types for unique, array
jbrockmendel 7018506
Merge branch 'master' of https://github.com/pandas-dev/pandas into un…
jbrockmendel 5308887
Add IntegerNA to docstring
jbrockmendel b7b7b67
Merge branch 'master' of https://github.com/pandas-dev/pandas into un…
jbrockmendel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,15 @@ | |
import pandas.compat as compat | ||
from pandas.core.dtypes.common import ( | ||
is_object_dtype, is_datetime64_dtype, is_datetime64tz_dtype, | ||
needs_i8_conversion) | ||
needs_i8_conversion, is_timedelta64_dtype) | ||
import pandas.util.testing as tm | ||
from pandas import (Series, Index, DatetimeIndex, TimedeltaIndex, | ||
PeriodIndex, Timedelta, IntervalIndex, Interval, | ||
CategoricalIndex, Timestamp, DataFrame, Panel) | ||
from pandas.core.arrays import ( | ||
DatetimeArrayMixin as DatetimeArray, | ||
TimedeltaArrayMixin as TimedeltaArray, | ||
) | ||
from pandas.compat import StringIO, PYPY, long | ||
from pandas.compat.numpy import np_array_datetime64_compat | ||
from pandas.core.arrays import PandasArray | ||
|
@@ -383,8 +387,12 @@ def test_value_counts_unique_nunique(self): | |
assert result[0] == orig[0] | ||
for r in result: | ||
assert isinstance(r, Timestamp) | ||
tm.assert_numpy_array_equal(result, | ||
orig._values.astype(object).values) | ||
|
||
# TODO(#24024) once orig._values returns DTA, remove | ||
# the `._eadata` below | ||
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. in future, can make this a proper form test (e.g. result =, expected = ) |
||
tm.assert_numpy_array_equal( | ||
result.astype(object), | ||
orig._values._eadata.astype(object)) | ||
else: | ||
tm.assert_numpy_array_equal(result, orig.values) | ||
|
||
|
@@ -410,7 +418,9 @@ def test_value_counts_unique_nunique_null(self): | |
else: | ||
o = o.copy() | ||
o[0:2] = iNaT | ||
values = o._values | ||
# TODO(#24024) once Series._values returns DTA, remove | ||
# the `._eadata` here | ||
values = o._values._eadata | ||
|
||
elif needs_i8_conversion(o): | ||
values[0:2] = iNaT | ||
|
@@ -431,7 +441,7 @@ def test_value_counts_unique_nunique_null(self): | |
o = klass(values.repeat(range(1, len(o) + 1))) | ||
o.name = 'a' | ||
else: | ||
if is_datetime64tz_dtype(o): | ||
if isinstance(o, DatetimeIndex): | ||
expected_index = orig._values._shallow_copy(values) | ||
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. these are super-hacks, in future, let's try to remove |
||
else: | ||
expected_index = Index(values) | ||
|
@@ -472,8 +482,7 @@ def test_value_counts_unique_nunique_null(self): | |
Index(values[1:], name='a')) | ||
elif is_datetime64tz_dtype(o): | ||
# unable to compare NaT / nan | ||
vals = values[2:].astype(object).values | ||
tm.assert_numpy_array_equal(result[1:], vals) | ||
tm.assert_extension_array_equal(result[1:], values[2:]) | ||
assert result[0] is pd.NaT | ||
else: | ||
tm.assert_numpy_array_equal(result[1:], values[2:]) | ||
|
@@ -1187,7 +1196,6 @@ def test_ndarray_values(array, expected): | |
|
||
@pytest.mark.parametrize("arr", [ | ||
np.array([1, 2, 3]), | ||
np.array([1, 2, 3], dtype="datetime64[ns]"), | ||
]) | ||
def test_numpy_array(arr): | ||
ser = pd.Series(arr) | ||
|
@@ -1199,7 +1207,12 @@ def test_numpy_array(arr): | |
def test_numpy_array_all_dtypes(any_numpy_dtype): | ||
ser = pd.Series(dtype=any_numpy_dtype) | ||
result = ser.array | ||
assert isinstance(result, PandasArray) | ||
if is_datetime64_dtype(any_numpy_dtype): | ||
assert isinstance(result, DatetimeArray) | ||
elif is_timedelta64_dtype(any_numpy_dtype): | ||
assert isinstance(result, TimedeltaArray) | ||
else: | ||
assert isinstance(result, PandasArray) | ||
|
||
|
||
@pytest.mark.parametrize("array, attr", [ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
IntegerNA ?
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.
will edit. note otherwise this is verbatim from 24024