Skip to content

Address several numpy/pandas deprecation warnings; clean up test output #1930

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 9 commits into from
Dec 19, 2023

Conversation

kandersolar
Copy link
Member

@kandersolar kandersolar commented Dec 14, 2023

  • 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.

This PR:

  • Fixes code that used newly deprecated functionality in pandas/numpy:
    • FutureWarning: Series.getitem treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use ser.iloc[pos]

    • DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)

    • FutureWarning: Setting an item of incompatible dtype is deprecated and will raise in a future error of pandas. Value '[69.43454873]' has dtype incompatible with int64, please explicitly cast to a compatible dtype first.

    • FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.

    • FutureWarning: Unit 'T' is deprecated and will be removed in a future version.

  • Fixes an overlooked issue in the remote-data tests on python 3.12 introduced in Add python 3.12 to CI #1886
  • Suppresses a few other nuisance warnings

There is still some junk in the test CI logs but I'm inclined to leave the rest for future PRs.

The version in default channel is old.  Version in conda-forge is up to date and contains a fix for this deprecation warning:

DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
Use `unit='minutes'` instead of `unit='T'` ('T' was deprecated in pandas 2.1).  Fixes:

FutureWarning: Unit 'T' is deprecated and will be removed in a future version.
Fixes:

FutureWarning: Series.__setitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To set a value by position, use `ser.iloc[pos] = value`
Fixes:

FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.
Fixes:

FutureWarning: Setting an item of incompatible dtype is deprecated and will raise in a future error of pandas. Value '[69.43454873]' has dtype incompatible with int64, please explicitly cast to a compatible dtype first.
Fixes:

DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)
Fixes:

RuntimeWarning: invalid value encountered in multiply
RuntimeWarning: invalid value encountered in scalar multiply
@kandersolar kandersolar added testing remote-data triggers --remote-data pytests labels Dec 14, 2023
@kandersolar kandersolar added this to the v0.10.3 milestone Dec 14, 2023
Fixes:

FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`
@kandersolar kandersolar changed the title Address several test warnings Address several numpy/pandas deprecation warnings; clean up test output Dec 14, 2023
@kandersolar kandersolar marked this pull request as ready for review December 14, 2023 17:34
@kandersolar kandersolar added remote-data triggers --remote-data pytests and removed remote-data triggers --remote-data pytests labels Dec 14, 2023
@@ -134,6 +134,7 @@ def fn(x):
return np.abs((x ** 2 - x) / 2 - n_pairs)

n_dist = np.round(scipy.optimize.fmin(fn, np.sqrt(n_pairs), disp=False))
n_dist = n_dist.item()
Copy link
Member Author

Choose a reason for hiding this comment

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

This change needs to be checked by someone who understands the WVM code better than I do. @cwhanse?

Copy link
Member

Choose a reason for hiding this comment

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

Line 136 returns an array of length 1, the item is converting to scalar. Is that correct? If so, then this looks approriate to me.

I don't think we would have triggered the error described in the numpy warning at line 145/6, since n_dist.ndim woudl be 1. Better to be specific here, in any case.

@kandersolar kandersolar mentioned this pull request Dec 14, 2023
15 tasks
Copy link
Member

@AdamRJensen AdamRJensen left a comment

Choose a reason for hiding this comment

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

LGTM

@kandersolar kandersolar merged commit 8057393 into pvlib:main Dec 19, 2023
@kandersolar kandersolar deleted the test-fixes branch December 19, 2023 14:46
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.

3 participants