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

Address pandas deprecation warnings #1995

Merged
merged 3 commits into from
Mar 19, 2024
Merged

Conversation

kandersolar
Copy link
Member

@kandersolar kandersolar commented Mar 18, 2024

  • [ ] Closes #xxxx
  • I am familiar with the contributing guidelines
  • Tests added
  • [ ] Updates entries in docs/sphinx/source/reference for API changes.
  • [ ] Adds description and name entries in the appropriate "what's new" file in docs/sphinx/source/whatsnew for all changes. Includes link to the GitHub Issue with :issue:`num` or this Pull Request with :pull:`num`. Includes contributor name and/or GitHub username (link with :ghuser:`user`).
  • [ ] New code is fully documented. Includes numpydoc compliant docstrings, examples, and comments where necessary.
  • Pull request is nearly complete and ready for detailed review.
  • Maintainer: Appropriate GitHub Labels (including remote-data) and Milestone are assigned to the Pull Request and linked Issue.

See #1994 (comment).

This PR addresses many pandas deprecation warnings. Most of them are just frequency string replacements like H -> h in calls to pd.date_range, but there are some others as well. For future reference, here are the warnings addressed:

  • "FutureWarning: 'H' is deprecated and will be removed in a future version, please use 'h' instead.",
  • "FutureWarning: 'H' is deprecated and will be removed in a future version. Please use 'h' instead of 'H'.",
  • "FutureWarning: 'T' is deprecated and will be removed in a future version, please use 'min' instead.",
  • 'FutureWarning: ChainedAssignmentError: behaviour will change in pandas 3.0!',
  • "FutureWarning: The 'delim_whitespace' keyword in pd.read_csv is deprecated and will be removed in a future version. Use sep='\\s+' instead",

There are two warnings remaining. The first is:

  • "FutureWarning: 'M' is deprecated and will be removed in a future version, please use 'ME' instead.",

ME doesn't exist until pandas 2.2, so we can't use it yet. This is only four warnings in test_clearsky.py, so we can live with it for now.

The second is a warning where we are already doing the right/future-compatible thing, but I don't know how to suppress the warning. I guess we should ignore it until it eventually goes away:

  • /home/runner/work/pvlib-python/pvlib-python/pvlib/iotools/acis.py:416: FutureWarning: Downcasting behavior in replace is deprecated and will be removed in a future version. To retain the old behavior, explicitly call result.infer_objects(copy=False). To opt-in to the future behavior, set pd.set_option('future.no_silent_downcasting', True)

@kandersolar kandersolar added this to the v0.10.4 milestone Mar 18, 2024
@kandersolar kandersolar added the remote-data triggers --remote-data pytests label Mar 18, 2024
looks like ME only exists for pandas 2.2+
@kandersolar kandersolar added remote-data triggers --remote-data pytests and removed remote-data triggers --remote-data pytests labels Mar 18, 2024
@kandersolar kandersolar marked this pull request as ready for review March 18, 2024 23:44
@kandersolar
Copy link
Member Author

Ready for review. The linter is complaining about lines I didn't touch, so I didn't fix them. I'm not sure why codecov is failing.

@@ -146,7 +146,7 @@ def read_surfrad(filename, map_variables=True):
metadata['surfrad_version'] = int(metadata_list[-1])
metadata['tz'] = 'UTC'

data = pd.read_csv(file_buffer, delim_whitespace=True,
data = pd.read_csv(file_buffer, sep=r'\s+',
Copy link
Member

Choose a reason for hiding this comment

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

The warning states:

"FutureWarning: The 'delim_whitespace' keyword in pd.read_csv is deprecated and will be removed in a future version. Use sep='\s+' instead",

Is there a reason that you're using a single backslash?

Copy link
Member Author

Choose a reason for hiding this comment

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

sep='\\s+' is equivalent to sep=r'\s+', I just preferred to use an r string instead of escaping the backslash

Copy link
Member

Choose a reason for hiding this comment

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

I figured - thanks for letting me know!

@kandersolar kandersolar merged commit f787047 into pvlib:main Mar 19, 2024
38 of 41 checks passed
@kandersolar kandersolar deleted the testfix branch March 19, 2024 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
remote-data triggers --remote-data pytests testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants