You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can create a normal DataFrame with, e.g., pandas.DataFrame(0, index=[1, 2, 3], columns=["A", "B", "C"]). However, this fails with a SparseDataFrame:
>>> x = pandas.SparseDataFrame(0, index=[1, 2, 3], columns=["A", "B", "C"])
Traceback (most recent call last):
File "<pyshell#97>", line 1, in <module>
x = pandas.SparseDataFrame(0, index=[1, 2, 3], columns=["A", "B", "C"])
File "c:\users\brenbarn\documents\python\extensions\pandas\pandas\sparse\frame.py", line 123, in __init__
NDFrame.__init__(self, mgr)
UnboundLocalError: local variable 'mgr' referenced before assignment
It looks like the code in SparseDataFrame.__init__ is not handling the case where the data is a single value. It has a bunch of if statements to handle different kinds of data, but falls through without creating mgr if none of them are met.
This makes it difficult to create an "empty" SparseDataFrame whose default fill value is something other than nan, e.g., pandas.SparseDataFrame(0, index=[1, 2, 3], columns=["A", "B", "C"], default_fill_value=0). In fact, I would suggest that if a default_fill_value is provided but no data is provided, the SparseDataFrame should be filled with the fill value (not nan), but perhaps that warrants a separate issue.
The text was updated successfully, but these errors were encountered:
# "real world" data that can be used to demonstrate this behavior
#http://archive.ics.uci.edu/ml/datasets/URL+Reputation
# http://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_svmlight_file.html
import pandas as pd
from sklearn.datasets import load_svmlight_file
X,y = load_svmlight_file('Day0.svm')
dataframe=pd.SparseDataFrame(X)
Traceback (most recent call last):
File "", line 1, in
File "C:\Anaconda\lib\site-packages\pandas\sparse\frame.py", line 122, in init
NDFrame.init(self, mgr)
UnboundLocalError: local variable 'mgr' referenced before assignment
You can create a normal DataFrame with, e.g.,
pandas.DataFrame(0, index=[1, 2, 3], columns=["A", "B", "C"])
. However, this fails with a SparseDataFrame:It looks like the code in
SparseDataFrame.__init__
is not handling the case where the data is a single value. It has a bunch of if statements to handle different kinds of data, but falls through without creatingmgr
if none of them are met.This makes it difficult to create an "empty" SparseDataFrame whose default fill value is something other than
nan
, e.g.,pandas.SparseDataFrame(0, index=[1, 2, 3], columns=["A", "B", "C"], default_fill_value=0)
. In fact, I would suggest that if a default_fill_value is provided but no data is provided, the SparseDataFrame should be filled with the fill value (notnan
), but perhaps that warrants a separate issue.The text was updated successfully, but these errors were encountered: