Skip to content

Commit 1705532

Browse files
committed
add NullKeyWarning
1 parent 20d5b1c commit 1705532

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

doc/source/reference/testing.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Exceptions and warnings
4646
errors.MergeError
4747
errors.NoBufferPresent
4848
errors.NullFrequencyError
49+
errors.NullKeyWarning
4950
errors.NumbaUtilError
5051
errors.NumExprClobberingError
5152
errors.OptionError

pandas/errors/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,29 @@ class CategoricalConversionWarning(Warning):
878878
"""
879879

880880

881+
class NullKeyWarning(Warning):
882+
"""
883+
Warning raised when grouping on null/NA keys with default `dropna` argument.
884+
885+
This warning helps ensure data integrity and alerts users to potential issues
886+
during grouping/aggregating when the default value of `dropna` would lead to
887+
null keys being dropped from the output.
888+
889+
For more information, see discussion of [PDEP-11](#53094)
890+
891+
See Also
892+
--------
893+
DataFrame.groupby : Group DataFrame using a mapper or by a Series of columns.
894+
DataFrame.pivot_table : Create a spreadsheet-style pivot table as a DataFrame.
895+
896+
Examples
897+
--------
898+
>>> df = pd.DataFrame({"A": ["a", None], "B": [1, 2]})
899+
>>> df.groupby(["A"]).sum() # doctest: +SKIP
900+
... # NullKeyWarning: ...
901+
"""
902+
903+
881904
class LossySetitemError(Exception):
882905
"""
883906
Raised when trying to do a __setitem__ on an np.ndarray that is not lossless.
@@ -927,6 +950,7 @@ class InvalidComparison(Exception):
927950
"MergeError",
928951
"NoBufferPresent",
929952
"NullFrequencyError",
953+
"NullKeyWarning",
930954
"NumExprClobberingError",
931955
"NumbaUtilError",
932956
"OptionError",

0 commit comments

Comments
 (0)