Skip to content

cut with np.inf gives TypeError #5483

@DanielWeitzenfeld

Description

@DanielWeitzenfeld
import pandas as pd
import numpy as np
arr = np.random.randn(20)
factor = pd.cut(arr, [-np.inf, 0, np.inf])

gives this error:

Traceback (most recent call last):
File "", line 1, in
File "/Users/weitzenfeld/anaconda/lib/python2.7/site-packages/pandas/tools/tile.py", line 102, in cut
include_lowest=include_lowest)
File "/Users/weitzenfeld/anaconda/lib/python2.7/site-packages/pandas/tools/tile.py", line 168, in _bins_to_cuts
include_lowest=include_lowest)
File "/Users/weitzenfeld/anaconda/lib/python2.7/site-packages/pandas/tools/tile.py", line 204, in _format_levels
fa, fb = fmt(a), fmt(b)
File "/Users/weitzenfeld/anaconda/lib/python2.7/site-packages/pandas/tools/tile.py", line 200, in
fmt = lambda v: _format_label(v, precision=prec)
File "/Users/weitzenfeld/anaconda/lib/python2.7/site-packages/pandas/tools/tile.py", line 247, in _format_label
return sgn + '%d' % whole
TypeError: %d format: a number is required, not numpy.float64

I'm using pandas version 0.12.0. Removing the -np.inf and np.inf eliminates the error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions