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

BUG: pd.options.future.no_silent_downcasting is not backward compatible #59845

Open
3 tasks done
vityas opened this issue Sep 20, 2024 · 1 comment
Open
3 tasks done
Labels
Bug Needs Info Clarification about behavior needed to assess issue PDEP6-related related to PDEP6 (not upcasting during setitem-like Series operations)

Comments

@vityas
Copy link

vityas commented Sep 20, 2024

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

with pd.option_context('future.no_silent_downcasting', True):
  pd.Series([None]).fillna(False)

Issue Description

I was not able to find a code that doesn't throw warnings for pandas >= 2.0. The example will work in pandas 2.2, but will break for earlier versions. Ahem... This is probably the first time in my Python development that a backwards incompatible change has been issued with a backwards incompatible workaround.

Expected Behavior

Not throw any warning.

i could do something like this

if pandas.__version__ >= '2.2.0':
  with pd.option_context('future.no_silent_downcasting', True):
    pd.Series([None]).fillna(False)
else:
  pd.Series([None]).fillna(False)

I suppose this code would work, but it's a bad code.

Installed Versions

pandas : 2.2.2
numpy : 1.26.3
pytz : 2024.1
dateutil : 2.8.1

@vityas vityas added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 20, 2024
@rhshadrach
Copy link
Member

Thanks for the report.

This is probably the first time in my Python development that a backwards incompatible change has been issued with a backwards incompatible workaround.

future.no_silent_downcasting was introduced so that users could adopt the future behavior of the breaking change, not to be a backwards compatible way to avoid the warning.

I suppose this code would work, but it's a bad code.

Why is it bad code? If you'd like to support multiple versions of pandas, I think you'll need to branch on the version. Though it is probably better practice to access the version via from importlib.metadata import version and not rely on string comparisons (e.g. https://packaging.pypa.io/en/latest/version.html).

@rhshadrach rhshadrach added Needs Info Clarification about behavior needed to assess issue PDEP6-related related to PDEP6 (not upcasting during setitem-like Series operations) and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Info Clarification about behavior needed to assess issue PDEP6-related related to PDEP6 (not upcasting during setitem-like Series operations)
Projects
None yet
Development

No branches or pull requests

2 participants