Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: winsorize nan policy #15660

@ari-stat

Description

@ari-stat

Describe your issue.

nan handling in winsorize for 'omit' option does not work properly. It seems to count nans as larger than any number, so if there are other large numbers they may not be winsorized. In the example below, I have 108 numbers, and winsorizing at 1% level (so max and min should be winsorized). The max (which is the last number in the array) is unchanged.

Reproducing Code Example

from scipy.stats.mstats import winsorize
import numpy as np

a = np.random.standard_normal(108)
a[0] = np.nan
a[-1] = 80

winsorize(a, limits=(0.01,0.01), nan_policy='omit')

Error message

No error, but the last element of the output array is still 80, when it is clearly the largest element in the array.  The code seems to be treating nan as the largest element.

SciPy/NumPy/Python version information

1.7.1 1.20.3 sys.version_info(major=3, minor=9, micro=7, releaselevel='final', serial=0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    defectA clear bug or issue that prevents SciPy from being installed or used as expectedscipy.stats

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions