Skip to content

REF: move ExtensionIndex.map to be part of DatetimeLikeArrayMixin.map #51934

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 1 commit into from
Mar 14, 2023

Conversation

topper-123
Copy link
Contributor

@topper-123 topper-123 commented Mar 13, 2023

Follow-up to #51809.

ExtensionIndex.map is only used by the datetime-like indexes (DatetimeIndex.map etc.) and contains no index-specific functionality, so shouldn't be an index method.

By moving this method to DatetimeLikeArrayMixin.map we simplify the code paths quite a bit when dealing with DatetimeArray.map etc. In the next PR I will make na_action="ignore" work as expected and close #51644.

# Item "IndexOpsMixin" of "Union[IndexOpsMixin, ExtensionArray,
# ndarray[Any, Any]]" has no attribute "map"
return arr.map(mapper, na_action=na_action) # type: ignore[union-attr]
if isinstance(arr, ExtensionArray):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

DatetimeArray/DatetimeIndex etc. have numpy dtypes, so using is_extension_array_dtype isn't enough, we need to check for ExtensionArray to reach the .map method of datetime-likes.

@mroeschke mroeschke added the Refactor Internal refactoring of code label Mar 14, 2023
@mroeschke mroeschke added this to the 2.1 milestone Mar 14, 2023
@mroeschke mroeschke merged commit 3135c62 into pandas-dev:main Mar 14, 2023
@mroeschke
Copy link
Member

Thanks @topper-123

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Refactor Internal refactoring of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG/API: DTI/TDI/PI/IntervalIndex.map ignore na_action
2 participants