rogerlew / pyvttbl

Automatically exported from code.google.com/p/pyvttbl
10 stars 8 forks source link

Crash of pyvttbl.pivot().to_dataframe() #11

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. make sparse pivot table (e.g. some elements empty)
2. do .to_dataframe() on sparse pivot table
3. crash with message:

Traceback (most recent call last):
  File "pilot-cancelation-report.py", line 148, in <module>
    a.run()
  File "pilot-cancelation-report.py", line 142, in run
    d1 = df.pivot('ks', rows=['duvod_popis'], cols=['zruseno_rok','zruseno_tyden'], aggregate='sum').to_dataframe()
  File "/usr/lib/python2.7/site-packages/pyvttbl-0.5.2.2-py2.7.egg/pyvttbl/base.py", line 2374, in to_dataframe
    df.insert(zip(header, rdata))
  File "/usr/lib/python2.7/site-packages/pyvttbl-0.5.2.2-py2.7.egg/pyvttbl/base.py", line 1554, in insert
    self[k]=np.concatenate((self[k], np.array([v], dtype=self._get_nptype(k))))
TypeError: long() argument must be a string or a number, not 'NoneType'

I have dirty-fixed this with (around line 1553 of base.py):

        elif c - s == set():
            for (k, v) in OrderedDict(row).items():
                if v is None:
                    v = 0
                self[k]=np.concatenate((self[k], np.array([v], dtype=self._get_nptype(k))))
                self.conditions[k].add(v)

(if v is None, let v = 0). But this is only dirty fix.

What is the expected output? What do you see instead?

it should generate DataFrame object.

What version of the product are you using? On what operating system?

0.5.2.2
linux (debian)
python 2.7

Please provide any additional information below.

more info on request, I'm able provide example data, if necessary.

Original issue reported on code.google.com by profa...@gmail.com on 30 Apr 2013 at 12:51