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):
202202 nested = item .split ("." )[0 ]
203203 col = "." .join (item .split ("." )[1 :])
204204 return self [nested ].nest .get_flat_series (col )
205+ else :
206+ raise KeyError (f"Column '{ item } ' not found in nested columns or base columns" )
205207 else :
206208 return super ().__getitem__ (item )
207209
Original file line number Diff line number Diff line change @@ -1014,3 +1014,10 @@ def test_eval_assignment():
10141014 assert set (nf .p2 .nest .fields ) == {"e" , "f" }
10151015 assert (nf ["p2.e" ] == nf ["packed.d" ] * 2 + nf .c ).all ()
10161016 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