Quantipy / quantipy

Python for people data
MIT License
66 stars 14 forks source link

DataSet.first_responses fails if the variable is not populated #1302

Closed jamesrkg closed 5 years ago

jamesrkg commented 5 years ago

I had an example where the variable happened to be completely empty, and in this case:

c:\users\jamesg\documents\techops\dev\quantipy\quantipy\core\dataset.pyc in first_responses(self, name, n, others, reduce_values)
   4073             n_label = '{} ({})'.format(self.text(name), _n)
   4074             self.add_meta(n_name, 'single', n_label, values)
-> 4075             n_vector = self[name].str.split(';', n=_n, expand=True)[_n-1]
   4076             self[n_name] = n_vector.replace(('', None), np.NaN).astype(float)
   4077             created.append(n_name)

c:\users\jamesg\.conda\envs\scratch\lib\site-packages\pandas\core\generic.pyc in __getattr__(self, name)
   2738         if (name in self._internal_names_set or name in self._metadata or
   2739                 name in self._accessors):
-> 2740             return object.__getattribute__(self, name)
   2741         else:
   2742             if name in self._info_axis:

c:\users\jamesg\.conda\envs\scratch\lib\site-packages\pandas\core\base.pyc in __get__(self, instance, owner)
    239             # this ensures that Series.str.<method> is well defined
    240             return self.accessor_cls
--> 241         return self.construct_accessor(instance)
    242 
    243     def __set__(self, instance, value):

c:\users\jamesg\.conda\envs\scratch\lib\site-packages\pandas\core\strings.pyc in _make_str_accessor(self)
   1839             # (instead of test for object dtype), but that isn't practical for
   1840             # performance reasons until we have a str dtype (GH 9343)
-> 1841             raise AttributeError("Can only use .str accessor with string "
   1842                                  "values, which use np.object_ dtype in "
   1843                                  "pandas")

AttributeError: Can only use .str accessor with string values, which use np.object_ dtype in pandas
alextanski commented 5 years ago

closed.