-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
REF: Simplify Datetimelike constructor dispatching #23140
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
Changes from 1 commit
f13cc58
4188ec7
7804f1b
a4775f4
8ee34fa
78943c1
aa71383
eae8389
e871733
7840f91
ec50b0b
eb7a6b6
32c6391
c903917
b97ec96
11db555
147de57
7c4d281
b90f421
dc4f474
46d5e64
b5827c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -430,10 +430,7 @@ def min(self, axis=None, *args, **kwargs): | |
-------- | ||
numpy.ndarray.min | ||
""" | ||
if axis is not None and axis >= self.ndim: | ||
raise ValueError("`axis` must be fewer than the number of " | ||
"dimensions ({ndim})".format(ndim=self.ndim)) | ||
|
||
_validate_minmax_axis(axis) | ||
nv.validate_min(args, kwargs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there reason not to add the axis validation to the existing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exactly I don't want another function, rather you can simply check this in side the function which is already there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. I'm not wild about the fact that the nv.validate_(min|max|argmin|argmax) functions now implicitly assume they are only being called on 1-dim objects, but at least the assumption is correct for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, yeah, that makes sense. |
||
|
||
try: | ||
|
@@ -462,10 +459,7 @@ def argmin(self, axis=None, *args, **kwargs): | |
-------- | ||
numpy.ndarray.argmin | ||
""" | ||
if axis is not None and axis >= self.ndim: | ||
raise ValueError("`axis` must be fewer than the number of " | ||
"dimensions ({ndim})".format(ndim=self.ndim)) | ||
|
||
_validate_minmax_axis(axis) | ||
nv.validate_argmin(args, kwargs) | ||
|
||
i8 = self.asi8 | ||
|
@@ -486,10 +480,7 @@ def max(self, axis=None, *args, **kwargs): | |
-------- | ||
numpy.ndarray.max | ||
""" | ||
if axis is not None and axis >= self.ndim: | ||
raise ValueError("`axis` must be fewer than the number of " | ||
"dimensions ({ndim})".format(ndim=self.ndim)) | ||
|
||
_validate_minmax_axis(axis) | ||
nv.validate_max(args, kwargs) | ||
|
||
try: | ||
|
@@ -518,10 +509,7 @@ def argmax(self, axis=None, *args, **kwargs): | |
-------- | ||
numpy.ndarray.argmax | ||
""" | ||
if axis is not None and axis >= self.ndim: | ||
raise ValueError("`axis` must be fewer than the number of " | ||
"dimensions ({ndim})".format(ndim=self.ndim)) | ||
|
||
_validate_minmax_axis(axis) | ||
nv.validate_argmax(args, kwargs) | ||
|
||
i8 = self.asi8 | ||
|
@@ -722,6 +710,25 @@ def _time_shift(self, periods, freq=None): | |
return result | ||
|
||
|
||
def _validate_minmax_axis(axis): | ||
""" | ||
Ensure that the axis argument passed to min, max, argmin, or argmax is | ||
zero or None, as otherwise it will be incorrectly ignored. | ||
|
||
Parameters | ||
---------- | ||
axis : int or None | ||
|
||
Raises | ||
------ | ||
ValueError | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see my comment above |
||
ndim = 1 # hard-coded for Index | ||
if axis is not None and axis >= ndim: | ||
raise ValueError("`axis` must be fewer than the number of " | ||
"dimensions ({ndim})".format(ndim=ndim)) | ||
|
||
|
||
def _ensure_datetimelike_to_i8(other, to_utc=False): | ||
""" | ||
helper for coercing an input scalar or array to i8 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not what i mean
add this specifically to no.validate_* there are mechanisms for this already
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, done.