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

feat(js): expose MinMaxScaler transform #237

Merged
merged 4 commits into from
Jan 14, 2025
Merged

Conversation

yoziru
Copy link
Contributor

@yoziru yoziru commented Jan 14, 2025

  • augurs-transforms-js: expose MinMaxScaler
  • DRY up transforms.test.ts

Summary by CodeRabbit

  • New Features

    • Added MinMaxScaler transformation option to scale data within a specified range.
  • Tests

    • Refactored test cases for Pipeline class to use a more generalized testing function.
    • Improved test coverage for scalers with and without NaN handling.
  • Documentation

    • Added documentation for the new MinMaxScaler transformation.

Copy link
Contributor

coderabbitai bot commented Jan 14, 2025

Warning

Rate limit exceeded

@yoziru has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 23 minutes and 19 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 51c56e6 and 1357c31.

📒 Files selected for processing (1)
  • js/augurs-transforms-js/src/lib.rs (3 hunks)

Walkthrough

The pull request introduces a new MinMaxScaler transformation option to the augurs-transforms-js library. This addition extends the existing Transform enum in the Rust source file, allowing users to scale data to a specified range. The changes include updating the into_transformer method to handle the new MinMaxScaler variant and modifying the test suite to incorporate comprehensive testing for this new scaling transformation.

Changes

File Change Summary
js/augurs-transforms-js/src/lib.rs - Added MinMaxScaler variant to Transform enum
- Updated into_transformer method to create MinMaxScaler instance
js/testpkg/transforms.test.ts - Introduced testScalerPipeline generalized testing function
- Refactored test cases for pipeline scaling transformations
- Consolidated tests for standard and min-max scalers

Sequence Diagram

sequenceDiagram
    participant User
    participant Pipeline
    participant Transformer
    participant MinMaxScaler

    User->>Pipeline: Create with MinMaxScaler
    Pipeline->>Transformer: Convert Transform to Transformer
    Transformer->>MinMaxScaler: Instantiate
    MinMaxScaler-->>Transformer: Return scaler instance
    Transformer-->>Pipeline: Configure pipeline
    User->>Pipeline: Apply transformation
Loading

Possibly related PRs

Poem

🐰 A Rabbit's Scaling Tale 🌈

Min and max, a data dance so bright,
Transforming numbers with mathematical might,
From ranges low to high we leap,
Our scaler's magic makes data weep,
A pipeline of wonder, precise and clean!

hop hop 🥕


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.

@yoziru yoziru marked this pull request as ready for review January 14, 2025 11:52
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)
js/augurs-transforms-js/src/lib.rs (1)

17-18: Consider enhancing MinMaxScaler documentation and configuration.

The documentation could be more specific about the default range and potential customization options. Additionally, consider adding ignore_nans configuration like other transformers for consistent behavior.

-    /// Scale the data to a given range.
+    /// Scale the data to a specific range (default: [0, 1]).
     MinMaxScaler {
+        /// Whether to ignore NaNs.
+        #[serde(default, rename = "ignoreNaNs")]
+        ignore_nans: bool,
+    },
js/testpkg/transforms.test.ts (2)

64-65: Consider fixing the type issue instead of using @ts-ignore.

The @ts-ignore suggests a type mismatch between the custom matcher and the array types. Consider extending the TypeScript types properly:

declare global {
  namespace jest {
    interface Matchers<R> {
      toAllBeCloseTo(expected: number[]): R;
    }
  }
}

84-90: Consider expanding NaN test cases.

While the current tests cover basic NaN handling, consider adding edge cases:

  • NaN at the start/end of array
  • All NaN values
  • Consecutive NaN values
// Additional test cases
const allNaN = Array(y.length).fill(NaN);
const consecutiveNaN = [...y];
consecutiveNaN[0] = NaN;
consecutiveNaN[1] = NaN;

testScalerPipeline('pipeline with all NaN', allNaN, 'standardScaler', true);
testScalerPipeline('pipeline with consecutive NaN', consecutiveNaN, 'standardScaler', true);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 22be0e3 and 088ae65.

📒 Files selected for processing (2)
  • js/augurs-transforms-js/src/lib.rs (3 hunks)
  • js/testpkg/transforms.test.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Tests
🔇 Additional comments (4)
js/augurs-transforms-js/src/lib.rs (2)

8-8: LGTM!

The MinMaxScaler import is correctly added alongside other transformer imports.


36-38: LGTM!

The MinMaxScaler transformer implementation follows the established pattern.

js/testpkg/transforms.test.ts (2)

43-48: Well-structured test helper function!

Good application of DRY principle with type-safe parameters.


80-82: LGTM!

Comprehensive test coverage for both scaler types.

Copy link
Collaborator

@sd2k sd2k left a comment

Choose a reason for hiding this comment

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

LGTM, just one doc suggestion

js/augurs-transforms-js/src/lib.rs Outdated Show resolved Hide resolved
@sd2k sd2k changed the title js expose minmaxscaler feat(js): expose MinMaxScaler transform Jan 14, 2025
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: 1

🧹 Nitpick comments (1)
js/augurs-transforms-js/src/lib.rs (1)

17-18: Enhance MinMaxScaler variant documentation and configuration.

Consider the following improvements:

  1. Expand the documentation to match the detail level of other variants
  2. Add ignore_nans configuration like other scalers
  3. Consider moving after StandardScaler for alphabetical ordering
-    /// Scale the data to a given range.
-    MinMaxScaler,
+    /// Scale the data to a specified range (typically [0, 1]).
+    /// This transformation is useful when features have different scales
+    /// but do not make assumptions about the distribution.
+    MinMaxScaler {
+        /// Whether to ignore NaNs.
+        #[serde(default, rename = "ignoreNaNs")]
+        ignore_nans: bool,
+    },
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 088ae65 and 51c56e6.

📒 Files selected for processing (1)
  • js/augurs-transforms-js/src/lib.rs (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (15)
  • GitHub Check: linux (ubuntu-22.04, ppc64le)
  • GitHub Check: linux (ubuntu-22.04, s390x)
  • GitHub Check: linux (ubuntu-22.04, armv7)
  • GitHub Check: linux (ubuntu-22.04, aarch64)
  • GitHub Check: linux (ubuntu-22.04, x86)
  • GitHub Check: musllinux (ubuntu-22.04, aarch64)
  • GitHub Check: windows (windows-latest, x86)
  • GitHub Check: Tests
  • GitHub Check: Test Book
  • GitHub Check: Clippy
  • GitHub Check: windows (windows-latest, x64)
  • GitHub Check: JS tests
  • GitHub Check: Prophet WASMStan component
  • GitHub Check: macos (macos-13, x86_64)
  • GitHub Check: Check
🔇 Additional comments (2)
js/augurs-transforms-js/src/lib.rs (2)

8-8: LGTM! Import changes are well-organized.

The MinMaxScaler import is correctly placed alongside other transformer imports.


17-18: Verify TypeScript type generation and documentation.

Since this is a public API change, please ensure:

  1. TypeScript types are correctly generated
  2. Documentation includes JavaScript usage examples
  3. Breaking changes are documented if any

Also applies to: 36-36

✅ Verification successful

TypeScript generation infrastructure is in place

The codebase has proper TypeScript configuration and type definition generation setup. The new MinMaxScaler feature is documented in:

  • crates/augurs-forecaster/README.md
  • book/src/migrating.md
  • book/src/getting-started/quick-start.md
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for existing usage and documentation
rg -l "StandardScaler" --type md  # Find documentation files
rg -l "StandardScaler" --type ts  # Find TypeScript files

Length of output: 65


Script:

#!/bin/bash
# Search for MinMaxScaler usage and documentation
rg -l "MinMaxScaler" --type-add 'docs:*.{md,rst,txt}' --type docs
rg -l "MinMaxScaler" --type-add 'web:*.{js,ts,jsx,tsx}' --type web

# Check for type generation configuration
fd -e toml -e json -x cat {} \; # Look for cargo/package config
fd "binding.gyp|tsconfig.json|package.json" -x cat {} \; # Look for JS/TS config

Length of output: 65925

@@ -31,6 +33,7 @@ pub enum Transform {
impl Transform {
fn into_transformer(self) -> Box<dyn Transformer> {
match self {
Transform::MinMaxScaler => Box::new(MinMaxScaler::new()),
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add configuration handling for MinMaxScaler.

The current implementation doesn't handle ignore_nans and uses default range. Consider:

  1. Adding ignore_nans handling to match other transformers
  2. Adding feature_range configuration to allow custom scaling ranges
-            Transform::MinMaxScaler => Box::new(MinMaxScaler::new()),
+            Transform::MinMaxScaler { ignore_nans } => {
+                Box::new(MinMaxScaler::new().ignore_nans(ignore_nans))
+            }

Additionally, consider adding feature_range configuration to the enum variant and implementation if supported by the underlying MinMaxScaler:

MinMaxScaler {
    #[serde(default, rename = "ignoreNaNs")]
    ignore_nans: bool,
    #[serde(default = "default_feature_range")]
    feature_range: (f64, f64),
}

@yoziru yoziru enabled auto-merge January 14, 2025 12:01
Copy link
Collaborator

@sd2k sd2k left a comment

Choose a reason for hiding this comment

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

:shipit:

@yoziru yoziru merged commit 6291626 into main Jan 14, 2025
24 checks passed
@yoziru yoziru deleted the js-expose-minmaxscaler branch January 14, 2025 12:07
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.

2 participants