Skip to content

PROPOSAL: use datetime64 and timedelta64 to eval #22063

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
16 changes: 16 additions & 0 deletions pandas/compat/numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ def np_array_datetime64_compat(arr, *args, **kwargs):
return np.array(arr, *args, **kwargs)


# np.percentile should support datetime64 in upsteam. numpy/numpy#11620
# TODO: change the version if the bug fixed
if _nlv >= '99.99.99':
Copy link
Member

Choose a reason for hiding this comment

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

Is this just a placeholder for "distant future"?

np_percentile_compat = np.percentile
else:
def np_percentile_compat(values, q, **kw):
Copy link
Member

Choose a reason for hiding this comment

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

the iNat concern aside, this looks like a nice function. But I don't see why it should be in compat. Might make more sense in nanops?

'''
provide compat for np.percentile supporting datetime64
'''
if values.dtype.kind == 'M':
Copy link
Member

Choose a reason for hiding this comment

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

Does timedelta64 get handled correctly by numpy?

result = np.percentile(values.view('i8'), q, **kw)
Copy link
Member

Choose a reason for hiding this comment

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

Will this handle iNaT correctly?

return result.astype(values.dtype)
else:
return np.percentile(values, q, **kw)


__all__ = ['np',
'_np_version_under1p10',
'_np_version_under1p11',
Expand Down
Loading