Skip to content

Commit

Permalink
Remove the multi-dimensional error fallback from NestedFrame.query.
Browse files Browse the repository at this point in the history
This logic was copied from pd.DataFrame.query, and the accompanying
comment said that it was to handle an occasional case where
`self.loc[b]` would raise an error on a multi-dimensional `b`, but
`self[b]` would succeed.  I can't cause this error with `.loc` anymore,
so the code coverage complains about the unexercised exception
clause.  Removing it since the limitation that inspired it seems
to be gone now.
  • Loading branch information
gitosaurus committed Oct 9, 2024
1 parent 838ae68 commit 9ad4313
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/nested_pandas/nestedframe/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,18 +475,13 @@ def query(self, expr: str, *, inplace: bool = False, **kwargs) -> NestedFrame |
# which means that a nested attribute was referenced. Apply this result
# to the nest and repack. Otherwise, apply it to this instance as usual,
# since it operated on the base attributes.
try:
if isinstance(result, NestedSeries):
nest_name, flat_nest = result.nest_name, result.flat_nest
new_flat_nest = flat_nest.loc[result]
result = self.copy()
result[nest_name] = pack_sorted_df_into_struct(new_flat_nest)
else:
result = self.loc[result]
except ValueError:
# when res is multi-dimensional loc raises, but this is sometimes a
# valid query
result = self[result]
if isinstance(result, NestedSeries):
nest_name, flat_nest = result.nest_name, result.flat_nest
new_flat_nest = flat_nest.loc[result]
result = self.copy()
result[nest_name] = pack_sorted_df_into_struct(new_flat_nest)
else:
result = self.loc[result]

if inplace:
self._update_inplace(result)
Expand Down

0 comments on commit 9ad4313

Please sign in to comment.