Align MicroSeries.nullify_weights to the Series index - #308
Open
vahid-ahmadi wants to merge 1 commit into
Open
Conversation
MicroSeries.nullify_weights built its all-ones weight Series without an
index, so it carried a default RangeIndex. Weighted operations are
label-aligned (self.multiply(self.weights) in sum()/weight()), so on any
non-default index the multiply produced all-NaN and every aggregation
collapsed to 0:
s = MicroSeries([1, 2, 3], index=[10, 11, 12], weights=[1, 2, 3])
s.nullify_weights()
s.sum() # 0.0, expected 6.0
Same bug class as #283, which fixed set_weights but not this path.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #301
Problem
nullify_weightsbuilt its all-ones weight Series without an index, so it carried a defaultRangeIndex. Weighted operations are label-aligned (self.multiply(self.weights)insum()/weight()), so on any non-default index the multiply produced all-NaN and every aggregation collapsed to zero:With a default index it happens to work, which is why nothing caught it.
This is the same bug class as #283, which added
index=self.indextoset_weights(with a comment explaining the label-alignment trap) but leftnullify_weightson the old pattern.Change
Pass
index=self.index, plus a comment matching the one inset_weights, and a regression test coveringsum,mean, and the resulting weight index.Verification
0.0 == 6assertion), passes aftermake test— 63 passed on pandas 3.0.5 and pandas 2.3.3make lint— passesNote: the lint job will be red until #307 merges (unrelated ruff 0.16 issue on
main).