Skip to content

IndexError in repr of series objects containing complex numbers with negative imaginary parts #27484

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
DRMacIver opened this issue Jul 19, 2019 · 1 comment · Fixed by #27511
Labels
Complex Complex Numbers Output-Formatting __repr__ of pandas objects, to_string
Milestone

Comments

@DRMacIver
Copy link

Code Sample, a copy-pastable example if possible

from pandas import Series

print(Series([-1j]))

Problem description

This raises the following error:

Traceback (most recent call last):
  File "foo.py", line 3, in <module>
    print(Series([-1j]))
  File "/home/david/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pandas/core/series.py", line 1611, in __repr__
    length=show_dimensions,
  File "/home/david/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pandas/core/series.py", line 1677, in to_string
    result = formatter.to_string()
  File "/home/david/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pandas/io/formats/format.py", line 312, in to_string
    fmt_values = self._get_formatted_values()
  File "/home/david/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pandas/io/formats/format.py", line 299, in _get_formatted_values
    values_to_format, None, float_format=self.float_format, na_rep=self.na_rep
  File "/home/david/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pandas/io/formats/format.py", line 1032, in format_array
    return fmt_obj.get_result()
  File "/home/david/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pandas/io/formats/format.py", line 1063, in get_result
    fmt_values = self._format_strings()
  File "/home/david/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pandas/io/formats/format.py", line 1288, in _format_strings
    return list(self.get_result_as_array())
  File "/home/david/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pandas/io/formats/format.py", line 1252, in get_result_as_array
    formatted_values = format_values_with(float_format)
  File "/home/david/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pandas/io/formats/format.py", line 1234, in format_values_with
    return _trim_zeros_complex(values, na_rep)
  File "/home/david/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pandas/io/formats/format.py", line 1597, in _trim_zeros_complex
    return ["".join(separate_and_trim(x, na_rep)) for x in str_complexes]
  File "/home/david/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pandas/io/formats/format.py", line 1597, in <listcomp>
    return ["".join(separate_and_trim(x, na_rep)) for x in str_complexes]
  File "/home/david/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pandas/io/formats/format.py", line 1594, in separate_and_trim
    + ["j"]
IndexError: list index out of range

Expected Output

This should print something like the following:

0    0.0-1.0j
dtype: complex128

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]

INSTALLED VERSIONS

commit : None
python : 3.7.4.final.0
python-bits : 64
OS : Linux
OS-release : 4.4.0-17134-Microsoft
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 0.25.0
numpy : 1.16.4
pytz : 2019.1
dateutil : 2.8.0
pip : 19.0.3
setuptools : 40.8.0
Cython : None
pytest : 5.0.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 7.6.1
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None

@mroeschke
Copy link
Member

PR #25745 is probably the culprit for this regression. Investigation and PR's welcome!

@mroeschke mroeschke added Complex Complex Numbers Output-Formatting __repr__ of pandas objects, to_string labels Jul 19, 2019
@mroeschke mroeschke added this to the 0.25.1 milestone Jul 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Complex Complex Numbers Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants