Skip to content

nanops.nanmedian typing fix #4

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

Merged
merged 1 commit into from
Nov 9, 2024
Merged
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
8 changes: 5 additions & 3 deletions pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ def nanmean(


@bottleneck_switch()
def nanmedian(values, *, axis: AxisInt | None = None, skipna: bool = True, mask=None):
def nanmedian(values: np.ndarray, *, axis: AxisInt | None = None, skipna: bool = True, mask=None) -> float | np.ndarray:
"""
Parameters
----------
Expand All @@ -738,7 +738,7 @@ def nanmedian(values, *, axis: AxisInt | None = None, skipna: bool = True, mask=

Returns
-------
result : float
result : float | ndarray
Unless input is a float array, in which case use the same
precision as the input array.

Expand All @@ -758,7 +758,7 @@ def nanmedian(values, *, axis: AxisInt | None = None, skipna: bool = True, mask=
# cases we never need to set NaN to the masked values
using_nan_sentinel = values.dtype.kind == "f" and mask is None

def get_median(x, _mask=None):
def get_median(x: np.ndarray, _mask=None):
if _mask is None:
_mask = notna(x)
else:
Expand Down Expand Up @@ -794,6 +794,8 @@ def get_median(x, _mask=None):

notempty = values.size

res: float | np.ndarray

# an array from a frame
if values.ndim > 1 and axis is not None:
# there's a non-empty array to apply over otherwise numpy raises
Expand Down