Skip to content

BUG: make duplicated hashtable test levels distinct - #66786

Draft
aryansk wants to merge 2 commits into
pandas-dev:mainfrom
aryansk:fix/66774-duplicated-hashtable-rng
Draft

BUG: make duplicated hashtable test levels distinct#66786
aryansk wants to merge 2 commits into
pandas-dev:mainfrom
aryansk:fix/66774-duplicated-hashtable-rng

Conversation

@aryansk

@aryansk aryansk commented Aug 15, 2026

Copy link
Copy Markdown

What this changes

test_duplicated_hashtable_impl instantiated np.random.default_rng(2) inside the comprehension, so a new generator with the same seed was created on every iteration and each level received the identical code sequence. The MultiIndex then collapsed to only n distinct label tuples, so the test exercised duplicate detection over a far narrower input than intended (it regressed in #54209, which used to draw once per level from a shared RNG).

This reuses a single generator across levels, restoring distinct codes per level (53 distinct tuples vs 6 for the same seed) while keeping the parametrized keep assertions intact.

How I used AI

I used an AI coding agent (opencode, Anthropic Claude model family) to help analyze the issue, verify the RNG behavior against a source build, and draft this change. I reviewed and understood the final diff (a one-line RNG refactor) and validated it by running the full test_duplicates.py module against a local source build — all 51 tests pass.

Closes: #66774

test_duplicated_hashtable_impl instantiated a fresh default_rng(2) inside
the comprehension, so every level drew the identical sequence and the
MultiIndex collapsed to only n distinct label tuples. Reuse one generator
across levels so the test exercises duplicate detection over a much wider
input, as it did before pandas-dev#54209.

Closes pandas-dev#66774
@github-actions github-actions Bot added the Needs Issue Assignment PR whose author is not assigned to a linked issue label Aug 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for the pull request, @aryansk! It's linked to #66774, but that issue isn't assigned to you yet. To make sure two people don't unknowingly work on the same thing, we ask contributors to claim an issue first. Just comment /take on #66774 to claim it, and you're good to go. See the contributing guide for the full flow.

Comment thread doc/source/whatsnew/v3.1.0.rst Outdated
- Bug in :meth:`DataFrame.select_dtypes` with an :class:`~pandas.api.extensions.ExtensionDtype` subclass such as :class:`ArrowDtype` or :class:`DatetimeTZDtype` raising ``TypeError``, emitting a spurious ``UserWarning``, or selecting the wrong columns; passing such a class now selects every column whose dtype is an instance of that class (:issue:`65366`)
- Bug in :meth:`Series.transform` and :meth:`DataFrame.transform` where passing a list of duplicate function names did not raise :class:`errors.SpecificationError` (:issue:`54929`)
- Bug in ``register_option`` where registering an option whose name was a prefix of an existing option (e.g. ``"a.b"`` when ``"a.b.c"`` was already registered) silently overwrote the existing option's namespace instead of raising (:issue:`29242`)
- Fixed ``MultiIndex`` duplicate detection tests instantiating a fresh RNG for every level, so each level received identical code arrays and the index collapsed to only ``n`` distinct label tuples (:issue:`66774`)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Tests don’t get whatsnew entries

@jbrockmendel

Copy link
Copy Markdown
Member

You checked the box saying you had said which AI you used, but you didn't actually do that.

@aryansk

aryansk commented Aug 15, 2026

Copy link
Copy Markdown
Author

Thanks @jbrockmendel — two fixes:

  1. AI disclosure: the PR was prepared with an AI coding agent (opencode, Anthropic Claude model family). I have reviewed and understood the change; I've updated the PR description to name the tool explicitly.
  2. The whatsnew entry is dropped (test-only change) and the checkbox updated — commit f1589e0 pushed.

Issue #66774 is now claimed via /take per the contributing guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Issue Assignment PR whose author is not assigned to a linked issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: test_duplicated_hashtable_impl generates identical codes for every MultiIndex level

2 participants