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
[MNT] address pd.DataFrame.groupby(axis=1)
deprecation in EnsembleForecaster
#5707
[MNT] address pd.DataFrame.groupby(axis=1)
deprecation in EnsembleForecaster
#5707
Conversation
Changes accommodate deprecation of `pandas.DataFrame.groupby(axis=1)` introduced in pandas 2.1.0. See https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.groupby.html and https://github.com/pandas-dev/pandas/blob/d711b1d2ff9ee2c3faf0e118535d3d6218886a9d/pandas/core/frame.py#L9105-L9111
Revising for code quality checks.
You should also update |
Your update is failing linting (code formatting) checks - perhaps you may like to split the one-liner into multiple lines to avoid too many brackets and indents. |
PS, how about this (different from the other code in the issue): y_pred = y_pred.T.groupby(level=1).agg(
_aggregate, self.aggfunc, self.weights
).T |
In order to get this to work, the input data into y_pred = y_pred.T.groupby(level=1).agg(
lambda y, aggfunc, weights: _aggregate(y.T, aggfunc, weights),
self.aggfunc,
self.weights
).T This passes the unit tests and avoids the FutureWarning, and it's similar to the original code. We could keep this line the same lambda y, aggfunc, weights: _aggregate(y.T, aggfunc, weights) Or define it as a wrapper somewhere else: def _aggregate_transform(y, aggfunc, weights):
return _aggregate(y.T, aggfunc, weights) What do you think? Edit: @pytest.mark.parametrize(
"forecasters",
[
[("trend", PolynomialTrendForecaster()), ("naive", NaiveForecaster())],
],
)
def test_ensemble_pandas_future_warn(forecasters):
"""Raises exception if FutureWarning triggered within EnsembleForecaster"""
y = make_forecasting_problem()
with pytest.warns(None) as record:
forecaster = EnsembleForecaster(forecasters)
forecaster.fit(y, fh=[1, 2, 3])
_ = forecaster.predict()
for warning in record:
if isinstance(warning.message, FutureWarning):
raise AssertionError("FutureWarning was triggered") |
Revising using `frame.T.groupby(level=1)` instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that works!
Re warning, we monitor for FutureWarning
-s regularly, but addressing them is a matter of maintainer time, so this is very much appreciated! They are listed at the end of diagnostic runs (you can look at "details" and the CRON job)
Looks like it still failed the linting steps. Should I revise or are we good to go? |
Please revise, the tests should all pass. Here's a guide on setting up linting checks on your computer: Let me know if it turns out too fiddly, I can do it for you then. |
Reformatted to conform to `black` code format
Thanks, I submitted the latest revision after running the |
groupby(axis=1)
in EnsembleForecaster
pd.DataFrame.groupby(axis=1)
deprecatio in EnsembleForecaster
(#5707)
pd.DataFrame.groupby(axis=1)
deprecatio in EnsembleForecaster
(#5707)pd.DataFrame.groupby(axis=1)
deprecatio in EnsembleForecaster
pd.DataFrame.groupby(axis=1)
deprecatio in EnsembleForecaster
pd.DataFrame.groupby(axis=1)
deprecation in EnsembleForecaster
Fixes #5701
Changes accommodate deprecation of
pandas.DataFrame.groupby(axis=1)
introduced in pandas 2.1.0.References: