Skip to content

Commit 5ab3b1c

Browse files
committed
Fixed issue#63444 w/ doc update
1 parent e807bb7 commit 5ab3b1c

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,7 @@ Other
14531453
array if the array shares data with the original DataFrame or Series (:ref:`copy_on_write_read_only_na`).
14541454
This logic is expanded to accessing the underlying pandas ExtensionArray
14551455
through ``.array`` (or ``.values`` depending on the dtype) as well (:issue:`61925`).
1456-
1456+
- Bug in :meth:`Series.round` where series shows TypeError when passed empty Series (:issue:`63444`)
14571457
.. ***DO NOT USE THIS SECTION***
14581458
14591459
.. ---------------------------------------------------------------------------

pandas/core/series.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,11 +2579,11 @@ def round(self, decimals: int = 0, *args, **kwargs) -> Series:
25792579
dtype: float64
25802580
"""
25812581
nv.validate_round(args, kwargs)
2582-
if not self.empty and (self.dtype == "object" or self.dtype=='str'):
2582+
if not self.empty and (self.dtype == "object" or self.dtype == "str"):
25832583
raise TypeError("Expected numeric dtype, got object instead.")
2584-
if not self.empty and (self.dtype=='str'):
2584+
if not self.empty and (self.dtype == "str"):
25852585
raise TypeError("Expected numeric dtype, got string instead.")
2586-
2586+
25872587
new_mgr = self._mgr.round(decimals=decimals)
25882588
return self._constructor_from_mgr(new_mgr, axes=new_mgr.axes).__finalize__(
25892589
self, method="round"
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,40 @@
11
import pytest
2-
import numpy as np
2+
33
import pandas as pd
44
import pandas.testing as tm
55

6-
#GH63444
6+
# GH63444
77

88

99
def test_series_round_empty1():
1010
result = pd.Series([]).round(2)
1111
expected = pd.Series([])
12+
tm.assert_series_equal(result, expected)
13+
1214

1315
def test_series_round_empty2():
14-
result = pd.Series([], dtype='float64').round()
15-
expected = pd.Series([], dtype='float64')
16+
result = pd.Series([], dtype="float64").round()
17+
expected = pd.Series([], dtype="float64")
1618
tm.assert_series_equal(result, expected)
19+
20+
1721
def test_series_round_numeric():
1822
result = pd.Series([1.2345, 2.6789, 3.14159]).round(2)
1923
expected = pd.Series([1.23, 2.68, 3.14])
2024
tm.assert_series_equal(result, expected)
25+
26+
2127
def test_series_round_integers():
2228
result = pd.Series([1, 2, 3]).round(2)
2329
expected = pd.Series([1, 2, 3])
2430
tm.assert_series_equal(result, expected)
2531

32+
2633
def test_series_round_str():
2734
with pytest.raises(TypeError):
28-
pd.Series(['a', 'b', 'c']).round(2)
35+
pd.Series(["a", "b", "c"]).round(2)
36+
37+
2938
def test_series_round_obj():
3039
with pytest.raises(TypeError):
31-
pd.Series(['123'], dtype='object').round(2)
40+
pd.Series(["123"], dtype="object").round(2)

0 commit comments

Comments
 (0)