Make pandas an optional dependency#1831
Open
zeel2104 wants to merge 1 commit intoonline-ml:mainfrom
Open
Conversation
MaxHalford
reviewed
Apr 27, 2026
Member
MaxHalford
left a comment
There was a problem hiding this comment.
Nearly there! I just have a couple of questions.
| super().learn_one(x, y=1) | ||
|
|
||
| def learn_many(self, X): | ||
| pd = utils.pandas.import_pandas() |
Member
There was a problem hiding this comment.
This is a good pattern, I like it
| def predict_proba_many(self, X): | ||
| pd = utils.pandas.import_pandas() | ||
| try: | ||
| return pd.Series(self.estimator.predict_proba(self._align_df(X)), columns=self.classes) |
Member
There was a problem hiding this comment.
Ok that fixes a bug I guess, I'm surprised it didn't get caught before
Comment on lines
+22
to
+28
| def requires_pandas(method): | ||
| @functools.wraps(method) | ||
| def wrapper(*args, **kwargs): | ||
| import_pandas() | ||
| return method(*args, **kwargs) | ||
|
|
||
| return wrapper |
| ] | ||
|
|
||
| [project.optional-dependencies] | ||
| pandas = [ |
Member
There was a problem hiding this comment.
Could you add some instructions to the installation docs to explain that mini-batch is an opt-in feature and requires pandas?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR removes
pandasas a hard dependency.Changes made:
pandasfrom core dependencies to an optional extrapandasin batch-related code pathsImportErrorwhenlearn_many,predict_many,transform_many, and related pandas-dependent operations are used withoutpandaspandasusage in places where it was not requiredpandasis not installedValidation
Tested without
pandasinstalled:python -m pytest river\utils\test_pandas.pyTested with
pandasandscikit-learninstalled:python -m pytest river\compose\test_.py river\compose\test_product.py river\preprocessing\test_scale.py river\multiclass\test_ovr.py river\naive_bayes\test_naive_bayes.py river\proba\test_gaussian.py river\covariance\test_emp.py river\compat\test_sklearn.py river\anomaly\test_lof.py