Skip to content

Cast channel_data to float at construction time#2341

Open
isofer wants to merge 6 commits intomainfrom
isofer/2340-cast-channel-data-to-float
Open

Cast channel_data to float at construction time#2341
isofer wants to merge 6 commits intomainfrom
isofer/2340-cast-channel-data-to-float

Conversation

@isofer
Copy link
Contributor

@isofer isofer commented Feb 26, 2026

Summary

  • Cast _channel data to float in MMM._generate_and_preprocess_model_data() immediately after building the xarray dataset, so all downstream consumers (scalers, pm.Data, budget optimizer, incrementality, sensitivity analysis) always see float data.
  • Adds a test verifying that integer channel input is cast to float at construction time.

Closes #2340


📚 Documentation preview 📚: https://pymc-marketing--2341.org.readthedocs.build/en/2341/

@isofer isofer marked this pull request as ready for review February 26, 2026 16:36
@cursor
Copy link

cursor bot commented Feb 26, 2026

PR Summary

Low Risk
Low risk: a small, targeted dtype normalization that affects only channel input tensors; main risk is minor behavior change for integer channel inputs, now always treated as float.

Overview
Casts the merged xarray _channel variable to float during MMM._generate_and_preprocess_model_data(), ensuring downstream scaling and pm.Data('channel_data') consistently operate on floating-point channel inputs.

Adds a regression test confirming that integer channel columns are converted to float in both mmm.xarray_dataset['_channel'] and the constructed PyTensor channel_data node.

Written by Cursor Bugbot for commit 7b09473. This will update automatically on new commits. Configure here.

@codecov
Copy link

codecov bot commented Feb 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.72%. Comparing base (fbc2831) to head (7b09473).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2341      +/-   ##
==========================================
- Coverage   93.18%   89.72%   -3.47%     
==========================================
  Files          79       79              
  Lines       12472    12473       +1     
==========================================
- Hits        11622    11191     -431     
- Misses        850     1282     +432     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.


self.xarray_dataset = xr.merge(dataarrays).fillna(0)

if not np.issubdtype(self.xarray_dataset["_channel"].dtype, np.floating):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't you just do astype(float) regardless?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cast channel_data to float at construction time

3 participants