Skip to content

fix: Use native xgb.Booster to fix Py3.12 crash (keeps .ubj format) - #335

Open
astropedrocosta wants to merge 7 commits into
openclimatefix:mainfrom
astropedrocosta:upgrade-model-json-py312
Open

fix: Use native xgb.Booster to fix Py3.12 crash (keeps .ubj format)#335
astropedrocosta wants to merge 7 commits into
openclimatefix:mainfrom
astropedrocosta:upgrade-model-json-py312

Conversation

@astropedrocosta

@astropedrocosta astropedrocosta commented Feb 3, 2026

Copy link
Copy Markdown

Pull Request

Description

This PR resolves a critical compatibility issue with Python 3.12 where the XGBRegressor Scikit-Learn wrapper causes the application to crash with an _estimator_type error upon initialisation.

Summary of Changes:

  • Refactored quartz_solar_forecast/forecasts/v2.py to replace the deprecated XGBRegressor wrapper with the native xgb.Booster engine.
  • Updated the inference logic to utilize xgb.DMatrix for data handling.
  • Verified that the native Booster maintains backward compatibility with the existing .ubj model format, eliminating the need to migrate to a larger JSON model file.

Motivation and Context:
This work stems from the installation and runtime failures identified in Issue #333. It operates synthetically with the collaborative work done in PR #334 with @Raakshass, aimed at stabilising the package for newer Python environments.

Fixes #333

How Has This Been Tested?

I have verified these changes locally by running the full forecasting pipeline using real weather data for Porto, Portugal.

Test Configuration:

  • OS: macOS (M1)
  • Python Version: 3.12
  • Test Script: test_porto.py (Local validation script)

Reproduction Instructions:

  1. Install the package in a Python 3.12 environment.
  2. Instantiate TryolabsSolarPowerPredictor.
  3. Run predict_power_output() with valid latitude/longitude data.
  • Yes

Sanity Check:
I have plotted the output data and verified that the solar generation curve follows expected day/night cycles (0 kW at night, peak generation during daylight hours).

  • Yes

Checklist:

  • My code follows OCF's coding style guidelines
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked my code and corrected any misspellings

@astropedrocosta

Copy link
Copy Markdown
Author

Conflicts resolved and linting fixed. The PR is ready for review. Note: Workflows are awaiting approval to run.

@astropedrocosta

Copy link
Copy Markdown
Author

Hi @peterdudfield, I'm following up on this!

I’ve resolved the merge conflicts and fixed the linting W293 errors. The code is now using the native xgb.Booster (which fixes the Python 3.12 crash) while keeping the original .ubj model format.

It looks like the workflows are still 'Awaiting Approval' to run. Ready for review whenever you have a moment!

@peterdudfield

Copy link
Copy Markdown
Contributor

Looks like the tests are failing? Can you have a look @astropedrocosta

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.

Cannot run forecast on Python 3.12 (Dependency Deadlock with scikit-learn)

2 participants