Thanks to visit codestin.com
Credit goes to github.com

Skip to content

PolynomialCountSketch.bitHash_ docstring says dtype=float32 but is actually int64 #34923

Description

@regarmukesh3g

Warning

This issue is not yet ready for a PR. If you are interested in contributing to scikit-learn, please have a look at our contributing guidelines, and in particular the sections for new contributors and the "Needs triage" label.

Introduce yourself

I use scikit-learn for general ML work. I found this while cross-checking
the PolynomialCountSketch docs against its implementation for an unrelated
performance PR (#34919) and noticed the bitHash_ attribute's documented
dtype doesn't match what the code actually produces.

Describe the bug and give evidence about its user-facing impact

PolynomialCountSketch's bitHash_ attribute is documented as:

bitHash_ : ndarray of shape (degree, n_features), dtype=float32
    Array with random entries in {+1, -1}, used to represent
    the 2-wise independent hash functions for Count Sketch computation.

but it is actually set with:

self.bitHash_ = random_state.choice(a=[-1, 1], size=(self.degree, n_features))

numpy.random.RandomState.choice with an integer array a=[-1, 1] and no
explicit dtype produces an integer array, not float32. This has been the
case since the class was introduced (#13003, 2019),
so it is not a regression, just a docstring that was never accurate.

User-facing impact is limited (the attribute is internal-ish and the class
still works correctly), but anyone relying on the documented dtype — for
example writing code that assumes bitHash_.astype(np.float32, copy=False)
is a no-op, or reasoning about memory usage from the docstring — would be
misled.

Steps/Code to Reproduce

import numpy as np
from sklearn.kernel_approximation import PolynomialCountSketch

X = np.random.RandomState(0).random_sample((50, 20))
ps = PolynomialCountSketch(degree=2, n_components=10, random_state=0).fit(X)
print(ps.bitHash_.dtype)

Expected Results

float32

(matching the docstring)

Actual Results

int64

Versions

System:
    python: 3.14.6 (v3.14.6:c63aec69bd5, Jun 10 2026, 08:07:54) [Clang 21.0.0 (clang-2100.1.1.101)]
executable: /Library/Frameworks/Python.framework/Versions/3.14/bin/python3
   machine: macOS-26.5.2-arm64-arm-64bit-Mach-O

Python dependencies:
      sklearn: 1.10.dev0
          pip: 26.1.2
   setuptools: 83.0.0
        numpy: 2.5.1
        scipy: 1.18.1
       Cython: 3.3.0
       pandas: None
   matplotlib: None
       joblib: 1.6.0
threadpoolctl: 3.6.0
     narwhals: 2.25.0

Built with OpenMP: True

I'd be happy to open a PR to fix the docstring to say the actual dtype
(int64, or more precisely whatever numpy.random.RandomState.choice
returns for an integer input array) once this is triaged.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions