|
10 | 10 |
|
11 | 11 | import operator
|
12 | 12 |
|
13 |
| -from pandas.core.common import (isnull, _pickle_array, _unpickle_array, |
| 13 | +from pandas.core.common import (isnull, notnull, _pickle_array, _unpickle_array, |
14 | 14 | _mut_exclusive, _ensure_index, _try_sort)
|
15 | 15 | from pandas.core.index import Index, NULL_INDEX
|
16 | 16 | from pandas.core.series import Series, TimeSeries
|
@@ -510,6 +510,23 @@ def sum(self, axis=None, dtype=None, out=None):
|
510 | 510 | nsparse = self.sp_index.npoints
|
511 | 511 | return sp_sum + self.fill_value * nsparse
|
512 | 512 |
|
| 513 | + def cumsum(self, axis=0, dtype=None, out=None): |
| 514 | + """ |
| 515 | + Cumulative sum of values. Preserves NaN values |
| 516 | +
|
| 517 | + Extra parameters are to preserve ndarray interface. |
| 518 | +
|
| 519 | + Returns |
| 520 | + ------- |
| 521 | +
|
| 522 | + """ |
| 523 | + if not np.isnan(self.fill_value): |
| 524 | + return self.to_dense().cumsum() |
| 525 | + return SparseSeries(self.sp_values.cumsum(), |
| 526 | + index=self.index, |
| 527 | + sparse_index=self.sp_index, |
| 528 | + fill_value=self.fill_value) |
| 529 | + |
513 | 530 | def mean(self, axis=None, dtype=None, out=None):
|
514 | 531 | """
|
515 | 532 | Mean of non-null values
|
@@ -1057,6 +1074,21 @@ def count(self, axis=0, **kwds):
|
1057 | 1074 | """
|
1058 | 1075 | return self.apply(SparseSeries.count, axis=axis)
|
1059 | 1076 |
|
| 1077 | + def cumsum(self, axis=0): |
| 1078 | + """ |
| 1079 | + Return SparseDataFrame of cumulative sums over requested axis. |
| 1080 | +
|
| 1081 | + Parameters |
| 1082 | + ---------- |
| 1083 | + axis : {0, 1} |
| 1084 | + 0 for row-wise, 1 for column-wise |
| 1085 | +
|
| 1086 | + Returns |
| 1087 | + ------- |
| 1088 | + y : SparseDataFrame |
| 1089 | + """ |
| 1090 | + return self.apply(SparseSeries.cumsum, axis=axis) |
| 1091 | + |
1060 | 1092 | def shift(self, periods, offset=None, timeRule=None):
|
1061 | 1093 | """
|
1062 | 1094 | Analogous to DataFrame.shift
|
|
0 commit comments