Skip to content

Commit 4c03fc7

Browse files
committed
Docs and cleanup
1 parent 3be5083 commit 4c03fc7

File tree

4 files changed

+40
-8
lines changed

4 files changed

+40
-8
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ Renamed the following offset aliases (:issue:`57986`):
504504

505505
Other Removals
506506
^^^^^^^^^^^^^^
507-
- :class:`.DataFrameGroupBy.idxmin`, :class:`.DataFrameGroupBy.idxmax`, :class:`.SeriesGroupBy.idxmin`, and :class:`.SeriesGroupBy.idxmax` will now raise a ``ValueError`` when used with ``skipna=False`` and an NA value is encountered (:issue:`10694`)
507+
- :class:`.DataFrameGroupBy.idxmin`, :class:`.DataFrameGroupBy.idxmax`, :class:`.SeriesGroupBy.idxmin`, and :class:`.SeriesGroupBy.idxmax` will now raise a ``ValueError`` when a group has all NA values, or when used with ``skipna=False`` and any NA value is encountered (:issue:`10694`)
508508
- :func:`concat` no longer ignores empty objects when determining output dtypes (:issue:`39122`)
509509
- :func:`concat` with all-NA entries no longer ignores the dtype of those entries when determining the result dtype (:issue:`40893`)
510510
- :func:`read_excel`, :func:`read_json`, :func:`read_html`, and :func:`read_xml` no longer accept raw string or byte representation of the data. That type of data must be wrapped in a :py:class:`StringIO` or :py:class:`BytesIO` (:issue:`53767`)

pandas/core/groupby/generic.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,15 @@ def idxmin(self, skipna: bool = True) -> Series:
14041404
Raises
14051405
------
14061406
ValueError
1407-
If the Series is empty or skipna=False and any value is NA.
1407+
When there are no valid values for a group. Then can happen if:
1408+
1409+
* There is an unobserved group and ``observed=False``.
1410+
* All values for a group are NA.
1411+
* Some values for a group are NA and ``skipna=False``.
1412+
1413+
.. versionchanged:: 3.0.0
1414+
Previously if all values for a group are NA or some values for a group are
1415+
NA and ``skipna=False`, this method would return NA. Now it raises instead.
14081416
14091417
See Also
14101418
--------
@@ -1457,7 +1465,15 @@ def idxmax(self, skipna: bool = True) -> Series:
14571465
Raises
14581466
------
14591467
ValueError
1460-
If the Series is empty or skipna=False and any value is NA.
1468+
When there are no valid values for a group. Then can happen if:
1469+
1470+
* There is an unobserved group and ``observed=False``.
1471+
* All values for a group are NA.
1472+
* Some values for a group are NA and ``skipna=False``.
1473+
1474+
.. versionchanged:: 3.0.0
1475+
Previously if all values for a group are NA or some values for a group are
1476+
NA and ``skipna=False`, this method would return NA. Now it raises instead.
14611477
14621478
See Also
14631479
--------
@@ -2597,7 +2613,15 @@ def idxmax(
25972613
Raises
25982614
------
25992615
ValueError
2600-
* If a column is empty or skipna=False and any value is NA.
2616+
When there are no valid values for a group. Then can happen if:
2617+
2618+
* There is an unobserved group and ``observed=False``.
2619+
* All values for a group are NA.
2620+
* Some values for a group are NA and ``skipna=False``.
2621+
2622+
.. versionchanged:: 3.0.0
2623+
Previously if all values for a group are NA or some values for a group are
2624+
NA and ``skipna=False`, this method would return NA. Now it raises instead.
26012625
26022626
See Also
26032627
--------
@@ -2663,7 +2687,15 @@ def idxmin(
26632687
Raises
26642688
------
26652689
ValueError
2666-
* If a column is empty or skipna=False and any value is NA.
2690+
When there are no valid values for a group. Then can happen if:
2691+
2692+
* There is an unobserved group and ``observed=False``.
2693+
* All values for a group are NA.
2694+
* Some values for a group are NA and ``skipna=False``.
2695+
2696+
.. versionchanged:: 3.0.0
2697+
Previously if all values for a group are NA or some values for a group are
2698+
NA and ``skipna=False`, this method would return NA. Now it raises instead.
26672699
26682700
See Also
26692701
--------

pandas/core/groupby/groupby.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1784,7 +1784,8 @@ def array_func(values: ArrayLike) -> ArrayLike:
17841784
new_mgr = data.grouped_reduce(array_func)
17851785
res = self._wrap_agged_manager(new_mgr)
17861786
if how in ["idxmin", "idxmax"]:
1787-
res = self._wrap_idxmax_idxmin(res, how=how, skipna=kwargs["skipna"])
1787+
# mypy expects how to be Literal["idxmin", "idxmax"].
1788+
res = self._wrap_idxmax_idxmin(res, how=how, skipna=kwargs["skipna"]) # type: ignore[arg-type]
17881789
out = self._wrap_aggregated_output(res)
17891790
return out
17901791

pandas/core/groupby/ops.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,8 +761,7 @@ def result_index(self) -> Index:
761761
def ids(self) -> npt.NDArray[np.intp]:
762762
return self.result_index_and_ids[1]
763763

764-
# @cache_readonly
765-
@property
764+
@cache_readonly
766765
def result_index_and_ids(self) -> tuple[Index, npt.NDArray[np.intp]]:
767766
levels = [Index._with_infer(ping.uniques) for ping in self.groupings]
768767
obs = [

0 commit comments

Comments
 (0)