Skip to content

Commit cb6dba0

Browse files
committed
TST: added tests for GH pandas-dev#2837
1 parent 3134cb2 commit cb6dba0

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

pandas/sparse/frame.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,11 @@ def to_dense(self):
241241
return DataFrame(data, index=self.index)
242242

243243
def get_dtype_counts(self):
244-
from collections import Counter
245-
return Series(Counter([ v.dtype.name for k, v in self.iteritems() ]))
244+
from collections import defaultdict
245+
d = defaultdict(int)
246+
for k, v in self.iteritems():
247+
d[v.dtype.name] += 1
248+
return Series(d)
246249

247250
def astype(self, dtype):
248251
raise NotImplementedError

pandas/sparse/tests/test_sparse.py

+17
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,23 @@ def test_constructor_convert_index_once(self):
821821
sdf = SparseDataFrame(columns=range(4), index=arr)
822822
self.assertTrue(sdf[0].index is sdf[1].index)
823823

824+
def test_constructor_from_series(self):
825+
826+
# GH 2873
827+
x = Series(np.random.randn(10000), name='a')
828+
x = x.to_sparse(fill_value=0)
829+
self.assert_(isinstance(x,SparseSeries))
830+
df = SparseDataFrame(x)
831+
self.assert_(isinstance(df,SparseDataFrame))
832+
833+
x = Series(np.random.randn(10000), name ='a')
834+
y = Series(np.random.randn(10000), name ='b')
835+
x.ix[:9998] = 0
836+
x = x.to_sparse(fill_value=0)
837+
838+
# currently fails
839+
#df1 = SparseDataFrame([x, y])
840+
824841
def test_dtypes(self):
825842
df = DataFrame(np.random.randn(10000, 4))
826843
df.ix[:9998] = np.nan

0 commit comments

Comments
 (0)