|
13 | 13 | import pandas._libs.sparse as splib
|
14 | 14 | from pandas._libs.sparse import BlockIndex, IntIndex, SparseIndex
|
15 | 15 | from pandas._libs.tslibs import NaT
|
| 16 | +from pandas._typing import Scalar |
16 | 17 | import pandas.compat as compat
|
17 | 18 | from pandas.compat.numpy import function as nv
|
18 | 19 | from pandas.errors import PerformanceWarning
|
|
46 | 47 | from pandas.core.construction import extract_array, sanitize_array
|
47 | 48 | from pandas.core.indexers import check_array_indexer
|
48 | 49 | from pandas.core.missing import interpolate_2d
|
| 50 | +from pandas.core.nanops import check_below_min_count |
49 | 51 | import pandas.core.ops as ops
|
50 | 52 | from pandas.core.ops.common import unpack_zerodim_and_defer
|
51 | 53 |
|
@@ -1220,21 +1222,36 @@ def any(self, axis=0, *args, **kwargs):
|
1220 | 1222 |
|
1221 | 1223 | return values.any().item()
|
1222 | 1224 |
|
1223 |
| - def sum(self, axis=0, *args, **kwargs): |
| 1225 | + def sum(self, axis: int = 0, min_count: int = 0, *args, **kwargs) -> Scalar: |
1224 | 1226 | """
|
1225 | 1227 | Sum of non-NA/null values
|
1226 | 1228 |
|
| 1229 | + Parameters |
| 1230 | + ---------- |
| 1231 | + axis : int, default 0 |
| 1232 | + Not Used. NumPy compatibility. |
| 1233 | + min_count : int, default 0 |
| 1234 | + The required number of valid values to perform the summation. If fewer |
| 1235 | + than ``min_count`` valid values are present, the result will be the missing |
| 1236 | + value indicator for subarray type. |
| 1237 | + *args, **kwargs |
| 1238 | + Not Used. NumPy compatibility. |
| 1239 | +
|
1227 | 1240 | Returns
|
1228 | 1241 | -------
|
1229 |
| - sum : float |
| 1242 | + scalar |
1230 | 1243 | """
|
1231 | 1244 | nv.validate_sum(args, kwargs)
|
1232 | 1245 | valid_vals = self._valid_sp_values
|
1233 | 1246 | sp_sum = valid_vals.sum()
|
1234 | 1247 | if self._null_fill_value:
|
| 1248 | + if check_below_min_count(valid_vals.shape, None, min_count): |
| 1249 | + return na_value_for_dtype(self.dtype.subtype, compat=False) |
1235 | 1250 | return sp_sum
|
1236 | 1251 | else:
|
1237 | 1252 | nsparse = self.sp_index.ngaps
|
| 1253 | + if check_below_min_count(valid_vals.shape, None, min_count - nsparse): |
| 1254 | + return na_value_for_dtype(self.dtype.subtype, compat=False) |
1238 | 1255 | return sp_sum + self.fill_value * nsparse
|
1239 | 1256 |
|
1240 | 1257 | def cumsum(self, axis=0, *args, **kwargs):
|
|
0 commit comments