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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,11 @@ cdef class BaseOffset:
return type(self)(n=1, normalize=self.normalize, **self.kwds)

def __add__(self, other):
if util.is_array(other) and other.dtype == object:
return np.array([self + x for x in other])
if util.is_array(other):
if other.dtype == object:
return np.array([self + x for x in other])
elif other.dtype.kind == "M":
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


try:
return self._apply(other)
Expand Down
Loading