kieferk / dfply

dplyr-style piping operations for pandas dataframes
GNU General Public License v3.0
889 stars 103 forks source link

ValueError: Item wrong length 114 instead of 60. #20

Closed Make42 closed 7 years ago

Make42 commented 7 years ago

With my simple code

 resultstatsDF >> mask(X.method == 'MICE')

I get the error

Traceback (most recent call last):
  File "/Development/Anaconda-Python-Distribution/anaconda2/envs/myenv/lib/python3.5/code.py", line 91, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "/Development/Anaconda-Python-Distribution/anaconda2/envs/myenv/lib/python3.5/site-packages/dfply/base.py", line 45, in __rrshift__
    result = self.function(other_copy)
  File "/Development/Anaconda-Python-Distribution/anaconda2/envs/myenv/lib/python3.5/site-packages/dfply/base.py", line 52, in <lambda>
    return pipe(lambda x: self.function(x, *args, **kwargs))
  File "/Development/Anaconda-Python-Distribution/anaconda2/envs/myenv/lib/python3.5/site-packages/dfply/base.py", line 112, in __call__
    return self.function(*args, **kwargs)
  File "/Development/Anaconda-Python-Distribution/anaconda2/envs/myenv/lib/python3.5/site-packages/dfply/base.py", line 179, in __call__
    evaluation = self.call_action(args, kwargs)
  File "/Development/Anaconda-Python-Distribution/anaconda2/envs/myenv/lib/python3.5/site-packages/dfply/base.py", line 253, in call_action
    return symbolic.to_callable(symbolic_function)(args[0])
  File "/Development/Anaconda-Python-Distribution/anaconda2/envs/myenv/lib/python3.5/site-packages/pandas_ply/symbolic.py", line 204, in <lambda>
    return lambda *args, **kwargs: obj._eval(dict(enumerate(args), **kwargs))
  File "/Development/Anaconda-Python-Distribution/anaconda2/envs/myenv/lib/python3.5/site-packages/pandas_ply/symbolic.py", line 142, in _eval
    result = evaled_func(*evaled_args, **evaled_kwargs)
  File "/Development/Anaconda-Python-Distribution/anaconda2/envs/myenv/lib/python3.5/site-packages/dfply/subset.py", line 56, in mask
    return df[mask.values]
  File "/Development/Anaconda-Python-Distribution/anaconda2/envs/myenv/lib/python3.5/site-packages/pandas/core/frame.py", line 2053, in __getitem__
    return self._getitem_array(key)
  File "/Development/Anaconda-Python-Distribution/anaconda2/envs/myenv/lib/python3.5/site-packages/pandas/core/frame.py", line 2090, in _getitem_array
    (len(key), len(self.index)))
ValueError: Item wrong length 114 instead of 60.

Where my resultstatsDF.shape is (60, 10). What am I to do?

Could it be that it has something to do with my the following?

resultstatsDF.index
Int64Index([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5],
           dtype='int64')
Make42 commented 7 years ago

Man, today it seems I get to the solution just after I write my question... Indeed resetting the index helped: resultstatsDF = resultstatsDF.reset_index()

I will the issue and solution stand - maybe it will be useful to someone in the future.