Always store MicroDataFrame weights as a Series - #309
Open
vahid-ahmadi wants to merge 1 commit into
Open
Conversation
nullify_weights and the deprecated set_weight_col assigned a bare np.ndarray to self.weights, while the rest of the class assumes an index-aligned Series. After either call, equals() raised AttributeError: 'numpy.ndarray' object has no attribute 'equals', and the .weights.reindex() calls in __getitem__ and the loc indexer were one step from the same failure. set_weight_col also skipped the length validation and index alignment that set_weights performs. Both now delegate to set_weights. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
18 tasks
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 #303
Problem
Two methods assigned a bare
np.ndarraytoself.weights, while the rest of the class assumes it is an index-alignedpd.Series:nullify_weights—self.weights = np.ones(len(self))set_weight_col(deprecated) —self.weights = np.array(self[column])__getitem__and_MicroLocIndexer.__getitem__both callself.weights.reindex(...), so column and row selection on a nullified frame were one step from the same failure.set_weight_coladditionally skipped the length validation and index alignment thatset_weightsperforms.Change
Both methods now delegate to
set_weights, which is the single place that validates length and buildspd.Series(..., index=self.index, dtype=float).One intentional behaviour change:
nullify_weightsnow clearsweights_col(viaset_weights), which is correct — after nullifying, the weights no longer come from a column.preserve_oldhandling inset_weight_colis unchanged; it still runs before the delegation.Verification
main(AttributeErroronequals) and pass with the changemake test— 64 passed on pandas 3.0.5 and pandas 2.3.3Note: the lint job will be red until #307 merges (unrelated ruff 0.16 issue on
main).