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

DEPR: Deprecate convert_float #41176

Merged
merged 13 commits into from May 26, 2021
Merged

Conversation

ahawryluk
Copy link
Contributor

I added tm.assert_produces_warning for every existing test that uses the convert_float argument, and a git grep only found one reference to convert_float in doc/. Is anything else required for a deprecation? IIUC, the actual feature would get removed in a pandas 2.0, correct?

@pep8speaks
Copy link

pep8speaks commented Apr 27, 2021

Hello @ahawryluk! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-05-25 16:38:24 UTC

@ahawryluk
Copy link
Contributor Author

ahawryluk commented Apr 27, 2021

I'm failing some checks due the warnings stacklevel. I think stacklevel=5 would be correct if the user calls pd.read_excel, but then it would be wrong for pd.ExcelFile.parse. What would you recommend?

@ahawryluk ahawryluk marked this pull request as draft April 28, 2021 14:35
@ahawryluk ahawryluk marked this pull request as ready for review April 28, 2021 18:12
@jreback jreback added Deprecate Functionality to remove in pandas IO Excel read_excel, to_excel labels Apr 30, 2021
@jreback jreback added this to the 1.3 milestone Apr 30, 2021
@jreback
Copy link
Contributor

jreback commented Apr 30, 2021

cc @rhshadrach @WillAyd

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, pending the stacklevel issue. I think this can be handled similarly to how the deprecation of xlrd was done.

caller = inspect.stack()[1]
if (
caller.filename.endswith(
os.path.join("pandas", "io", "excel", "_base.py")
)
and caller.function == "read_excel"
):
stacklevel = 4
else:
stacklevel = 2
warnings.warn(
f"Your version of xlrd is {xlrd_version}. In xlrd >= 2.0, "
f"only the xls format is supported. Install "
f"openpyxl instead.",
FutureWarning,
stacklevel=stacklevel,

IIUC, the actual feature would get removed in a pandas 2.0, correct?

Correct.

pandas/tests/io/excel/test_readers.py Show resolved Hide resolved
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, @jreback you good here?

mangle_dupe_cols=True,
**kwds,
):

if convert_float is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

this is slightly magical. can we instead have a function that shows the deprecation and just call it where appropriate so can set the stacklevel w/o this?

Copy link
Member

Choose a reason for hiding this comment

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

I don't see how this would get around needing logic to set the stacklevel. Maybe you're asking to move the logic to the new function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jreback @rhshadrach I've consolidated both stack inspections from _base.py into a single function. It seems like an improvement to me, but let me know if you see other adjustments I should make.

Copy link
Member

Choose a reason for hiding this comment

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

After rereading @jreback's comment, it now makes sense to me. The request is to move the deprecation itself to a function (not the determination of stacklevel), and call this further up in the call stack where we don't need to have any logic to determine the stacklevel. If this is doable, I agree it's a better approach.

Copy link
Member

Choose a reason for hiding this comment

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

I think this would work: move the warnings.warn to a function, call in both read_excel and ExcelFile.parse when appropriate, but in read_excel after emitting the warning change the value of convert_float. Does that make sense?

Copy link
Contributor

Choose a reason for hiding this comment

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

you might be able to use this: from pandas.util._exceptions import find_stack_level

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh nice. I looked at pandas.util._exceptions.find_stack_level when I made my last edit, but at the time it seemed specific to "astype" et al. so I tried making something similar. The edits from #41560 two days ago look great. I'll give it a try right away. (I couldn't see a clean way without stack inspection to raise a single warning from both read_excel and ExcelFile.parse. The latter isn't really advertised in the documentation, but it should still raise the correct warnings.)

@simonjayhawkins simonjayhawkins changed the title CLN: Deprecate convert_float DEPR: Deprecate convert_float May 24, 2021
@simonjayhawkins
Copy link
Member

@ahawryluk can you merge master to resolve conflicts

@ahawryluk
Copy link
Contributor Author

@jreback @rhshadrach I've updated the warnings in pandas/io/excel/_base.py to use the recently improved find_stack_level from pandas.utils._exceptions. One of the test suites failed, but I don't think it's related to excel routines. One of the error messages was "TypeError: Cannot cast array data from dtype('O') to dtype('<U') according to the rule 'unsafe'", and all the others were "FutureWarning: Promotion of numbers and bools to strings is deprecated."

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.

very nice - lgtm

@jreback jreback merged commit 0b8294e into pandas-dev:master May 26, 2021
@jreback
Copy link
Contributor

jreback commented May 26, 2021

thanks @ahawryluk very nice

@ahawryluk
Copy link
Contributor Author

Thanks everyone for your help

@ahawryluk ahawryluk deleted the depr_convert_floats branch May 26, 2021 17:03
TLouf pushed a commit to TLouf/pandas that referenced this pull request Jun 1, 2021
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecate Functionality to remove in pandas IO Excel read_excel, to_excel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CLN: consider deprecating convert_floats from read_excel
5 participants