IAMconsortium / pyam

Analysis & visualization of energy & climate scenarios
https://pyam-iamc.readthedocs.io/
Apache License 2.0
221 stars 115 forks source link

Adjust for pandas 2.1.0 #780

Closed khaeru closed 9 months ago

khaeru commented 10 months ago

Using pyam-iamc v1.9.0 with pandas 2.1.0 appears (initially) to work alright, at least for the subset of functionality used in iiasa/message_data.

However, there are (many) FutureWarnings emitted. Here are the ones I've observed:

pyam/aggregation.py:210: FutureWarning: The provided callable <built-in function sum> is currently using SeriesGroupBy.sum. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass 'sum' instead.

pyam/aggregation.py:210: FutureWarning: The provided callable <function sum at 0x7fbbe5333eb0> is currently using SeriesGroupBy.sum. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass 'sum' instead.

pyam/core.py:2691: FutureWarning: unique with argument that is not not a Series, Index, ExtensionArray, or np.ndarray is deprecated and will raise in a future version.

pyam/plotting.py:466: FutureWarning: The behavior of array concatenation with empty entries is deprecated. In a future version, this will no longer exclude empty items when determining the result dtype. To retain the old behavior, exclude the empty entries before the concat operation.

pyam/plotting.py:485: FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.

Again, AFAICT there's no bug, and we will use filterwarnings() for now. This issue is just to track when those filters can be removed.

danielhuppmann commented 10 months ago

Thanks @khaeru, but these warnings should have been fixed already by #777 - can you confirm?

khaeru commented 10 months ago

Great, thanks! I will try to check against main in the next day or two.

coroa commented 9 months ago

Note that there seems to be at least one non-trivial bug with the combination of pandas 2.1 and pyam 1.9:

import pandas as pd
import pyam

test_df = (
    pd.DataFrame(
        dict(
            model="any",
            scenario="any",
            region=["AUS", "USA"],
            variable="any",
            unit="any",
            year=2000,
            value=50,
        )
    )
    .set_index(["model", "scenario", "region", "variable", "unit", "year"])
    .value.unstack("year")
)

pyam.IamDataFrame(test_df.iloc[[0]]).region
/Users/coroa/repos/pyam/pyam/core.py:2691: FutureWarning: unique with argument that is not not a Series, Index, ExtensionArray, or np.ndarray is deprecated and will raise in a future version.
  index = pd.unique(index)

will result in ["AUS", "USA"] as regions rather than only ["AUS"] since we only included the first line.

It is fixed on the main branch/the release candidate.

test_df looks like:

year                                 2000
model scenario region variable unit      
any   any      AUS    any      any     50
               USA    any      any     50
danielhuppmann commented 9 months ago

Re @coroa, indeed, that was noted and fixed in #763 (and a test added to guard against regression) - but there isn't really anything we can do about past releases...

danielhuppmann commented 9 months ago

Closing this issue, please reopen if you encounter any unfixed future-warnings.