Skip to content

'ValueError: Cannot assign nan to integer series" when calling where on Series with non-unique index. #4550

Closed
@jgehrcke

Description

@jgehrcke

Create a Series with non-unique index:

>>> import pandas as pd
>>> pd.__version__
'0.12.0'
>>> s1 = pd.Series(range(3))
>>> s2 = pd.Series(range(3))
>>> comb = pd.concat([s1,s2])
>>> comb
0    0
1    1
2    2
0    0
1    1
2    2
dtype: int64

As of #4548 I cannot use comb[comb<2] =+ 10, so I tried working with where (according to http://pandas.pydata.org/pandas-docs/stable/indexing.html#where-and-masking, stating "To guarantee that selection output has the same shape as the original data, you can use the where method in Series and DataFrame"). But already calling where on comb is problematic:

>>> comb.where(comb < 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/projects/bioinfp_apps/Python-2.7.3/lib/python2.7/site-packages/pandas/core/series.py", line 745, in where
    ser._set_with(~cond, other)
  File "/projects/bioinfp_apps/Python-2.7.3/lib/python2.7/site-packages/pandas/core/series.py", line 886, in _set_with
    self._set_values(key, value)
  File "/projects/bioinfp_apps/Python-2.7.3/lib/python2.7/site-packages/pandas/core/series.py", line 904, in _set_values
    values[key] = _index.convert_scalar(values, value)
  File "index.pyx", line 547, in pandas.index.convert_scalar (pandas/index.c:9752)
  File "index.pyx", line 560, in pandas.index.convert_scalar (pandas/index.c:9639)
ValueError: Cannot assign nan to integer series
>>> 

Is this expected?

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDtype ConversionsUnexpected or buggy dtype conversionsIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions