File tree Expand file tree Collapse file tree 2 files changed +9
-0
lines changed
src/nested_pandas/nestedframe
tests/nested_pandas/nestedframe Expand file tree Collapse file tree 2 files changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -202,6 +202,8 @@ def __getitem__(self, item):
202
202
nested = item .split ("." )[0 ]
203
203
col = "." .join (item .split ("." )[1 :])
204
204
return self [nested ].nest .get_flat_series (col )
205
+ else :
206
+ raise KeyError (f"Column '{ item } ' not found in nested columns or base columns" )
205
207
else :
206
208
return super ().__getitem__ (item )
207
209
Original file line number Diff line number Diff line change @@ -1014,3 +1014,10 @@ def test_eval_assignment():
1014
1014
assert set (nf .p2 .nest .fields ) == {"e" , "f" }
1015
1015
assert (nf ["p2.e" ] == nf ["packed.d" ] * 2 + nf .c ).all ()
1016
1016
assert (nf ["p2.f" ] == nf ["p2.e" ] + nf .b ).all ()
1017
+
1018
+
1019
+ def test_access_non_existing_column ():
1020
+ """Test that accessing a non-existing column raises a KeyError"""
1021
+ nf = NestedFrame ()
1022
+ with pytest .raises (KeyError ):
1023
+ _ = nf ["non_existing_column" ]
You can’t perform that action at this time.
0 commit comments