Skip to content
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

BUG: Fix formatting of complex numbers with exponents #60417

Merged
merged 1 commit into from
Nov 26, 2024

Conversation

snitish
Copy link
Contributor

@snitish snitish commented Nov 25, 2024

>>> input_array=[(1.8816e-09+0j), (3.39676e-09+0j)]
>>> pd.Series(input_array)
0    1.881600e-09+0.000000e+                    00j
1    3.396760e-09+0.000000e+                    00j
dtype: complex128

The issue was due to the regex in the _trim_zeros_complex function not being able to handle +/- in the exponent. It assumes the complex number string to be of the form (-)xxx(+/)yyyj. I fixed the regex so it doesn't split on +/- if preceded by an exponent.
Post the fix:

>>> input_array=[(1.8816e-09+0j), (3.39676e-09+0j)]
>>> pd.Series(input_array)
0    1.881600e-09+0.000000e+00j
1    3.396760e-09+0.000000e+00j
dtype: complex128

@snitish
Copy link
Contributor Author

snitish commented Nov 25, 2024

@mroeschke Thanks for your feedback on #60405. Raised a new PR with amendments.

@snitish snitish changed the title Fix formatting of complex numbers with exponents BUG: Fix formatting of complex numbers with exponents Nov 25, 2024
@mroeschke mroeschke added the Output-Formatting __repr__ of pandas objects, to_string label Nov 26, 2024
@mroeschke mroeschke added this to the 3.0 milestone Nov 26, 2024
@mroeschke mroeschke merged commit 759874e into pandas-dev:main Nov 26, 2024
55 checks passed
@mroeschke
Copy link
Member

Thanks @snitish

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
2 participants