merging two empty dataframes can incur a division by zero · Issue #17776 · pandas-dev/pandas (original) (raw)
Code Sample, a copy-pastable example if possible
import numpy import pandas
pandas.show_versions()
a = pandas.DataFrame({'a':[],'b':[],'c':[]}) numpy.seterr(divide='raise') pandas.merge(a,a,on=('a','b')) # no problem if we only merge on 'a'.
Problem description
The call to merge triggers a division by zero.
Traceback (most recent call last):
File "/homes/mickyl/work/bugs/pandas_merge_div_by_0.py", line 8, in
pandas.merge(a,a,on=('a','b'))
File "/homes/mickyl/venvs/debian8/local/lib/python2.7/site-packages/pandas/core/reshape/merge.py", line 54, in merge
return op.get_result()
File "/homes/mickyl/venvs/debian8/local/lib/python2.7/site-packages/pandas/core/reshape/merge.py", line 569, in get_result
join_index, left_indexer, right_indexer = self._get_join_info()
File "/homes/mickyl/venvs/debian8/local/lib/python2.7/site-packages/pandas/core/reshape/merge.py", line 734, in _get_join_info
right_indexer) = self._get_join_indexers()
File "/homes/mickyl/venvs/debian8/local/lib/python2.7/site-packages/pandas/core/reshape/merge.py", line 713, in _get_join_indexers
how=self.how)
File "/homes/mickyl/venvs/debian8/local/lib/python2.7/site-packages/pandas/core/reshape/merge.py", line 985, in _get_join_indexers
lkey, rkey = _get_join_keys(llab, rlab, shape, sort)
File "/homes/mickyl/venvs/debian8/local/lib/python2.7/site-packages/pandas/core/reshape/merge.py", line 1457, in _get_join_keys
stride //= shape[i]
FloatingPointError: divide by zero encountered in long_scalars
The expeted behaviour is for merge to return an empty dataframe without causing division by 0.
Expected Output
just a print-out of all the version numbers with no exception.
Output of pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 2.7.9.final.0
python-bits: 64
OS: Linux
OS-release: 4.7.0-0.bpo.1-amd64
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: None.None
pandas: 0.20.3
pytest: 2.6.3
pip: 9.0.1
setuptools: 5.5.1
Cython: 0.25.2
numpy: 1.13.3
scipy: 0.19.1
xarray: None
IPython: 5.4.1
sphinx: 1.2.3
patsy: None
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: 1.2.1
tables: 3.1.1
numexpr: 2.6.4
feather: None
matplotlib: 2.0.0
openpyxl: 2.4.8
xlrd: 0.9.2
xlwt: 0.7.5
xlsxwriter: 0.5.2
lxml: 3.4.0
bs4: None
html5lib: 0.999999999
sqlalchemy: 0.9.8
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: None