cvxportfolio icon indicating copy to clipboard operation
cvxportfolio copied to clipboard

null_checer(obj) function in data_management.py returns error

Open kch382001 opened this issue 5 years ago • 1 comments

When I ran the MultipPeriodOPtimization example, the volumes is loaded from csv.gz file and passed as a dataframe to the TCostModel setup.

volumes=pd.read_csv(datadir+'volumes.csv.gz',index_col=0,parse_dates=[0]).iloc[:,:-1] .... ... simulated_tcost = cp.TcostModel(half_spread=0.0005/2., nonlin_coeff=1., sigma=sigmas, volume=volumes)

The error happens on the following line: def null_checker(obj): """Check if obj contains NaN.""" if (isinstance(obj, pd.Panel) or isinstance(obj, pd.DataFrame) or isinstance(obj, pd.Series)): if np.any(pd.isnull(obj)): # this line spit error raise ValueError('Data object contains NaN values', obj) elif np.isscalar(obj): if np.isnan(obj): raise ValueError('Data object contains NaN values', obj) else: raise TypeError('Data object can only be scalar or Pandas.') ---- I got the following error: alueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

by changing it to np.any(pd.isnull(obj)).any() seems to fix the problem

kch382001 avatar Sep 04 '19 22:09 kch382001

I am using numpy 1.17.1. The issue does not exist on numpy 1.14. To be safe, it is better to change it to np.any(pd.isnull(obj)).any()

kch382001 avatar Sep 04 '19 22:09 kch382001