Skip to content

BUG: Fix na_values dict not working on index column (#57547) #57965

New issue

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

By clicking “No 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? No Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2024
Merged

BUG: Fix na_values dict not working on index column (#57547) #57965

merged 1 commit into from
Apr 9, 2024

Conversation

tomhoq
Copy link
Contributor

@tomhoq tomhoq commented Mar 22, 2024

In the read_csv method, pandas allows having na_values set as a dict, which in such case lets you decide which values are null for each column. In the occurence of one of the columns being None, no null values are applied to the column and it remains as it was. This specific case is what is being tested in the issue #57547.

The problem was that in these particular conditions variables col_na_values and col_na_fvalues were not being set correctly causing a TypeError. All i had to do was correctly define these variables as empty sets in an else block.

On the python engine this same logic was not yet programmed. I implemented it, by adding an if statement, ensuring na_values are only applied if the column is not None.

* fix base_parser not setting col_na_values when na_values is a dict containing None

* fix python_parser applying na_values in a column None

* add unit test to test_na_values.py;

* update whatsnew.
@tomhoq
Copy link
Contributor Author

tomhoq commented Apr 7, 2024

@rhshadrach Would it be possible to ask someone to review this PR? Thank you

@mroeschke mroeschke added the IO CSV read_csv, to_csv label Apr 9, 2024
@mroeschke mroeschke added this to the 3.0 milestone Apr 9, 2024
@mroeschke mroeschke merged commit 5376e2a into pandas-dev:main Apr 9, 2024
50 checks passed
@mroeschke
Copy link
Member

Thanks @tomhoq

@tomhoq
Copy link
Contributor Author

tomhoq commented Apr 9, 2024

Thank you for the review

pmhatre1 pushed a commit to pmhatre1/pandas-pmhatre1 that referenced this pull request May 7, 2024
pandas-dev#57965)

BUG: Na_values dict not working on index column (pandas-dev#57547)

* fix base_parser not setting col_na_values when na_values is a dict containing None

* fix python_parser applying na_values in a column None

* add unit test to test_na_values.py;

* update whatsnew.
No Sign up for free to join this conversation on GitHub. Already have an account? No Sign in to comment
Labels
IO CSV read_csv, to_csv
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: na_values dict form not working on index column
2 participants