Skip to content

Adding column of floats to DataFrame yields TypeError #7366

@fonnesbeck

Description

@fonnesbeck

I have a function that builds a DataFrame of summary statistics that I have used routinely for several months, but now breaks due to a change in Pandas over the past few weeks. Specifically, I have the following list of floats:

(Pdb) [r[0] for r in ratios] [1.1200000000000001, 5.0, 0.73999999999999999, 0.35999999999999999, 1.1100000000000001, 1.1699999999999999, 0.92000000000000004, 0.94999999999999996, 1.0600000000000001, 0.77000000000000002, 0.59999999999999998, 2.0099999999999998, 3.2999999999999998, 0.37, 1.6100000000000001, 1.02] 

Which I use to create a column in the following table:

(Pdb) table oxygen 0 1 male 0.57 0.59 under 2 months 0.06 0.23 2-11 months 0.66 0.59 12-23 months 0.23 0.10 Jordanian 0.90 0.91 Palestinian 0.05 0.06 vitamin D < 20 0.55 0.53 vitamin D < 11 0.40 0.38 prev_cond 0.11 0.11 heart_hx 0.05 0.04 breastfed 0.68 0.56 premature 0.13 0.23 adm_pneumo 0.09 0.25 adm_bronchopneumo 0.52 0.28 adm_sepsis 0.11 0.16 adm_bronchiolitis 0.21 0.21 

However, this now causes the following:

(Pdb) table['foo'] = [r[0] for r in ratios] *** TypeError: Not implemented for this type 

Here is a more verbose output:

TypeError Traceback (most recent call last) <ipython-input-49-0723b2a631c0> in <module>() ----> 1 make_table(groupby_o2, table_vars=table_vars, replace_dict={0.0: 'No Oxygen', 1.0: 'Oxygen'}) <ipython-input-47-6f3ebc37c721> in make_table(groupby, table_vars, replace_dict) 3 ratios = [calc_or(groupby, v) for v in table.index] 4 import pdb; pdb.set_trace() ----> 5 table['OR'] = [r[0] for r in ratios] 6 table['Interval'] = [r[1] for r in ratios] 7 table['N'] = [r[2] for r in ratios] /usr/local/lib/python2.7/site-packages/pandas/core/frame.pyc in __setitem__(self, key, value) 1899 else: 1900 # set column -> 1901 self._set_item(key, value) 1902 1903 def _setitem_slice(self, key, value): /usr/local/lib/python2.7/site-packages/pandas/core/frame.pyc in _set_item(self, key, value) 1982 self._ensure_valid_index(value) 1983 value = self._sanitize_column(key, value) -> 1984 NDFrame._set_item(self, key, value) 1985 1986 # check if we are modifying a copy /usr/local/lib/python2.7/site-packages/pandas/core/generic.pyc in _set_item(self, key, value) 1137 1138 def _set_item(self, key, value): -> 1139 self._data.set(key, value) 1140 self._clear_item_cache() 1141 /usr/local/lib/python2.7/site-packages/pandas/core/internals.pyc in set(self, item, value, check) 2637 2638 try: -> 2639 loc = self.items.get_loc(item) 2640 except KeyError: 2641 # This item wasn't present, just insert at end /usr/local/lib/python2.7/site-packages/pandas/core/index.pyc in get_loc(self, key) 2055 2056 def get_loc(self, key): -> 2057 if np.isnan(key): 2058 try: 2059 return self._nan_idxs.item() TypeError: Not implemented for this type 

Not exactly sure which change caused it, but this code was working on the same data 3-4 weeks ago.

Currently running 0.13.1-936-g592a537 on OS X 10.9.3, Python 2.7.6 from Homebrew.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexingRelated to indexing on series/frames, not to indexes themselvesRegressionFunctionality that used to work in a prior pandas version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions