Skip to content

Commit 9a07f9c

Browse files
committed
ERR: raise KeyError on invalid column name in aggregate
xref pandas-dev#19552
1 parent ccf9677 commit 9a07f9c

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

doc/source/whatsnew/v0.23.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ Groupby/Resample/Rolling
647647
- Bug in :func:`DataFrame.groupby` where aggregation by ``first``/``last``/``min``/``max`` was causing timestamps to lose precision (:issue:`19526`)
648648
- Bug in :func:`DataFrame.transform` where particular aggregation functions were being incorrectly cast to match the dtype(s) of the grouped data (:issue:`19200`)
649649
- Bug in :func:`DataFrame.groupby` passing the `on=` kwarg, and subsequently using ``.apply()`` (:issue:`17813`)
650-
- Bug in :func:`DataFrame.resample().aggregate` not raising a `ValueError` when aggregating a non-existent column (:issue:`16766`)
650+
- Bug in :func:`DataFrame.resample().aggregate` not raising a ``KeyError`` when aggregating a non-existent column (:issue:`16766`, :issue:`19566`)
651651

652652
Sparse
653653
^^^^^^

pandas/core/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def nested_renaming_depr(level=4):
394394
nested_renaming_depr()
395395
elif isinstance(obj, ABCDataFrame) and \
396396
k not in obj.columns:
397-
raise ValueError(
397+
raise KeyError(
398398
"Column '{col}' does not exist!".format(col=k))
399399

400400
arg = new_arg

pandas/tests/test_resample.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ def f():
613613
t[['A']].agg({'A': ['sum', 'std'],
614614
'B': ['mean', 'std']})
615615

616-
pytest.raises(ValueError, f)
616+
pytest.raises(KeyError, f)
617617

618618
def test_agg_nested_dicts(self):
619619

@@ -668,7 +668,7 @@ def test_try_aggregate_non_existing_column(self):
668668
df = DataFrame(data).set_index('dt')
669669

670670
# Error as we don't have 'z' column
671-
with pytest.raises(ValueError):
671+
with pytest.raises(KeyError):
672672
df.resample('30T').agg({'x': ['mean'],
673673
'y': ['median'],
674674
'z': ['sum']})

0 commit comments

Comments
 (0)