Skip to content

BUG: np.min(pd.Index) and np.max(pd.Index) raise a TypeError #26125

Closed
@jschendel

Description

@jschendel

Code Sample, a copy-pastable example if possible

In [1]: import numpy as np; import pandas as pd

In [2]: np.__version__, pd.__version__
Out[2]: ('1.16.2', '0.25.0.dev0+421.g8b60ebb359')

In [3]: idx = pd.Index([10, 20, 11]); idx
Out[3]: Int64Index([10, 20, 11], dtype='int64')

In [4]: np.min(idx)
---------------------------------------------------------------------------
TypeError: min() got an unexpected keyword argument 'out'

In [5]: np.max(idx)
---------------------------------------------------------------------------
TypeError: max() got an unexpected keyword argument 'out'

Note that other numpy functions work fine:

In [6]: np.sum(idx), np.prod(idx), np.argmax(idx), np.argmin(idx)
Out[6]: (41, 2200, 1, 0)

And np.min and np.max work on other pandas data structures:

In [7]: s = pd.Series([10, 20, 11])

In [8]: np.min(s), np.max(s)
Out[8]: (10, 20)

In [9]: df = pd.DataFrame({'A': [10, 20, 11], 'B': [3, 1, 4]})

In [10]: np.min(df)
Out[10]:
A    10
B     1
dtype: int64

In [11]: np.max(df)
Out[11]:
A    20
B     4
dtype: int64

Problem description

Both np.min and np.max raise a TypeError when applied to a pd.Index. Using pd.Index.min and pd.Index.max is more idiomatic for pandas, but using the numpy equivalent functions should work, as they do for other pandas data structures.

Expected Output

I'd expect np.min(pd.Index) and np.max(pd.Index) to be equivalent to pd.Index.min and pd.Index.max, as is the case with other pandas data structures.

Output of pd.show_versions()

INSTALLED VERSIONS

commit: 8b60ebb
python: 3.6.8.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 78 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.25.0.dev0+421.g8b60ebb359
pytest: 4.2.0
pip: 19.0.1
setuptools: 40.6.3
Cython: 0.28.2
numpy: 1.16.2
scipy: 1.2.1
pyarrow: 0.6.0
xarray: 0.9.6
IPython: 7.2.0
sphinx: 1.8.2
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.9
feather: 0.4.0
matplotlib: 2.0.2
openpyxl: 2.4.8
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 0.9.8
lxml.etree: 3.8.0
bs4: None
html5lib: 0.999
sqlalchemy: 1.1.13
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
fastparquet: 0.1.5
pandas_gbq: None
pandas_datareader: None
gcsfs: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions