Skip to content

Align MicroSeries.nullify_weights to the Series index - #308

Open
vahid-ahmadi wants to merge 1 commit into
mainfrom
fix/nullify-weights-index
Open

Align MicroSeries.nullify_weights to the Series index#308
vahid-ahmadi wants to merge 1 commit into
mainfrom
fix/nullify-weights-index

Conversation

@vahid-ahmadi

Copy link
Copy Markdown

Closes #301

Problem

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

s = MicroSeries([1, 2, 3], index=[10, 11, 12], weights=[1, 2, 3])
s.nullify_weights()
s.sum()      # -> 0.0, expected 6.0

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.index to set_weights (with a comment explaining the label-alignment trap) but left nullify_weights on the old pattern.

Change

Pass index=self.index, plus a comment matching the one in set_weights, and a regression test covering sum, mean, and the resulting weight index.

Verification

  • New test fails before the change (0.0 == 6 assertion), passes after
  • make test — 63 passed on pandas 3.0.5 and pandas 2.3.3
  • make lint — passes

Note: the lint job will be red until #307 merges (unrelated ruff 0.16 issue on main).

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

MicroSeries.nullify_weights() ignores the index, making sum() return 0.0

1 participant