Commit d409035
BUG: Fix behavior of argmax and argmin with inf (#16449)
Closes #13595
The implementations of `nanargmin` and `nanargmax` in `nanops` were
forcing the `_get_values` utility function to always mask out infinite
values. For example, in `nanargmax`,
>>> nanops._get_values(np.array([1, np.nan, np.inf]), True,
isfinite=True, fill_value_typ='-inf')
(array([ 1., -inf, -inf]),
array([False, True, True], dtype=bool),
dtype('float64'),
numpy.float64)
The first element of the result tuple (the masked version of the
values array) is used for actually finding the max or min argument. As
a result, infinite values could never be correctly recognized as the
maximum or minimum values in an array.
This also affects the behavior of `DataFrame.groupby.idxmax`: since
`Series.idxmax` previously raised a `ValueError` with string data, the
group by would silently drop columns that contained strings.1 parent 18f7b1c commit d409035
File tree
4 files changed
+72
-7
lines changed- doc/source/whatsnew
- pandas
- core
- tests
- groupby
- series
4 files changed
+72
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
130 | | - | |
| 130 | + | |
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
474 | 474 | | |
475 | 475 | | |
476 | 476 | | |
477 | | - | |
478 | | - | |
| 477 | + | |
479 | 478 | | |
480 | 479 | | |
481 | 480 | | |
| |||
485 | 484 | | |
486 | 485 | | |
487 | 486 | | |
488 | | - | |
489 | | - | |
| 487 | + | |
490 | 488 | | |
491 | 489 | | |
492 | 490 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2339 | 2339 | | |
2340 | 2340 | | |
2341 | 2341 | | |
2342 | | - | |
| 2342 | + | |
| 2343 | + | |
2343 | 2344 | | |
2344 | 2345 | | |
2345 | 2346 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
1857 | 1857 | | |
1858 | 1858 | | |
1859 | 1859 | | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
| 1868 | + | |
| 1869 | + | |
| 1870 | + | |
| 1871 | + | |
| 1872 | + | |
| 1873 | + | |
| 1874 | + | |
| 1875 | + | |
| 1876 | + | |
| 1877 | + | |
| 1878 | + | |
| 1879 | + | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
| 1889 | + | |
| 1890 | + | |
| 1891 | + | |
| 1892 | + | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
| 1897 | + | |
| 1898 | + | |
| 1899 | + | |
| 1900 | + | |
| 1901 | + | |
| 1902 | + | |
| 1903 | + | |
| 1904 | + | |
| 1905 | + | |
| 1906 | + | |
| 1907 | + | |
| 1908 | + | |
| 1909 | + | |
| 1910 | + | |
| 1911 | + | |
| 1912 | + | |
| 1913 | + | |
| 1914 | + | |
| 1915 | + | |
| 1916 | + | |
| 1917 | + | |
| 1918 | + | |
| 1919 | + | |
| 1920 | + | |
| 1921 | + | |
| 1922 | + | |
| 1923 | + | |
| 1924 | + | |
| 1925 | + | |
0 commit comments