Skip to content

ENH: Allow dt accessor when using ArrowDtype with datetime types #50954

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 19 commits into from
Feb 8, 2023

Conversation

mroeschke
Copy link
Member

Enabled & tested for pa.timestamp types so far. Will follow up with pa.duration types in a subsequent PR

@mroeschke mroeschke added the Arrow pyarrow functionality label Jan 24, 2023
@mroeschke mroeschke modified the milestone: 2.0 Jan 26, 2023
@mroeschke
Copy link
Member Author

Any other comments here @jbrockmendel ?

@jbrockmendel
Copy link
Member

will take another look

Callable to map the delegate's function to the cls' function.
raise_on_missing: bool, default True
Raise if an accessor does not exist on delegate.
False skips the missing accessor.
Copy link
Member

Choose a reason for hiding this comment

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

do you expect to reuse this machinery again? if not, could the pyarrow-dt be accessor be implemented standalone to avoid making this more complicaed?

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 am hoping to use this for the pyarrow duration types as well.

I think a standalone implementation would require a further refactoring of this dt accessor. Looks like currently datetime and timedelta dispatch to the Index while we probably need something that dispatches to the array

@@ -472,6 +559,8 @@ def __new__(cls, data: Series):
index=orig.index,
)

if isinstance(data.dtype, ArrowDtype) and data.dtype.kind in "mM":
Copy link
Member

Choose a reason for hiding this comment

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

is it "mM" or just "M"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks yeah this should be "M" until pa.duration is supported

fget=_getter, fset=_setter, doc=getattr(delegate, name).__doc__
fget=_getter,
fset=_setter,
doc=getattr(delegate, accessor_mapping(name)).__doc__,
Copy link
Member

Choose a reason for hiding this comment

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

can we do this once near the top?

Copy link
Member

Choose a reason for hiding this comment

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

ill put this into my next Assorted Cleanups branch

Copy link
Member

@jbrockmendel jbrockmendel left a comment

Choose a reason for hiding this comment

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

LGTM pending green

@mroeschke mroeschke merged commit bd508de into pandas-dev:main Feb 8, 2023
@mroeschke mroeschke deleted the enh/dt/arrow branch February 8, 2023 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arrow pyarrow functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants