-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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: Display precision doesn't affect complex float numbers #25514 #25745
Conversation
Codecov Report
@@ Coverage Diff @@
## master #25745 +/- ##
==========================================
- Coverage 91.25% 91.25% -0.01%
==========================================
Files 172 172
Lines 52977 52979 +2
==========================================
+ Hits 48343 48344 +1
- Misses 4634 4635 +1
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #25745 +/- ##
==========================================
- Coverage 91.9% 91.89% -0.02%
==========================================
Files 175 175
Lines 52485 52501 +16
==========================================
+ Hits 48235 48244 +9
- Misses 4250 4257 +7
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a whatsnew for v0.25?
does this also change the notebook display? if so can we have a test for to_html() with notebook =True and False. |
@@ -1417,6 +1417,18 @@ def test_to_string_float_index(self): | |||
'5.0 4') | |||
assert result == expected | |||
|
|||
def test_to_string_complex_float_formatting(self): | |||
fmt.set_option('display.precision', 5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to use the context manger here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you use the context manager here
can you merge master and see if you can update |
Done. |
pandas/core/frame.py
Outdated
2 1 1.0 (1+0j) 1 True | ||
3 1 1.0 (1+0j) 1 True | ||
4 1 1.0 (1+0j) 1 True | ||
int64 float64 complex128 object bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there an extra space here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Good catch! Thanks.
@@ -1094,7 +1097,10 @@ def format_values_with(float_format): | |||
for val in values.ravel()[imask]]) | |||
|
|||
if self.fixed_width: | |||
return _trim_zeros(values, na_rep) | |||
if is_complex: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can do the type check right here instead of above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with that is at that point the values
object has been reassigned as values = np.array(values, dtype='object')
and is no longer a complex type but an array with the complex numbers (or floats) as strings.
@@ -1417,6 +1417,18 @@ def test_to_string_float_index(self): | |||
'5.0 4') | |||
assert result == expected | |||
|
|||
def test_to_string_complex_float_formatting(self): | |||
fmt.set_option('display.precision', 5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you use the context manager here
(0.2739442392974528 + 0.23515228785438969j), | ||
(0.26974928742135185 + 0.3250604054898979j)]}) | ||
result = df.to_string() | ||
expected = (' x\n0 0.44678+0.07152j\n' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do these have an extra space?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is how it would display normally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor change. ping on green.
@@ -1370,6 +1370,18 @@ def test_to_string_float_index(self): | |||
'5.0 4') | |||
assert result == expected | |||
|
|||
def test_to_string_complex_float_formatting(self): | |||
with pd.option_context('display.precision', 5): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add the gh issue number as a comment
thanks @sakarpanta |
git diff upstream/master -u -- "*.py" | flake8 --diff