Skip to content

Commit 07858c2

Browse files
authored
BUG: dtype from nankurt and nanskew when returning 0 (#53482)
* BUG: dtype from nankurt and nanskew when returning 0 * add GH number * simplify
1 parent 6d8668a commit 07858c2

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

doc/source/whatsnew/v2.1.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ Numeric
347347
^^^^^^^
348348
- Bug in :class:`RangeIndex` setting ``step`` incorrectly when being the subtrahend with minuend a numeric value (:issue:`53255`)
349349
- Bug in :meth:`Series.corr` and :meth:`Series.cov` raising ``AttributeError`` for masked dtypes (:issue:`51422`)
350+
- Bug when calling :meth:`Series.kurt` and :meth:`Series.skew` on numpy data of all zero returning a python type instead of a numpy type (:issue:`53482`)
350351
- Bug in :meth:`Series.mean`, :meth:`DataFrame.mean` with object-dtype values containing strings that can be converted to numbers (e.g. "2") returning incorrect numeric results; these now raise ``TypeError`` (:issue:`36703`, :issue:`44008`)
351352
- Bug in :meth:`DataFrame.corrwith` raising ``NotImplementedError`` for pyarrow-backed dtypes (:issue:`52314`)
352353
- Bug in :meth:`DataFrame.size` and :meth:`Series.size` returning 64-bit integer instead of int (:issue:`52897`)

pandas/core/nanops.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@ def nanskew(
12671267
result = np.where(m2 == 0, 0, result)
12681268
result[count < 3] = np.nan
12691269
else:
1270-
result = 0 if m2 == 0 else result
1270+
result = dtype.type(0) if m2 == 0 else result
12711271
if count < 3:
12721272
return np.nan
12731273

@@ -1355,7 +1355,7 @@ def nankurt(
13551355
if count < 4:
13561356
return np.nan
13571357
if denominator == 0:
1358-
return 0
1358+
return values.dtype.type(0)
13591359

13601360
with np.errstate(invalid="ignore", divide="ignore"):
13611361
result = numerator / denominator - adj

pandas/tests/reductions/test_stat_reductions.py

+2
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ def test_skew(self):
244244
assert np.isnan(df.skew()).all()
245245
else:
246246
assert 0 == s.skew()
247+
assert isinstance(s.skew(), np.float64) # GH53482
247248
assert (df.skew() == 0).all()
248249

249250
@td.skip_if_no_scipy
@@ -267,4 +268,5 @@ def test_kurt_corner(self):
267268
assert np.isnan(df.kurt()).all()
268269
else:
269270
assert 0 == s.kurt()
271+
assert isinstance(s.kurt(), np.float64) # GH53482
270272
assert (df.kurt() == 0).all()

0 commit comments

Comments
 (0)