Skip to content

Behaviour of .sum() inconsistent between Series and DataFrame when summing Decimals #13446

Closed
@tui-rob

Description

@tui-rob

Using sum() on a Series of Decimal datatypes returns a Decimal. However, using sum() on a DataFrame of Decimal datatypes returns floats.

I think it would be more consistent for the DataFrame sum() to return Decimals.

Code Sample

import pandas as pd
from decimal import Decimal

df = pd.DataFrame({'a':[Decimal('1.0'), Decimal('2.0')],
                   'b':[Decimal('3.0'), Decimal('4.0')]})

type(df['a'].sum()), type(df.sum()[0])

Out[1]: (decimal.Decimal, numpy.float64)

Expected Output

Out[1]: (decimal.Decimal, decimal.Decimal)

output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.5.1.final.0
python-bits: 32
OS: Windows
OS-release: 7
machine: x86
processor: x86 Family 6 Model 42 Stepping 7, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None

pandas: 0.18.0
nose: 1.3.7
pip: 7.1.2
setuptools: 18.5
Cython: 0.23.4
numpy: 1.10.1
scipy: 0.16.0
statsmodels: 0.6.1
xarray: None
IPython: 4.0.1
sphinx: 1.3.1
patsy: 0.4.0
dateutil: 2.4.2
pytz: 2015.7
blosc: None
bottleneck: 1.0.0
tables: 3.2.2
numexpr: 2.5
matplotlib: 1.5.0
openpyxl: 2.2.6
xlrd: 0.9.4
xlwt: 1.0.0
xlsxwriter: 0.7.7
lxml: 3.4.4
bs4: 4.4.1
html5lib: 0.999
httplib2: None
apiclient: None
sqlalchemy: 1.0.9
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.38.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions