Skip to content

Commit f1c886d

Browse files
authored
Min max sparse fillna (#41691)
1 parent 2003d93 commit f1c886d

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

pandas/core/arrays/sparse/array.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ def max(self, axis=0, *args, **kwargs):
13971397

13981398
# This condition returns a nan if there are no valid values in the array.
13991399
if self.size > 0 and self._valid_sp_values.size == 0:
1400-
return np.nan
1400+
return self.fill_value
14011401
else:
14021402
return np.nanmax(self, axis)
14031403

@@ -1406,7 +1406,7 @@ def min(self, axis=0, *args, **kwargs):
14061406

14071407
# This condition returns a nan if there are no valid values in the array.
14081408
if self.size > 0 and self._valid_sp_values.size == 0:
1409-
return np.nan
1409+
return self.fill_value
14101410
else:
14111411
return np.nanmin(self, axis)
14121412

pandas/tests/arrays/sparse/test_array.py

+4
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,9 @@ class TestMinMax:
13261326
data_neg = plain_data * (-1)
13271327
data_NaN = SparseArray(np.array([0, 1, 2, np.nan, 4]))
13281328
data_all_NaN = SparseArray(np.array([np.nan, np.nan, np.nan, np.nan, np.nan]))
1329+
data_NA_filled = SparseArray(
1330+
np.array([np.nan, np.nan, np.nan, np.nan, np.nan]), fill_value=5
1331+
)
13291332

13301333
@pytest.mark.parametrize(
13311334
"raw_data,max_expected,min_expected",
@@ -1334,6 +1337,7 @@ class TestMinMax:
13341337
(data_neg, [0], [-4]),
13351338
(data_NaN, [4], [0]),
13361339
(data_all_NaN, [np.nan], [np.nan]),
1340+
(data_NA_filled, [5], [5]),
13371341
],
13381342
)
13391343
def test_maxmin(self, raw_data, max_expected, min_expected):

0 commit comments

Comments
 (0)