Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

query("nested.b.isna()") fails #146

Closed
2 of 3 tasks
hombit opened this issue Sep 20, 2024 · 0 comments · Fixed by #150
Closed
2 of 3 tasks

query("nested.b.isna()") fails #146

hombit opened this issue Sep 20, 2024 · 0 comments · Fixed by #150
Assignees
Labels
bug Something isn't working

Comments

@hombit
Copy link
Collaborator

hombit commented Sep 20, 2024

Bug report

We cannot use built-in methods in queries because of an issue in the query parsing code:

from nested_pandas import NestedFrame

nf = NestedFrame.from_flat(NestedFrame({'a': [1, 2], 'b': [3, None]}, index=[1,1]), base_columns=[])
nf.query("nested.b.isna()")
File ~/.virtualenvs/v/lib/python3.12/site-packages/nested_pandas/nestedframe/core.py:357, in NestedFrame.query(self, expr)
    313 """
    314 Query the columns of a NestedFrame with a boolean expression. Specified
    315 queries can target nested columns in addition to the typical column set
   (...)
    353 >>> df.query("mynested.a > 2")
    354 """
    356 # Rebuild queries for each specified nested/base layer
--> 357 exprs_to_use = self._split_query(expr)
    359 # For now (simplicity), limit query to only operating on one layer
    360 if len(exprs_to_use.keys()) != 1:

File ~/.virtualenvs/v/lib/python3.12/site-packages/nested_pandas/nestedframe/core.py:293, in NestedFrame._split_query(self, expr)
    291 expr_slice = split_expr[i].strip("()")
    292 # Check if it's a nested column
--> 293 if self._is_known_hierarchical_column(expr_slice):
    294     nested, colname = split_expr[i].split(".")
    295     current_focus = nested.strip("()")

File ~/.virtualenvs/v/lib/python3.12/site-packages/nested_pandas/nestedframe/core.py:58, in NestedFrame._is_known_hierarchical_column(self, colname)
     56 """Determine whether a string is a known hierarchical column name"""
     57 if "." in colname:
---> 58     left, right = colname.split(".")
     59     if left in self.nested_columns:
     60         return right in self.all_columns[left]

ValueError: too many values to unpack (expected 2)

I believe it is related to #144, but probably would need a different fix

Before submitting
Please check the following:

  • I have described the situation in which the bug arose, including what code was executed, information about my environment, and any applicable data others will need to reproduce the problem.
  • I have included available evidence of the unexpected behavior (including error messages, screenshots, and/or plots) as well as a descriprion of what I expected instead.
  • If I have a solution in mind, I have provided an explanation and/or pseudocode and/or task list.
@hombit hombit added the bug Something isn't working label Sep 20, 2024
@gitosaurus gitosaurus self-assigned this Oct 9, 2024
@gitosaurus gitosaurus linked a pull request Oct 9, 2024 that will close this issue
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants