Skip to content

Conversation

@JonAnCla
Copy link

@JonAnCla JonAnCla 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

@JonAnCla JonAnCla 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
Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
@github-actions
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

3 participants