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

fix: Pandas 3.0 warning for inplace method #642

Merged
merged 3 commits into from
Feb 6, 2024

Conversation

lars20070
Copy link
Contributor

@lars20070 lars20070 commented Feb 2, 2024

Related #637

Proposed Changes

Currently, the following warning for inplace methods in the upcoming Pandas 3.0 is triggered.

~/.venv/lib/python3.11/site-packages/influxdb_client/client/write/dataframe_serializer.py:237: FutureWarning: A value is trying to be set on a copy of a DataFrame or Series through chained assignment using an inplace method.
The behavior will change in pandas 3.0. This inplace method will never work because the intermediate object on which we are setting values always behaves as a copy.

For example, when doing 'df[col].method(value, inplace=True)', try using 'df.method({col: value}, inplace=True)' or df[col] = df[col].method(value) instead, to perform the operation inplace on the original object.

The pull request silences the warning.

Checklist

  • CHANGELOG.md updated
  • Rebased/mergeable
  • pytest tests completes successfully
  • Commit messages are conventional
  • Sign CLA (if not already signed)

@lars20070 lars20070 changed the title silence pandas 3.0 warning fix Pandas 3.0 warning for inplace method Feb 3, 2024
@lars20070 lars20070 changed the title fix Pandas 3.0 warning for inplace method fix: Pandas 3.0 warning for inplace method Feb 3, 2024
Copy link
Contributor

@bednar bednar left a comment

Choose a reason for hiding this comment

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

Hi @lars20070, first off, thank you for your contribution through the PR, it's greatly appreciated! 👍

Could you please explain why Pandas recommends using the syntax: For example, when doing 'df[col].method(value, inplace=True)', try using 'df.method({col: value}, inplace=True)'?

It seems our sources employ this recommended syntax.

Best Regards

@lars20070
Copy link
Contributor Author

Hi @bednar, Pandas is currently in version 2.2 with 3.0 scheduled for April 2024. No, I cannot explain why Pandas triggered the warning. But you might be on the safe side using option 2 and be prepared for the upcoming breaking changes. I can see your #638 changes but still get the warning from this line.

Copy link
Contributor

@bednar bednar left a comment

Choose a reason for hiding this comment

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

Hi @lars20070,

Thank you for your thorough explanation and for aligning your solution with best practices recommended by Pandas.

Before we proceed to merge your PR, could you please ensure that all items on our project's Checklist are satisfied?

image

After that we are be able to merge this PR.

Thanks again for your contribution 👍

@lars20070
Copy link
Contributor Author

lars20070 commented Feb 5, 2024

@bednar I struggle a bit to understand your setup. I am more familiar with Poetry projects. I would appreciate your input.

  • I have updated the CHANGELOG.md.
  • I forked yesterday. So no need to rebase. I see no merge conflicts.
  • pytest seems to pass. I see no failing tests.
  • Guess my commit message was not quite conventional.

Can you please explain what changes in the code are needed. I cannot see any merge conflicts or failing tests. Thanks.

@bednar
Copy link
Contributor

bednar commented Feb 5, 2024

@lars20070, please sign the CLA and check the checkbox so we can proceed with merging your PR.

@lars20070
Copy link
Contributor Author

Signed. Thanks @bednar.

Copy link
Contributor

@bednar bednar left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@lars20070
Copy link
Contributor Author

On a totally unrelated note. Any chance of looking into this issue?
Apologies for cross-posting.

@bednar
Copy link
Contributor

bednar commented Feb 6, 2024

@lars20070 unfurnetally I don't know anything about vsflux... I am at JetBrains IDEs ;)

@bednar bednar merged commit ed89701 into influxdata:master Feb 6, 2024
14 checks passed
@bednar bednar added this to the 1.41.0 milestone Feb 6, 2024
@lars20070 lars20070 deleted the fixpandas3warning branch February 6, 2024 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants