-
Notifications
You must be signed in to change notification settings - Fork 7
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!: add serde derives for more types #112
Conversation
This is a breaking change because it changes the definition of some types so that they make more sense. Specifically, `OutlierOutput::outlying_series` is now a `BTreeSet` to preserve order, and `OutlierIntervals::intervals` is now a `Vec<OutlierInterval>` instead of a `Vec<usize>`, to make it more easily usable.
WalkthroughThe pull request introduces several modifications across multiple files in the Changes
Possibly related PRs
Suggested labels
Poem
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Outside diff range and nitpick comments (1)
crates/augurs-outlier/src/lib.rs (1)
273-293
: Enhance test coverage for serializationIn the
serialize
test, consider adding cases with intervals whereend
isSome(usize)
to ensure serialization handles both open and closed intervals correctly.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (7)
- crates/augurs-core/src/distance.rs (1 hunks)
- crates/augurs-js/src/outlier.rs (4 hunks)
- crates/augurs-outlier/Cargo.toml (1 hunks)
- crates/augurs-outlier/src/dbscan.rs (3 hunks)
- crates/augurs-outlier/src/lib.rs (7 hunks)
- crates/augurs-outlier/src/mad.rs (2 hunks)
- crates/augurs-outlier/src/testing.rs (2 hunks)
Additional comments not posted (19)
crates/augurs-outlier/Cargo.toml (1)
27-28
: LGTM!Adding
serde_json
as a development dependency is a valid change. It expands the development environment by including a library for JSON serialization and deserialization, which can be useful for testing and development purposes. The specified version is a stable release, ensuring compatibility and reliability.This change does not affect the existing functionality of the crate and is limited to the development environment, making it a safe addition.
crates/augurs-core/src/distance.rs (1)
20-20
: Conditional serialization support forDistanceMatrix
struct.The addition of the
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
attribute to theDistanceMatrix
struct is a great improvement. It allows instances ofDistanceMatrix
to be serialized and deserialized when the "serde" feature is enabled, enhancing the struct's functionality for data interchange formats such as JSON.The conditional compilation ensures that the serde dependencies are only included when needed, keeping the dependencies minimal when serialization is not required. This provides flexibility to enable or disable serialization support based on the project's requirements.
crates/augurs-js/src/outlier.rs (4)
274-279
: LGTM!The change simplifies the conversion logic by directly mapping
augurs_outlier::OutlierInterval
instances toOutlierInterval
without the intermediate vector. This aligns with the AI-generated summary and improves the clarity of the code.
295-301
: LGTM!The
From
implementation forOutlierInterval
directly mapsaugurs_outlier::OutlierInterval
instances toOutlierInterval
, streamlining the conversion process. This change aligns with the AI-generated summary and enhances the clarity and efficiency of the code by simplifying the conversion logic.
1-1
: LGTM!The import of
BTreeSet
from thestd::collections
module aligns with the AI-generated summary, which mentions thatHashSet
has been replaced withBTreeSet
for theoutlying_series
field in theOutlierOutput
struct. UsingBTreeSet
is appropriate when the order of outlier indices is important, as it maintains its elements in sorted order.
310-310
: Verify the impact of the change on the codebase.The change from
HashSet<usize>
toBTreeSet<usize>
for theoutlying_series
field in theOutlierOutput
struct aligns with the AI-generated summary. UsingBTreeSet
is appropriate when the order of outlier indices is important, as it maintains its elements in sorted order.However, it's important to ensure that this change is consistently applied throughout the codebase and that any dependent code is updated accordingly, as the order of elements will now be preserved.
Run the following script to verify the usage of
outlying_series
field:Verification successful
The update to
BTreeSet<usize>
foroutlying_series
is consistently applied across the codebase. No issues detected.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of `outlying_series` field in the codebase. # Test: Search for the usage of `outlying_series` field. Expect: Consistent usage with `BTreeSet`. rg --type rust -A 5 $'outlying_series'Length of output: 4138
crates/augurs-outlier/src/testing.rs (1)
880-891
: LGTM!The
flatten_intervals
function looks good. It correctly converts anOutlierIntervals
to a list of indices by iterating over the intervals, collecting thestart
andend
indices (if present), and flattening them into a single vector. The use ofiter()
,flat_map()
, andcollect()
is idiomatic and efficient.crates/augurs-outlier/src/mad.rs (1)
Line range hint
386-716
: LGTM!The changes in the test code, including the updated import statement and the flattening of intervals before comparison, appear to be a valid refactoring to accommodate the new structure of
outlier_intervals
. The test coverage and correctness are maintained.crates/augurs-outlier/src/dbscan.rs (4)
360-360
: LGTM!The import statement has been updated to include the
flatten_intervals
function from thetesting
module, which is necessary to support the changes made in the test cases.
519-525
: LGTM!The changes to the iteration over outlier indices simplify the logic and improve readability by using the flattened indices obtained from
flatten_intervals
. The usage ofiter
andnext()
on the flattened indices is more idiomatic and consistent with the introduction offlatten_intervals
in the import statement.
602-606
: LGTM!The assertions have been updated to retrieve indices from the flattened intervals, ensuring that they remain valid under the new implementation. The changes are consistent with the modifications made to the iteration logic.
608-614
: LGTM!The assertions have been updated to use the flattened indices, ensuring that they access the correct values. The usage of array indexing is consistent with the flattened structure of the indices, and the assertions remain valid in testing the expected behavior of the outlier detection.
crates/augurs-outlier/src/lib.rs (7)
4-4
: LGTM: ImportingBTreeSet
to preserve orderThe import of
BTreeSet
is appropriate for ensuring the order of outlying series is preserved, aligning with the PR objectives.
41-42
: Enable serialization forOutlierOutput
structAdding
serde
serialization attributes allowsOutlierOutput
to be serialized consistently, which is beneficial for data interchange.
45-47
: Updateoutlying_series
to useBTreeSet
Changing
outlying_series
to aBTreeSet<usize>
ensures that the series indices are ordered, which can be important for downstream processing.
83-84
: Enable serialization forSeries
structAdding
serde
serialization attributes to theSeries
struct facilitates consistent serialization of series results.
134-138
: RefactorOutlierIntervals
to useintervals
and enable serializationReplacing
indices
withintervals: Vec<OutlierInterval>
provides a more structured and clear representation of outlier intervals. Serialization attributes enable consistent data exchange.
141-141
: Exclude internal stateexpecting_end
from serializationUsing
#[cfg_attr(feature = "serde", serde(skip))]
appropriately omits the internalexpecting_end
flag from serialized output, preventing exposure of internal logic.
182-196
: AddOutlierInterval
struct for clearer interval representationIntroducing
OutlierInterval
struct enhances the clarity and usability of outlier intervals, allowing for explicit start and optional end indices.
|
||
self.intervals.push(OutlierInterval { | ||
start: ts, | ||
end: None, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve error handling in add_start
method
The use of debug_assert!
means the check is only active in debug builds. Consider using assert!
or returning a Result
to ensure that invalid states are caught in release builds as well.
|
||
match self.intervals.last_mut() { | ||
Some(x @ OutlierInterval { end: None, .. }) => { | ||
x.end = Some(ts); | ||
} | ||
_ => unreachable!("tried to add end to an open-ended interval"), | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve error handling in add_end
method
Similar to add_start
, using debug_assert!
and unreachable!
may not catch errors in release builds. Consider explicit error handling to prevent potential panics in production.
This is a breaking change because it changes the definition of some types
so that they make more sense.
Specifically,
OutlierOutput::outlying_series
is now aBTreeSet
to preserveorder, and
OutlierIntervals::intervals
is now aVec<OutlierInterval>
insteadof a
Vec<usize>
, to make it more easily usable.Summary by CodeRabbit
New Features
DistanceMatrix
struct with conditional serialization and deserialization support.OutlierInterval
struct for better representation of outlier intervals.flatten_intervals
function for streamlined processing of outlier intervals.Improvements
HashSet
withBTreeSet
for ordered outlier series.Documentation
serde_json
as a development dependency for improved JSON handling in the development environment.