Skip to content

Commit 5d75d81

Browse files
committed
ENH: Make print_thing respect display.precision for Real numbers
1 parent 59b3a1a commit 5d75d81

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

pandas/io/formats/printing.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121

2222
from pandas._config import get_option
2323

24+
from numbers import Real # Real
25+
from pandas._config import get_option # display.precision
26+
2427
from pandas.core.dtypes.inference import is_sequence
2528

2629
from pandas.io.formats.console import get_console_size
@@ -168,7 +171,6 @@ def _pprint_dict(
168171
else:
169172
return fmt.format(things=", ".join(pairs))
170173

171-
172174
def pprint_thing(
173175
thing: object,
174176
_nest_lvl: int = 0,
@@ -201,19 +203,25 @@ def pprint_thing(
201203
"""
202204

203205
def as_escaped_string(
204-
thing: Any, escape_chars: EscapeChars | None = escape_chars
206+
thing: Any, escape_chars: EscapeChars | None = escape_chars
205207
) -> str:
206208
translate = {"\t": r"\t", "\n": r"\n", "\r": r"\r", "'": r"\'"}
207209
if isinstance(escape_chars, Mapping):
208210
if default_escapes:
209211
translate.update(escape_chars)
210212
else:
211-
translate = escape_chars # type: ignore[assignment]
213+
translate = escape_chars
212214
escape_chars = list(escape_chars.keys())
213215
else:
214216
escape_chars = escape_chars or ()
215217

216-
result = str(thing)
218+
# Real instance kontrolü ve precision uygulaması
219+
if isinstance(thing, Real) and not isinstance(thing, int):
220+
precision = get_option("display.precision")
221+
result = f"{thing:.{precision}f}"
222+
else:
223+
result = str(thing)
224+
217225
for c in escape_chars:
218226
result = result.replace(c, translate[c])
219227
return result

0 commit comments

Comments
 (0)