We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 227d8c4 commit 23bbe73Copy full SHA for 23bbe73
pandas/core/nanops.py
@@ -87,6 +87,21 @@ def _f(*args, **kwargs):
87
88
return _f
89
90
+class skipna_switch(object):
91
+
92
+ def __init__(self, alt):
93
+ self.alt = alt
94
95
+ def __call__(self, default):
96
97
+ @functools.wraps(default)
98
+ def f(values, axis=None, skipna=True, **kwds):
99
+ if skipna:
100
+ return default(values, axis, skipna, **kwds)
101
+ else:
102
+ return self.alt(values, axis, **kwds)
103
104
+ return f
105
106
class bottleneck_switch(object):
107
@@ -338,15 +353,13 @@ def nanmean(values, axis=None, skipna=True):
338
353
return _wrap_results(the_mean, dtype)
339
354
340
355
356
+@skipna_switch(np.median)
341
357
@disallow('M8')
342
358
@bottleneck_switch()
343
359
def nanmedian(values, axis=None, skipna=True):
344
360
345
361
values, mask, dtype, dtype_max = _get_values(values, skipna)
346
362
347
- if not skipna:
348
- return _wrap_results(np.median(values, axis=axis), dtype)
349
-
350
363
def get_median(x):
351
364
mask = notna(x)
352
365
if not skipna and not mask.all():
0 commit comments