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

.normalize() doesn't work with .where() #691

Closed
critmcdonald opened this issue Sep 14, 2017 · 3 comments
Closed

.normalize() doesn't work with .where() #691

critmcdonald opened this issue Sep 14, 2017 · 3 comments
Labels

Comments

@critmcdonald
Copy link

I have a case where I can't filter a table after it has been run through .normalize(), getting an error IndexError: tuple index out of range.

It is a repeatable problem, but it is not always a problem. I've proven that I can also filter a simple normalized table. So, while this could be user error, I don't think so, but I would be happy to be proven wrong.

I have a repo that reproduces the problem in a notebook. But I also have an example where I can filter a normalized table.

@gutte
Copy link

gutte commented Apr 20, 2018

I also get IndexError: tuple index out of range when performing certain operations on a table that has been normalized using .normalize(). It seems to be something about how the column names are indexed.

Example:
table = agate.Table.from_csv('testinput.csv')
norm_table = table.normalize('student',['course1','course2','course3','course4'])
selection = norm_table.where(lambda row: row['property'] == 'course1') # THIS GIVES AN ERROR

where testinput.csv:
student,course1,course2,course3,course4
A,1,2,3,4
B,3,4,1,2
C,2,1,3,4
D,1,4,3,2
E,3,4,1,2

My reason for thinking that its not a user issue is that the problem can be worked around by temporarily writing the table to file and reading again, hence "fixing" the indexing:

norm_table.to_csv('temp.csv')
norm_table = agate.Table.from_csv('temp.csv')
selection = norm_table.where(lambda row: row['property'] == 'course1') # NO ERROR!

@jpmckinney
Copy link
Member

jpmckinney commented Jul 14, 2021

I think the issue is that normalize adds new rows, but it doesn't fill in row names for the new rows, so you end up getting an index error.

@jpmckinney
Copy link
Member

@gutte Thank you for sharing the easy-to-replicate code!

@jpmckinney jpmckinney changed the title Trouble filtering table that has been normalized .normalize() doesn't work with .where() Jul 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants