-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
implement+test mean for datetimelike EA/Index/Series #24757
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 4 commits
434e2cd
c8abf33
30eeb64
d48e2ef
0e32be2
231458d
1129e8c
38f829a
aba90ec
176b355
ccb790b
4f4cb6d
ec83db1
5fb1db9
028c789
50e714e
1b24e7d
4d40906
a49da37
94d3466
e4e6a03
7953a7b
15307da
da719e1
637b415
58bca36
abcb87a
4df0b1c
c9736d7
d2f5e6f
de9025c
4c553a9
330fc41
7c6201b
642d4e2
7b9fd42
4be012f
5682b65
581ff1a
34a83a4
14150ee
450c8ce
3e31ca1
111c345
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1435,6 +1435,34 @@ def max(self, axis=None, skipna=True, *args, **kwargs): | |
# Don't have to worry about NA `result`, since no NA went in. | ||
return self._box_func(result) | ||
|
||
def mean(self, axis=None, skipna=True): | ||
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. Do we want to add an I would personally try to not add too much overhead in additional useless kwargs just for matching signatures, if they can be avoided. 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. IIRC, this lets us hook into 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. Yes, that's why we did it in the past (but for that we also need the additional kwargs). But, for EAs, we could also decide to implement the array function protocol to achieve this goal, which might obviate the need to add the additional 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. @jbrockmendel i think its worthile here to allow calling 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. don'e we also need out=? meaning we should just accept kwargs like we do for Series.mean |
||
""" | ||
Return the mean value of the Array or maximum along | ||
jbrockmendel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
an axis. | ||
|
||
TomAugspurger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
See Also | ||
-------- | ||
numpy.ndarray.mean | ||
Series.mean : Return the mean value in a Series. | ||
""" | ||
nv.validate_minmax_axis(axis) | ||
|
||
mask = self.isna() | ||
if skipna: | ||
values = self[~mask] | ||
elif mask.any(): | ||
return NaT | ||
else: | ||
values = self | ||
|
||
if not len(values): | ||
# short-circut for empty max / min | ||
return NaT | ||
|
||
result = nanops.nanmean(values.view('i8'), skipna=skipna) | ||
# Don't have to worry about NA `result`, since no NA went in. | ||
return self._box_func(result) | ||
|
||
|
||
# ------------------------------------------------------------------- | ||
# Shared Constructor Helpers | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,27 @@ def test_ops_properties_basic(self): | |
assert s.day == 10 | ||
pytest.raises(AttributeError, lambda: s.weekday) | ||
|
||
# TODO: figure out where in tests.reductions this belongs | ||
def test_mean(self, tz_naive_fixture): | ||
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. seems very duplicative of the test below, is there a reason? 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. bc at the time when this was written Index reduction tests had not been collected in tests.reductions. Will move/de-duplicate. |
||
tz = tz_naive_fixture | ||
idx1 = pd.DatetimeIndex(['2011-01-01', '2011-01-02', | ||
'2011-01-03'], tz=tz) | ||
assert idx1.mean() == pd.Timestamp('2011-01-02', tz=tz) | ||
assert idx1._data.mean() == pd.Timestamp('2011-01-02', tz=tz) | ||
|
||
idx2 = pd.DatetimeIndex(['2011-01-01', '2011-01-02', pd.NaT, | ||
'2011-01-03'], tz=tz) | ||
assert idx2.mean(skipna=False) is pd.NaT | ||
assert idx2._data.mean(skipna=False) is pd.NaT | ||
assert idx2.mean(skipna=True) == idx2[1] | ||
assert idx2._data.mean(skipna=True) == idx2[1] | ||
|
||
idx3 = pd.DatetimeIndex([]) | ||
assert idx3.mean() is pd.NaT | ||
assert idx3._data.mean() is pd.NaT | ||
assert idx3.mean(skipna=False) is pd.NaT | ||
assert idx3._data.mean(skipna=False) is pd.NaT | ||
|
||
def test_minmax_tz(self, tz_naive_fixture): | ||
tz = tz_naive_fixture | ||
# monotonic | ||
|
Uh oh!
There was an error while loading. Please reload this page.