Skip to content

Commit 65e716a

Browse files
author
y-p
committed
BUG: df with dupe cols should raise KeyError on accessing non-existent col via list #2218
1 parent c8a45cb commit 65e716a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pandas/core/frame.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1796,13 +1796,18 @@ def _getitem_array(self, key):
17961796
indexer = self.columns.get_indexer(key)
17971797
mask = indexer == -1
17981798
if mask.any():
1799-
raise KeyError("No column(s) named: %s" % str(key[mask]))
1799+
raise KeyError("No column(s) named: %s" %
1800+
com.pprint_thing(key[mask]))
18001801
result = self.reindex(columns=key)
18011802
if result.columns.name is None:
18021803
result.columns.name = self.columns.name
18031804
return result
18041805
else:
18051806
mask = self.columns.isin(key)
1807+
for k in key:
1808+
if k not in self.columns:
1809+
raise KeyError("No column(s) named: %s" %
1810+
com.pprint_thing(k))
18061811
return self.take(mask.nonzero()[0], axis=1)
18071812

18081813
def _slice(self, slobj, axis=0):

0 commit comments

Comments
 (0)