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 floats with exponents #60405

Closed
wants to merge 10 commits into from

Conversation

snitish
Copy link
Contributor

@snitish snitish commented Nov 23, 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 snitish changed the title Fix formatting of complex floats with exponents BUG: Fix formatting of complex floats with exponents Nov 23, 2024
Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Could you also add a whatsnew note in v3.0.0.rst?

@@ -422,6 +422,23 @@ def test_to_string_complex_float_formatting(self):
)
assert result == expected

# GH #60393
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make this a separate test?

@mroeschke mroeschke added the Output-Formatting __repr__ of pandas objects, to_string label Nov 25, 2024
@snitish snitish closed this Nov 25, 2024
@snitish
Copy link
Contributor Author

snitish commented Nov 25, 2024

Looks like I broke my branch. Will re-raise the PR.

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
5 participants