From 9ad43139b1ae6d9cf62fc57b92d117954cdd20de Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 9 Oct 2024 13:01:34 -0700 Subject: [PATCH] Remove the multi-dimensional error fallback from NestedFrame.query. 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. --- src/nested_pandas/nestedframe/core.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/nested_pandas/nestedframe/core.py b/src/nested_pandas/nestedframe/core.py index 1ad9e74..35038b9 100644 --- a/src/nested_pandas/nestedframe/core.py +++ b/src/nested_pandas/nestedframe/core.py @@ -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)