Search code examples
pythonscipyhistogramhistogram2dscipy.stats

Why is binned_statistic_2d now throwing TypeError?


I have been using scipy's binned_statistic_2d function to plot a 2d histogram of some data, particularly to return a list of the index of which bin the data is in, by setting the expand_binnumbers = True. It was working perfectly, until today. The following code demonstrates my problem:

import numpy as np
from scipy.stats import binned_statistic_2d as hist 

# my data is two arrays of numbers 
x = np.random.random((5,))
y = np.random.random((5,))

# I need to know which bin the values are in so I return the bin_idx
data = hist(x,y, bins = [2,2], statistic = 'count', values = None, expand_binnumbers = True)

bin_idx = data[3]

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

Any ideas why this should suddenly stop working?


Solution

  • The recent update to Scipy broke things somewhat - as @WarrenWeckesser said in the comments, setting values = x makes things work again.