Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

value_counts: TypeError: bins argument only works with numeric data. #54857

Closed
anmyachev opened this issue Aug 29, 2023 · 0 comments · Fixed by #54884
Closed

value_counts: TypeError: bins argument only works with numeric data. #54857

anmyachev opened this issue Aug 29, 2023 · 0 comments · Fixed by #54884
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@anmyachev
Copy link
Contributor

Reproducer:

import pandas as pd
import numpy as np

values = np.array([3, 1, 2, 3, 4, np.nan])
pd.value_counts(values, bins=3)  # <- TypeError: bins argument only works with numeric data.
pd.Series(values).value_counts(bins=3)  # <- TypeError: bins argument only works with numeric data.

numpy 1.25.2
pandas 2.1.0rc0

>>> pd.Series(values).value_counts(bins=3)
Traceback (most recent call last):
  File "Miniconda3\envs\modin\lib\site-packages\pandas\core\algorithms.py", line 882, in value_counts_internal
    ii = cut(values, bins, include_lowest=True)
  File "Miniconda3\envs\modin\lib\site-packages\pandas\core\reshape\tile.py", line 258, in cut
    rng = (nanops.nanmin(x), nanops.nanmax(x))
  File "Miniconda3\envs\modin\lib\site-packages\pandas\core\nanops.py", line 147, in f
    result = alt(values, axis=axis, skipna=skipna, **kwds)
  File "Miniconda3\envs\modin\lib\site-packages\pandas\core\nanops.py", line 404, in new_func
    result = func(values, axis=axis, skipna=skipna, mask=mask, **kwargs)
  File "Miniconda3\envs\modin\lib\site-packages\pandas\core\nanops.py", line 1089, in reduction
    values, mask = _get_values(
  File "Miniconda3\envs\modin\lib\site-packages\pandas\core\nanops.py", line 316, in _get_values
    np.putmask(values, mask, fill_value)
TypeError: putmask: first argument must be an array

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "Miniconda3\envs\modin\lib\site-packages\pandas\core\base.py", line 1010, in value_counts
    return algorithms.value_counts_internal(
  File "Miniconda3\envs\modin\lib\site-packages\pandas\core\algorithms.py", line 884, in value_counts_internal
    raise TypeError("bins argument only works with numeric data.") from err
TypeError: bins argument only works with numeric data.
@phofl phofl added Regression Functionality that used to work in a prior pandas version Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff labels Aug 30, 2023
@phofl phofl added this to the 2.1.1 milestone Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants