Skip to content
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

DateOffset add to ndarray #57927

Closed
wants to merge 3 commits into from
Closed

Conversation

hottwaj
Copy link

@hottwaj hottwaj commented Mar 20, 2024

This is WIP to implement changes needed to allow DateOffset subclasses e.g. MonthEnd to be directly added to numpy.ndarray, e.g. numpy.array(['2022-01-01'], dtype='datetime64') + pandas.offsets.MonthEnd(1)

I need some guidance on:

  • cython mechanism to check that passed ndarray is datetime64 dtype i.e.cython equivalent of pandas.api.types.is_datetime64_any_dtype
  • how to approach adding unit tests? two ideas I have
    • somehow duplicate existing offset tests but run them on ndarray instead of Series? looks on the surface to be more difficult to implement
    • apply a set of offsets to a predefined Series and ndarray equivalent, and then check results match

Many thanks!

if other.dtype == object:
return np.array([self + x for x in other])
elif is_datetime64_any_dtype(other):
return self._apply_array(other).astype(other.dtype)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need the astype here?

Copy link
Author

@hottwaj hottwaj Mar 27, 2024

Choose a reason for hiding this comment

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

I found that without this DateOffset._apply_array did not respect the dtype that was passed in

once the .astype step was added in, I could use e.g. datetime64[D] and get a datetime64[D] back

I'll do some further testing when working on unit tests

Copy link
Member

Choose a reason for hiding this comment

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

FWIW datetime64[D] is not a supported unit in pandas

Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

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

This would also need tests and a whatsnew note in v3.0.0.rst

@mroeschke mroeschke added Numeric Operations Arithmetic, Comparison, and Logical operations Frequency DateOffsets labels Mar 20, 2024
Copy link
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Apr 27, 2024
@mroeschke
Copy link
Member

Thanks for the pull request, but it appears to have gone stale. If interested in continuing, please merge in the main branch, address any review comments and/or failing tests, and we can reopen.

@mroeschke mroeschke closed this Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Frequency DateOffsets Numeric Operations Arithmetic, Comparison, and Logical operations Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: implement DateOffset + np.datetime64 array
3 participants