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] Fix Future warnings with Pandas 2.1.0 #629

Closed
raoulcollenteur opened this issue Sep 4, 2023 · 5 comments · Fixed by #684
Closed

[BUG] Fix Future warnings with Pandas 2.1.0 #629

raoulcollenteur opened this issue Sep 4, 2023 · 5 comments · Fixed by #684
Assignees
Labels
bug Indicates an unintended behavior or coding error priority 0 high, deal with as soon as possible
Milestone

Comments

@raoulcollenteur
Copy link
Member

Describe the bug

Pastas is not working well with Pandas 2.1.0 for now, as shown by errors on GH Actions.

To Reproduce

https://github.com/pastas/pastas/actions/runs/6069992486/job/16465234055?pr=626

Expected behavior

Work.

Python package version

pandas >= 2.1.0

@raoulcollenteur raoulcollenteur added the bug Indicates an unintended behavior or coding error label Sep 4, 2023
@raoulcollenteur
Copy link
Member Author

Limiting Pandas to 2.0 for now through PR #626, so GH Actions works again and we can work on Pandas 2.1.0 support from there in a separate branch.

@raoulcollenteur raoulcollenteur self-assigned this Sep 4, 2023
@raoulcollenteur raoulcollenteur added this to the 1.3 milestone Sep 4, 2023
@raoulcollenteur raoulcollenteur modified the milestones: 1.3, 1.4 Nov 28, 2023
@raoulcollenteur raoulcollenteur changed the title [BUG] Pastas not compatible with Pandas 2.1.0 [BUG] Fix Future warnings with Pandas 2.1.0 Nov 29, 2023
@raoulcollenteur
Copy link
Member Author

I checked an I think it might actually work, but we get lots of future warnings from Pandas. So we have to update some of the code. After upgrading the master-branch to 1.3, we can allow the dev-branch to allow Pandas >=2.1 and solve the warnings efficiently.

@martinvonk martinvonk added the priority 0 high, deal with as soon as possible label Nov 29, 2023
@raoulcollenteur
Copy link
Member Author

Some warnings I found

  • /python3.11/site-packages/pastas/io/pas.py:40: FutureWarning: Passing literal json to 'read_json' is deprecated and will be removed in a future version. To read from a literal string, wrap it in a 'StringIO' object.
    obj[key] = read_json(value, typ="series", orient="split")

  • /python3.11/site-packages/pastas/model.py:1179: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.
    parameters = concat(frames)

@martinvonk
Copy link
Collaborator

  • /pastas/pastas/timeseries_utils.py:135: FutureWarning: Day.delta is deprecated and will be removed in a future version. Use pd.Timedelta(obj) instead
    dt = to_offset(freq).delta / Timedelta(1, "D")

  • pastas/pastas/stats/core.py:198: FutureWarning: The 'unit' keyword in TimedeltaIndex construction is deprecated and will be removed in a future version. Use pd.to_timedelta instead.
    index=TimedeltaIndex(lags, unit="D", name="Lags"),

  • pastas/pastas/model.py:1801: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise in a future error of pandas. Value '['±12.78%' '±13.98%' '±0.00e+00%' '±0.00e+00%' '±27.49%' '±11.42%'
    '±12.01%' '±0.00e+00%' '±4.27e-02%' '±26.32%' '±14.90%']' has dtype incompatible with float64, please explicitly cast to a compatible dtype first.
    parameters.loc[:, "stderr"] = "±" + stderr.abs().apply(

  • pastas/pastas/model.py:1209: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.
    parameters = concat(frames)

  • pastas/pastas/model.py:1215: 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.

    parameters.optimal.update(self.parameters.optimal)

  • pastas/pastas/timeseries_utils.py:181: FutureWarning: Day.is_anchored is deprecated and will be removed in a future version, please use False instead.
    if to_offset(offset.rule_code).is_anchored():

@martinvonk martinvonk linked a pull request Feb 16, 2024 that will close this issue
@raoulcollenteur
Copy link
Member Author

Pastas now works with all Pandas versions up to the latest 2.2 release after PR #684.

For pandas 3.0, some additional changes are necessary and only pandas 2.2 or higher will work. https://pandas.pydata.org/docs/whatsnew/v2.2.0.html#upcoming-changes-in-pandas-3-0

@raoulcollenteur raoulcollenteur modified the milestones: 1.5, 1.4 Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unintended behavior or coding error priority 0 high, deal with as soon as possible
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants