Skip to content

Issue with Zero's Broadcasting down a column in Heterogeneous data columns ... #13758

Closed
@mmcky

Description

@mmcky

I had a recent use case which produced some unexpected output and I have isolated the problem down to a much simpler case to replicate the behavior.

Please see simplified code example below.

Code Sample, a copy-pastable example if possible

import pandas as pd
import numpy as np
data = {
    'One' : pd.Series(['A', 1.2, np.nan]),
    'Two' : pd.Series([1.4, 3.2, 4.5])
}
df = pd.DataFrame(data)

Doing the sum across the first column (which in this case is redundant). [Note: In my case I was doing groupby operations where some columns were being summed and others were single columns as indexed by a level of a MultiIndex. The issue was that some of the columns ended up being full of 0's)

df[['One']].sum(axis=1)

produces an unexpected outcome:

0    0.0
1    0.0
2    0.0
dtype: float64

I think this might be an error and it produces a valid column of 0's that is of dtype=float64.

Expected Output

0      A
1    1.2
2    NaN
Name: One, dtype: object

output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Linux
OS-release: 3.16.0-38-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.18.1
nose: 1.3.7
pip: 8.1.2
setuptools: 23.0.0
Cython: 0.24
numpy: 1.11.1
scipy: 0.17.1
statsmodels: 0.6.1
xarray: None
IPython: 4.2.0
sphinx: 1.4.1
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.4
blosc: None
bottleneck: 1.1.0
tables: 3.2.2
numexpr: 2.6.0
matplotlib: 1.5.1
openpyxl: 2.3.2
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.2
lxml: 3.6.0
bs4: 4.4.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.13
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.40.0
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions