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

ENH: Make print_thing respect display.precision for Real numbers #60613

Closed

Conversation

aydinomer00
Copy link

  • closes ENH: How about let pprint_thing print Real instance according to display.precision #60503

  • Tests added and passed:

    • Added test_pprint_thing_real_precision to test precision formatting
    • Verified with multiple display.precision values (2, 3, 4)
    • Tested with various float numbers including np.pi
  • All code checks passed

  • Added type annotations for clarity in modified functions

  • Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file:
    - Enhanced print_thing to respect display.precision setting for Real numbers

This PR modifies the print_thing function to respect display.precision settings when formatting Real numbers. For example:

with pd.option_context('display.precision', 2):
    df = pd.DataFrame({"value": [np.pi]})
    print(df)  # Shows 3.14

with pd.option_context('display.precision', 4):
    print(df)  # Shows 3.1416

Copy link
Member

@rhshadrach rhshadrach 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!

escape_chars = list(escape_chars.keys())
else:
escape_chars = escape_chars or ()

result = str(thing)
# Real instance kontrolü ve precision uygulaması
if isinstance(thing, Real) and not isinstance(thing, int):
Copy link
Member

Choose a reason for hiding this comment

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

Can you use is_float from padnas.core.dtypes.inference

escape_chars = list(escape_chars.keys())
else:
escape_chars = escape_chars or ()

result = str(thing)
# Real instance kontrolü ve precision uygulaması
Copy link
Member

Choose a reason for hiding this comment

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

This comment repeats the code verbatim and can be removed. Also, can you make any comments in English.

import pytest

from pandas._config.config import option_context # option_context
Copy link
Member

Choose a reason for hiding this comment

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

Can you remove the comment

@@ -155,6 +158,13 @@ def test_east_asian_len(self):
assert adj.len("パンダpanda") == 11
assert adj.len("パンダpanda") == 10

def test_pprint_thing_real_precision(self):
Copy link
Member

Choose a reason for hiding this comment

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

Can you move to TestPPrintThing above

@@ -155,6 +158,13 @@ def test_east_asian_len(self):
assert adj.len("パンダpanda") == 11
assert adj.len("パンダpanda") == 10

def test_pprint_thing_real_precision(self):
with option_context('display.precision', 3):
assert pprint_thing(3.14159265359) == "3.142"
Copy link
Member

Choose a reason for hiding this comment

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

Use printing.pprint_thing instead, as the other tests here do

@rhshadrach rhshadrach added Output-Formatting __repr__ of pandas objects, to_string Enhancement labels Dec 30, 2024
- Replace isinstance(thing, Real) with is_float
- Remove Turkish comments and unnecessary inline comments
- Move test_pprint_thing_real_precision to TestPPrintThing class
- Use consistent printing.pprint_thing import style
- Remove Real numbers reference from docstring
- Remove Turkish comments
- Fix import structure in tests
@rhshadrach
Copy link
Member

@aydinomer00 - looks like the CI is failing. Let me know if you'd like assistance.

Copy link
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Feb 11, 2025
@rhshadrach
Copy link
Member

Closing as stale. @aydinomer00 - if you'd like to continue, merge main and address the comments above, and we'd be more than happy to reopen!

@rhshadrach rhshadrach closed this Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Output-Formatting __repr__ of pandas objects, to_string Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: How about let pprint_thing print Real instance according to display.precision
2 participants