Skip to content

BUG:error in reading a boolean column with blanks from excel file #45903 #46374

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

Closed
wants to merge 6 commits into from

Conversation

dimitra-karadima
Copy link
Contributor

Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the work on this @dimitra-karadima.

I added couple of comments, in particular, I'd like to understand better your approach. It may be correct, but it's not immediately clear why this is the right fix.

Also, do you think it could make sense to use a new column in test_types.xls (and the other formats) instead of creating the new files?

@@ -294,6 +294,7 @@ class BooleanArray(BaseMaskedArray):
# Fill values used for any/all
_truthy_value = True
_falsey_value = False
_NONE_VALUES = {"nan", "NaN", "None", "NA", "null", "NULL"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fail to understand how this is related to having blanks. In the current version of pandas (without the changes in this PR), what's the value of the blank value in the spreadsheet when constructing the extension array? Feels like it should be None or an empty string, not one of those.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@datapythonista Hello! Thanks for the review! The point here is that I added this list because the isna() fails. The None values are converted into strings so without this list, the "None" values will raise a ValueError. Of course if you have any suggestion on how to implement this better please tell me.

"boolean_with_blanks" + read_ext, dtype={"var1": "boolean"}
)
expected = DataFrame(
[[True], [False], [None], [True]], columns=["var1"], dtype="boolean"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[[True], [False], [None], [True]], columns=["var1"], dtype="boolean"
{'var1': [True, False, None, True}, dtype="boolean"

This seems simpler and easier to read and maintain.

@datapythonista datapythonista added Bug IO Excel read_excel, to_excel ExtensionArray Extending pandas with custom dtypes or arrays. NA - MaskedArrays Related to pd.NA and nullable extension arrays labels Apr 5, 2022
@@ -420,8 +420,10 @@ def test_reader_special_dtypes(self, request, read_ext):
datetime(2013, 12, 14),
datetime(2015, 3, 14),
],
"BoolColWithBlank": [True, False, None, True, False],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@datapythonista I upated the test_types files as you suggested but for some reason no False or True values are shown. Only 1 or 0 and I cannot find out why.

@github-actions
Copy link
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label May 12, 2022
@mroeschke
Copy link
Member

Thanks for the pull request, but it appears to have gone stale. If interested in continuing, please merge in the main branch, address any review comments and/or failing tests, and we can reopen.

@mroeschke mroeschke closed this Jun 10, 2022
@asishm asishm mentioned this pull request Jun 2, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug ExtensionArray Extending pandas with custom dtypes or arrays. IO Excel read_excel, to_excel NA - MaskedArrays Related to pd.NA and nullable extension arrays Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Reading a Boolean column with "blanks" from an Excel file raises an absurd error
3 participants