-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
test backportability of #38120 #38137
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
Closed
simonjayhawkins
wants to merge
4
commits into
pandas-dev:1.1.x
from
simonjayhawkins:test-backportability-of-38120
Closed
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,11 +46,14 @@ | |
pandas_dtype, | ||
) | ||
from pandas.core.dtypes.generic import ( | ||
ABCDatetimeArray, | ||
ABCExtensionArray, | ||
ABCIndex, | ||
ABCIndexClass, | ||
ABCMultiIndex, | ||
ABCRangeIndex, | ||
ABCSeries, | ||
ABCTimedeltaArray, | ||
) | ||
from pandas.core.dtypes.missing import isna, na_value_for_dtype | ||
|
||
|
@@ -191,8 +194,15 @@ def _reconstruct_data( | |
------- | ||
ExtensionArray or np.ndarray | ||
""" | ||
if is_extension_array_dtype(dtype): | ||
values = dtype.construct_array_type()._from_sequence(values) | ||
if isinstance(values, ABCExtensionArray) and values.dtype == dtype: | ||
# Catch DatetimeArray/TimedeltaArray | ||
return values | ||
elif is_extension_array_dtype(dtype): | ||
cls = dtype.construct_array_type() | ||
if isinstance(values, cls) and values.dtype == dtype: | ||
return values | ||
|
||
values = cls._from_sequence(values) | ||
elif is_bool_dtype(dtype): | ||
values = values.astype(dtype, copy=False) | ||
|
||
|
@@ -652,8 +662,13 @@ def factorize( | |
# responsible only for factorization. All data coercion, sorting and boxing | ||
# should happen here. | ||
|
||
if isinstance(values, ABCRangeIndex): | ||
return values.factorize(sort=sort) | ||
|
||
values = _ensure_arraylike(values) | ||
original = values | ||
if not isinstance(values, ABCMultiIndex): | ||
values = extract_array(values, extract_numpy=True) | ||
|
||
# GH35667, if na_sentinel=None, we will not dropna NaNs from the uniques | ||
# of values, assign na_sentinel=-1 to replace code value for NaN. | ||
|
@@ -662,6 +677,19 @@ def factorize( | |
na_sentinel = -1 | ||
dropna = False | ||
|
||
if ( | ||
isinstance(values, (ABCDatetimeArray, ABCTimedeltaArray)) | ||
and values.freq is not None | ||
): | ||
codes, uniques = values.factorize(sort=sort) | ||
if isinstance(original, ABCIndexClass): | ||
uniques = original._shallow_copy(uniques, name=None) | ||
elif isinstance(original, ABCSeries): | ||
from pandas import Index | ||
|
||
uniques = Index(uniques) | ||
return codes, uniques | ||
|
||
if is_extension_array_dtype(values.dtype): | ||
values = extract_array(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. there was a merge conflict here, and should have removed this line 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. when the current ci has completed, will remove this and check not needed. |
||
codes, uniques = values.factorize(na_sentinel=na_sentinel) | ||
|
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
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.
this was moved in the PR but not on 1.1.x so may need to remove
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.
RangeIndex.factorize was added in #38034, so this causes a recursion error, removing.