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
(matching the docstring)
Actual Results
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.
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
PolynomialCountSketchdocs against its implementation for an unrelatedperformance PR (#34919) and noticed the
bitHash_attribute's documenteddtype doesn't match what the code actually produces.
Describe the bug and give evidence about its user-facing impact
PolynomialCountSketch'sbitHash_attribute is documented as:but it is actually set with:
numpy.random.RandomState.choicewith an integer arraya=[-1, 1]and noexplicit
dtypeproduces an integer array, notfloat32. This has been thecase 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
Expected Results
(matching the docstring)
Actual Results
Versions
I'd be happy to open a PR to fix the docstring to say the actual dtype
(
int64, or more precisely whatevernumpy.random.RandomState.choicereturns for an integer input array) once this is triaged.