Skip to content

Fix compatibility with modern scikit-learn and Python versions#15

Open
kopeckylukas wants to merge 16 commits intoDTUComputeStatisticsAndDataAnalysis:masterfrom
kopeckylukas:master
Open

Fix compatibility with modern scikit-learn and Python versions#15
kopeckylukas wants to merge 16 commits intoDTUComputeStatisticsAndDataAnalysis:masterfrom
kopeckylukas:master

Conversation

@kopeckylukas
Copy link
Copy Markdown

@kopeckylukas kopeckylukas commented Apr 6, 2026

Contributing to bug fixes

  • Fill out the template below
  • The pull request should only fix existing bug reports
  • The pull request should comply with these points mentioned in the contribution guidelines

Link to the relevant Bug(s)

Fixes Issues:

Description of the Change

For #12

  • Fix sklearn compatibility: reshape 1D array in plot method StandardScaler.inverse_transform now requires 2D input in newer versions of scikit-learn (from scikit-learn version 1.0 and later). Reshape the loadings slice to 2D before inverse transforming and flatten the result.

For #13

  • Change attribute force_all_finite to ensure_all_finite in check_array function to ensure compatibility with scikit-learn version 1.6 and later. 
force_all_finite was removed in scikit-learn version 1.8

For #14

  • resolve syntax warning introduced in Python 3.8 when comparing two strings using is not instead of !=. (SyntaxWarning: "is not" with 'str' literal. Did you mean "!="? if self.method is not 'SIMPLS'). is not compares object identity, not value.

Possible Drawbacks

The behaviour was only tested for the latest versions of Python (3.11 and later) and dependencies (scikit-learn v1.6 and later). This bridges the gap of over 6 years since the last release. It is possible that these changes will not work for intermediate versions of packages.

Further, the updated version does not pass pytests. However, this code did not introduce any changes to the code itself and only addressed Syntax and Type errors caused by dependencies API changes. The failed pytest are likely due to changes in the way random seeds are handled when data are generated.

Verification Process

Run example code to ensure the code can now be run without errors and future warnings, and attempted to run existing unit tests. The result of those tests described in Possible Drawbacks section.

Release Notes

  • Fixed scikit-learn compatibility issue where StandardScaler.inverse_transform requires 2D input (scikit-learn ≥1.0) by reshaping the loadings slice in the plot method (Plot error #12).

  • Replaced deprecated force_all_finite parameter with ensure_all_finite in check_array calls for compatibility with scikit-learn ≥1.6 (TypeError when fitting the model #13).

  • Fixed SyntaxWarning by replacing identity comparison (is not) with value comparison (!=) for string literals (SyntaxWarning when fitting the model #14).

… function to ensure compatibility with scikit-learn version 1.6 and later
…rings using `is not` instead of `!=`. `is not` compares object identity, not value.
StandardScaler.inverse_transform now requires 2D input in newer
versions of scikit-learn. Reshape the loadings slice to 2D before
inverse transforming and flatten the result.
uptil this point, matplotlib was an extra, but the example code requires it, therefore, it was changed to requirements
*This is a newly maintained version of the MBPLS software originally developed by Andreas Baum and Laurent Vermue
(homepage: https://github.com/DTUComputeStatisticsAndDataAnalysis/MBPLS/). This maintained version has been updated to be compatible with Python 3.8 and later.
Lukas Kopecky, April 2026.*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant