Description
Problem description
DataFrame.replace
and Series.replace
fail unceremoniously on an empty Series or dict argument; I would expect it to simply do nothing.
While there is a fair bit of type-based wizardry going on in this function, I don't suppose there is any actual ambiguity in how this edge case should behave?
Code Sample, a copy-pastable example if possible
from pandas import Series
s = Series([0,0,1,1,2,2])
print(s.replace(Series([7,7])).tolist())
print(s.replace(Series([7])).tolist())
print(s.replace(Series([])).tolist())
Output
[7, 7, 7, 7, 2, 2]
[7, 7, 1, 1, 2, 2]
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-82-d889d2100216> in <module>()
3 print(s.replace(Series([7,7])).tolist())
4 print(s.replace(Series([7])).tolist())
----> 5 print(s.replace(Series([])).tolist())
/usr/local/lib/python3.5/dist-packages/pandas-0.19.2-py3.5-linux-x86_64.egg/pandas/core/generic.py in replace(self, to_replace, value, inplace, limit, regex, method, axis)
3438
3439 items = list(compat.iteritems(to_replace))
-> 3440 keys, values = zip(*items)
3441
3442 are_mappings = [is_dict_like(v) for v in values]
ValueError: not enough values to unpack (expected 2, got 0)
Expected Output
[7, 7, 7, 7, 2, 2]
[7, 7, 1, 1, 2, 2]
[0, 0, 1, 1, 2, 2]
Output of pd.show_versions()
pandas: 0.19.2
nose: None
pip: 8.1.2
setuptools: 27.2.0
Cython: 0.24.1
numpy: 1.11.1
scipy: 0.18.0
statsmodels: None
xarray: None
IPython: 5.1.0
sphinx: None
patsy: None
dateutil: 2.5.3
pytz: 2016.6.1
blosc: None
bottleneck: 1.2.0
tables: None
numexpr: 2.6.2
matplotlib: 1.5.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: 0.7.3
lxml: None
bs4: 4.4.1
html5lib: 0.999
httplib2: 0.9.1
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None
pandas_datareader: None