Skip to content

regression in 0.24: np.clip does not work for some values of a_min #25066

@sam-s

Description

@sam-s

Code Sample

import pandas as pd
import numpy as np
print(pd.__name__,pd.__version__,np.__name__,np.__version__)
np.clip(pd.Series([0,1,0,1]), 1e-7, 1)
np.clip(pd.Series([0,1,0,1]), 1e-8, 1)
np.clip(pd.Series([0.0,1.0,0.0,1.0]), 1e-8, 1)

Problem description

With pandas 0.23.4, numpy.clip works as expected, producing a Series of type float64 for any min argument.

With pandas 0.24.0, it works up to 1e-7 but not for 1e-8

>>> np.clip(pd.Series([0,1,0,1]), 1e-7, 1)
0    1.000000e-07
1    1.000000e+00
2    1.000000e-07
3    1.000000e+00
dtype: float64
>>> np.clip(pd.Series([0,1,0,1]), 1e-8, 1)
0    0
1    1
2    0
3    1
dtype: int64

This is an unwelcome change from the previous version.

Expected Output

>>> np.clip(pd.Series([0,1,0,1]), 1e-7, 1)
0    1.000000e-07
1    1.000000e+00
2    1.000000e-07
3    1.000000e+00
dtype: float64
>>> np.clip(pd.Series([0,1,0,1]), 1e-8, 1)
0    1.000000e-08
1    1.000000e+00
2    1.000000e-08
3    1.000000e+00
dtype: float64
>>> np.clip(pd.Series([0,1,0,1]), 1e-15, 1)
0    1.000000e-15
1    1.000000e+00
2    1.000000e-15
3    1.000000e+00
dtype: float64

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.7.2.final.0 python-bits: 64 OS: Darwin OS-release: 17.7.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: en_US.UTF-8 LANG: C LOCALE: en_US.UTF-8

pandas: 0.24.0
pytest: None
pip: 19.0.1
setuptools: 40.7.0
Cython: None
numpy: 1.16.0
scipy: 1.2.0
pyarrow: None
xarray: None
IPython: 7.2.0
sphinx: None
patsy: None
dateutil: 2.7.5
pytz: 2018.9
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 3.0.2
openpyxl: None
xlrd: 1.2.0
xlwt: None
xlsxwriter: 1.1.2
lxml.etree: 4.3.0
bs4: None
html5lib: None
sqlalchemy: 1.2.17
pymysql: None
psycopg2: 2.7.7 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    AlgosNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffBugRegressionFunctionality that used to work in a prior pandas version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions