From ccdb97e3ed112cdcbe1dceb3e9b8d2594e41e4f0 Mon Sep 17 00:00:00 2001 From: MeeseeksMachine <39504233+meeseeksmachine@users.noreply.github.com> Date: Tue, 29 Mar 2022 13:27:21 +0200 Subject: [PATCH] Backport PR #46119: REF: isinstance(x, int) -> is_integer(x) (#46501) Co-authored-by: JHM Darbyshire <24256554+attack68@users.noreply.github.com> Co-authored-by: Simon Hawkins --- pandas/io/formats/style_render.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pandas/io/formats/style_render.py b/pandas/io/formats/style_render.py index 2e9a62a54cd44..34d047eb59be6 100644 --- a/pandas/io/formats/style_render.py +++ b/pandas/io/formats/style_render.py @@ -25,6 +25,11 @@ from pandas._typing import Level from pandas.compat._optional import import_optional_dependency +from pandas.core.dtypes.common import ( + is_complex, + is_float, + is_integer, +) from pandas.core.dtypes.generic import ABCSeries from pandas import ( @@ -1431,9 +1436,9 @@ def _default_formatter(x: Any, precision: int, thousands: bool = False) -> Any: value : Any Matches input type, or string if input is float or complex or int with sep. """ - if isinstance(x, (float, complex)): + if is_float(x) or is_complex(x): return f"{x:,.{precision}f}" if thousands else f"{x:.{precision}f}" - elif isinstance(x, int): + elif is_integer(x): return f"{x:,.0f}" if thousands else f"{x:.0f}" return x @@ -1448,7 +1453,7 @@ def _wrap_decimal_thousands( """ def wrapper(x): - if isinstance(x, (float, complex, int)): + if is_float(x) or is_integer(x) or is_complex(x): if decimal != "." and thousands is not None and thousands != ",": return ( formatter(x)