File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -378,7 +378,8 @@ def to_dense(self, sparse_only=False):
378
378
379
379
@property
380
380
def density (self ):
381
- return float (len (self .sp_index )) / len (self .index )
381
+ r = float (self .sp_index .npoints ) / float (self .sp_index .length )
382
+ return r
382
383
383
384
def astype (self , dtype = None ):
384
385
"""
Original file line number Diff line number Diff line change @@ -156,6 +156,14 @@ def test_construct_DataFrame_with_sp_series(self):
156
156
# it works!
157
157
df = DataFrame ({'col' : self .bseries })
158
158
159
+ def test_series_density (self ):
160
+ # GH2803
161
+ ts = Series (np .random .randn (10 ))
162
+ ts [2 :- 2 ] = nan
163
+ sts = ts .to_sparse ()
164
+ density = sts .density # don't die
165
+ self .assertEqual (density ,4 / 10.0 )
166
+
159
167
def test_sparse_to_dense (self ):
160
168
arr , index = _test_data1 ()
161
169
series = self .bseries .to_dense ()
You can’t perform that action at this time.
0 commit comments