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

change: use u32 instead of i32 for lower/upper windows #177

Merged
merged 1 commit into from
Nov 21, 2024

Conversation

sd2k
Copy link
Collaborator

@sd2k sd2k commented Nov 21, 2024

The Python Prophet library expects the lower window to be negative
and the upper window to be positive, but here it makes more sense
to restrict both to being positive and just assume that the lower
window refers to 'before the holiday date'.

Summary by CodeRabbit

  • New Features

    • Enhanced holiday feature generation with improved offset handling, allowing for negative offsets in the lower window.
  • Bug Fixes

    • Updated data types for holiday observation windows to ensure non-negative integers, improving type safety.
  • Documentation

    • Adjusted method signatures to reflect changes in data types for lower and upper window fields.

The Python Prophet library expects the lower window to be negative
and the upper window to be positive, but here it makes more sense
to restrict both to being positive and just assume that the lower
window refers to 'before the holiday date'.
Copy link

cloudflare-workers-and-pages bot commented Nov 21, 2024

Deploying augurs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 157eb4a
Status: ✅  Deploy successful!
Preview URL: https://bdea195d.augurs.pages.dev
Branch Preview URL: https://holiday-lower-upper-u32.augurs.pages.dev

View logs

Copy link
Contributor

coderabbitai bot commented Nov 21, 2024

Walkthrough

The changes in this pull request involve modifications to the Holiday struct across multiple files, specifically updating the types of the lower_window and upper_window fields from Option<Vec<i32>> to Option<Vec<u32>>. This adjustment ensures that the observation windows for holidays are represented as non-negative integers. Additionally, the make_holiday_features function in the prep.rs file is updated to allow for negative offsets in the lower window, enhancing the flexibility of holiday feature generation. These changes maintain the overall structure and logic of the affected components.

Changes

File Path Change Summary
crates/augurs-prophet/src/features.rs Updated lower_window and upper_window fields from Option<Vec<i32>> to Option<Vec<u32>>. Updated method signatures for with_lower_window and with_upper_window to accept Vec<u32>.
js/augurs-prophet-js/src/lib.rs Updated lower_window and upper_window fields from Option<Vec<i32>> to Option<Vec<u32>>. Adjusted conversion implementation for consistency with new types.
crates/augurs-prophet/src/prophet/prep.rs Modified make_holiday_features to adjust holiday offset calculations, changing the range from lower..=upper to -lower..=upper. Minor adjustments to iterator mappings for type casting.

Possibly related PRs

Poem

🐇 In fields of data, bright and new,
The holidays shine with a clearer view.
With windows wide, both low and high,
We count the days as they flutter by.
So hop along, let’s cheer and play,
For changes made, it's a bright new day! 🌼


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 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

🧹 Outside diff range and nitpick comments (4)
crates/augurs-prophet/src/features.rs (3)

20-21: Document the deviation from Python Prophet's convention

While changing to u32 makes the API more intuitive (interpreting windows as time periods before/after holiday), this deviates from Python Prophet's convention of using negative values for lower windows. Consider adding a note in the struct documentation explaining this design choice and how it differs from Python Prophet.

 /// A holiday to be considered by the Prophet model.
+///
+/// Note: Unlike Python Prophet which uses negative values for lower windows,
+/// this implementation uses positive values to represent time periods before
+/// the holiday date. For example, a lower window of 2 means the holiday
+/// effect starts 2 days before the actual holiday date.
 #[derive(Debug, Clone)]
 pub struct Holiday {

40-42: Enhance documentation with valid range information

The documentation example is clear, but it would be helpful to explicitly state that the window values must be non-negative integers.

     /// Set the lower window for the holiday.
     ///
     /// The lower window is the number of days before the holiday
     /// that it is observed. For example, if the holiday is on
     /// 2023-01-01 and the lower window is 1, then the holiday will
-    /// _also_ be observed on 2022-12-31.
+    /// _also_ be observed on 2022-12-31.
+    ///
+    /// Note: Window values must be non-negative integers, representing
+    /// the number of days before the holiday.

61-61: Add non-negative range information to upper_window documentation

For consistency with the lower_window documentation, consider adding a note about the non-negative requirement.

     /// Set the upper window for the holiday.
     ///
     /// The upper window is the number of days after the holiday
     /// that it is observed. For example, if the holiday is on
     /// 2023-01-01 and the upper window is 1, then the holiday will
-    /// _also_ be observed on 2023-01-02.
+    /// _also_ be observed on 2023-01-02.
+    ///
+    /// Note: Window values must be non-negative integers, representing
+    /// the number of days after the holiday.
js/augurs-prophet-js/src/lib.rs (1)

1233-1236: Consider clarifying the behavior change in the documentation.

While the documentation explains how the lower window works with positive values, it would be helpful to explicitly mention that this is a departure from Python Prophet's behavior where lower windows are traditionally negative values. This change in behavior should be prominently documented to avoid confusion for users migrating from Python Prophet.

Consider adding a note like:

    /// The lower window for the holiday.
    ///
    /// The lower window is the number of days before the holiday
    /// that it is observed. For example, if the holiday is on
    /// 2023-01-01 and the lower window is 1, then the holiday will
    /// _also_ be observed on 2022-12-31.
+   ///
+   /// Note: Unlike Python Prophet which uses negative values for lower windows,
+   /// this implementation uses positive values to represent days before the holiday.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between effd7ee and 157eb4a.

📒 Files selected for processing (3)
  • crates/augurs-prophet/src/features.rs (3 hunks)
  • crates/augurs-prophet/src/prophet/prep.rs (2 hunks)
  • js/augurs-prophet-js/src/lib.rs (2 hunks)
🔇 Additional comments (6)
crates/augurs-prophet/src/features.rs (1)

20-21: Verify the impact of type changes

The change from i32 to u32 for window values is a breaking change that needs careful verification.

Also applies to: 42-42, 61-61

✅ Verification successful

Let me gather more information about the type changes and their impact.

Let me also check the test files specifically:


Based on the gathered information, I can now provide a final response:

Type change from i32 to u32 appears safe to proceed

The change from i32 to u32 for window values is actually safe because:

  • All existing usage patterns in the codebase only use non-negative values (e.g., vec![0, 0], vec![1, 1])
  • The fields are only accessed through builder methods with_lower_window and with_upper_window
  • The JavaScript bindings in augurs-prophet-js handle the conversion appropriately
  • No test cases were found using negative values for these fields
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential breaking changes and usage patterns

# Check for direct usage of Holiday struct fields
echo "Checking direct field access patterns..."
rg -A 2 "holiday\.(lower|upper)_window" 

# Check for calls to with_lower_window and with_upper_window methods
echo "Checking method call patterns..."
rg -A 2 "with_(lower|upper)_window\(" 

# Look for test files that might need updates
echo "Checking test files..."
fd -e rs test | xargs rg -A 2 "Holiday"

Length of output: 2159


Script:

#!/bin/bash
# Check the git history for these fields to understand the type change
git log -L :lower_window:crates/augurs-prophet/src/features.rs -L :upper_window:crates/augurs-prophet/src/features.rs

# Look for any negative values being used in tests or examples
rg -A 2 "(-[0-9]+|[0-9]+)" crates/augurs-prophet/src/features.rs

# Check for any error handling or validation related to these fields
ast-grep --pattern 'fn with_lower_window($$$) { $$$ }'
ast-grep --pattern 'fn with_upper_window($$$) { $$$ }'

Length of output: 1443


Script:

# Check test files for window-related tests
fd -e rs test | xargs rg "(lower|upper)_window"

# Look for any validation or conversion of window values in tests
fd -e rs test | xargs rg "Holiday.*window"

Length of output: 94

js/augurs-prophet-js/src/lib.rs (2)

1245-1245: LGTM: Type change aligns with the design decision.

The change from Option<Vec<i32>> to Option<Vec<u32>> for upper_window is consistent with the overall design decision to use unsigned integers for window values.


Line range hint 1233-1245: Verify handling of unsigned windows across the codebase.

Let's ensure that all code handling these windows has been updated to work with unsigned integers.

✅ Verification successful

All window-related code consistently uses unsigned integers (u32)

Based on the search results:

  • All occurrences of lower_window and upper_window in the codebase use Vec<u32> type
  • No instances of signed integer (i32) usage with windows were found
  • The implementation is well documented with references to Python/R Prophet compatibility
  • The conversion functions with_lower_window and with_upper_window properly handle the unsigned values
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining signed integer handling of window values
# and verify documentation of the behavioral change.

# Check for any remaining i32 types used with windows
rg -g '*.rs' '(?i)(lower|upper)_window.*i32'

# Look for conversion or handling of window values
rg -g '*.rs' '(?i)(lower|upper)_window'

# Check for documentation about Python/R Prophet compatibility
rg -g '*.{rs,md}' -i 'python.*prophet|prophet.*python'

Length of output: 4545

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

667-669: LGTM: Safe type conversion for lower window values.

The conversion from u32 to i32 is safe and necessary for later negation of the lower window values.


674-676: LGTM: Safe type conversion for upper window values.

The conversion from u32 to i32 is safe and maintains consistency with the lower window conversion.


685-687: LGTM: Correctly handles negative offsets while using u32.

The implementation elegantly solves the requirement to use u32 for window values while maintaining the expected behavior of negative offsets for the lower window. The comment clearly explains the rationale.

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