Skip to content

assign None to Series got ValueError #20592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hack4code opened this issue Apr 3, 2018 · 3 comments
Closed

assign None to Series got ValueError #20592

hack4code opened this issue Apr 3, 2018 · 3 comments
Labels
Indexing Related to indexing on series/frames, not to indexes themselves

Comments

@hack4code
Copy link

hack4code commented Apr 3, 2018

import pandas as pd

s = pd.Series({'aa': 1})
s['aa'] = None

Problem description

got exception:
ValueError: ['a' 'a'] not contained in the index

Expected Output

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.4.final.0
python-bits: 64
OS: Darwin
OS-release: 17.5.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.21.0
pytest: None
pip: 9.0.1
setuptools: 28.8.0
Cython: None
numpy: 1.13.1
scipy: 0.19.1
pyarrow: None
xarray: None
IPython: 6.0.0
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999999999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@chris-b1
Copy link
Contributor

chris-b1 commented Apr 4, 2018

Strange, somewhere in the indexing code 'aa' gets treated as a iterable. PR would be welcome. Note that it would be more typical to use np.nan as a missing value, which is handled correctly (s['aa'] = np.nan)

@chris-b1 chris-b1 added this to the Next Major Release milestone Apr 4, 2018
@chris-b1 chris-b1 added Indexing Related to indexing on series/frames, not to indexes themselves Difficulty Intermediate labels Apr 4, 2018
@fredrik-1
Copy link

The problem is that _set_with_engine throws a typeError, _set_with is used instead which for some reason change the key to a list with key = list(key) and list('aa')=['a','a']

So one solution might be to change key=list(key) with

if isinstance(key, str):
     key=[key]
else:
     key = list(key)

I don't know if this works in both python 2 and 3

@JustinZhengBC
Copy link
Contributor

Solved in #23495

@jreback jreback closed this as completed Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

No branches or pull requests

5 participants