Skip to content
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

fix: fix filtering of NaNs in Prophet preprocessing #219

Merged
merged 1 commit into from
Dec 23, 2024
Merged

Conversation

sd2k
Copy link
Collaborator

@sd2k sd2k commented Dec 23, 2024

Fixes #209.

Summary by CodeRabbit

  • New Features

    • Introduced a method to filter out NaN values from training data, ensuring data integrity.
    • Added regression tests to verify handling of NaN values in model fitting.
  • Bug Fixes

    • Improved error handling in data preprocessing to maintain robustness against invalid entries.
  • Documentation

    • Updated test conditions to reflect new features and ensure clarity on functionality.

Copy link
Contributor

coderabbitai bot commented Dec 23, 2024

Walkthrough

The pull request addresses the handling of NaN values in the Prophet forecasting library by introducing a new filter_nans method in the TrainingData struct. This method removes NaN entries from the y vector while simultaneously updating corresponding entries in other vectors like ds, cap, floor, x, and seasonality_conditions. The changes modify the preprocessing workflow to handle NaN values more robustly, ensuring that the data preparation process can handle incomplete or invalid data without causing panics.

Changes

File Change Summary
crates/augurs-prophet/src/data.rs Added filter_nans() method to TrainingData struct to remove NaN values and update associated vectors
crates/augurs-prophet/src/forecaster.rs Updated test module compilation attribute to #[cfg(all(test, feature = "wasmstan"))]
crates/augurs-prophet/src/prophet.rs Added fit_with_nans() regression test to verify NaN handling
crates/augurs-prophet/src/prophet/prep.rs Simplified preprocess method signature and integrated filter_nans() method

Assessment against linked issues

Objective Addressed Explanation
Handle NaNs without panicking [#209]
Create TrainingData::filter_nans() method [#209]
Consume self and return new TrainingData [#209]

Possibly related PRs

Poem

🐰 A Rabbit's Ode to NaN Filtering 🧹

In data's wild and winding maze,
Where numbers dance in misty haze,
Our Prophet learns to gently sift,
No more shall NaNs cause a rift!
Filtering magic, clean and bright! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
crates/augurs-prophet/src/data.rs (2)

141-179: Efficient and clean NaN filtering logic.

This implementation properly filters out NaN entries in the y vector, updates corresponding fields, and keeps the data structure coherent. The use of a helper retain function is concise.
• Consider if the caller needs feedback on the number of removed rows or warnings (e.g. for large fraction of NaNs).
• Adding extra tests for edge cases, such as all NaNs or multiple consecutive NaNs, could further improve reliability.


347-362: Test covers a basic NaN scenario.

The test checks that a single NaN is filtered from both the y vector and ds. Consider adding broader test coverage (e.g., multiple NaNs or no NaNs).

crates/augurs-prophet/src/prophet.rs (1)

866-877: Test ensures no panic with NaN entries.

“fit_with_nans” successfully validates that including a NaN in the y column won’t crash the process. It matches the PR objective of robustly handling NaNs.
• You could extend coverage to verify the final fitted model state or that the resulting set of data is correct in length.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8ed69b7 and 23fa3b3.

📒 Files selected for processing (4)
  • crates/augurs-prophet/src/data.rs (2 hunks)
  • crates/augurs-prophet/src/forecaster.rs (1 hunks)
  • crates/augurs-prophet/src/prophet.rs (1 hunks)
  • crates/augurs-prophet/src/prophet/prep.rs (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • crates/augurs-prophet/src/forecaster.rs
🔇 Additional comments (2)
crates/augurs-prophet/src/data.rs (1)

135-140: Documentation is nice and clear.

These doc comments thoroughly describe the intent and outcome of removing NaN values from the y column and the corresponding entries in others. The mention that “NaN values in other columns are retained” ensures clarity in known behavior.

crates/augurs-prophet/src/prophet/prep.rs (1)

Line range hint 197-210: Great integration of “filter_nans” into preprocess.

Calling “data.filter_nans()” ensures the dataset is cleansed before proceeding. This matches Issue #209 and PR 219 objectives for robust Prophet preprocessing.
• The direct call is straightforward; be sure any upstream code that depends on “n” is now consistent with the filtered size.

@sd2k sd2k merged commit 633ec1a into main Dec 23, 2024
24 checks passed
@sd2k sd2k deleted the fix-filtering-nans branch December 23, 2024 10:23
@sd2k sd2k mentioned this pull request Dec 23, 2024
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.

Prophet panics when preprocessing data with NaNs
1 participant