Skip to content

CLN: remove redundant openpyxl type conversions #39782

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

Merged
merged 2 commits into from
Feb 15, 2021

Conversation

ahawryluk
Copy link
Contributor

openpyxl already converts cell values to Python types, preferring
integers where possible. For backwards-compatibility, we have to convert
integers back to float if not convert_float

  • closes #xxxx
  • tests passed
  • Ensure all linting tests pass, see here for how to run them
  • whatsnew entry

openpyxl already converts cell values to Python types, preferring
integers where possible. For backwards-compatibility, we have to convert
integers back to float if not `convert_float`
elif cell.data_type == TYPE_ERROR:
return np.nan
elif cell.data_type == TYPE_BOOL:
return bool(cell.value)
Copy link
Member

Choose a reason for hiding this comment

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

Are there tests for bool/int/etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes there are. If I break the function to return

  • all numbers as float, 198 tests fail
  • all numbers as int, 211 tests fail
  • all bools as int, 20 tests fail
  • all bools as str, zero tests fail because TextParser does its own conversions

Thanks for taking them time to look at my first pull request. Let me know if there's anything that needs to be improved.

Copy link
Member

Choose a reason for hiding this comment

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

Great - thanks for checking.

Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

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

lgtm - very nice cleanup.

elif cell.data_type == TYPE_ERROR:
return np.nan
elif cell.data_type == TYPE_BOOL:
return bool(cell.value)
Copy link
Member

Choose a reason for hiding this comment

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

Great - thanks for checking.

@rhshadrach rhshadrach added Clean IO Excel read_excel, to_excel labels Feb 13, 2021
@rhshadrach rhshadrach added this to the 1.3 milestone Feb 13, 2021
@jreback jreback merged commit a233a5c into pandas-dev:master Feb 15, 2021
@jreback
Copy link
Contributor

jreback commented Feb 15, 2021

thanks @ahawryluk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean IO Excel read_excel, to_excel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants