MCPcopy
hub / github.com/pandas-dev/pandas / _wrap_decimal_thousands

Function _wrap_decimal_thousands

pandas/io/formats/style_render.py:1910–1934  ·  view source on GitHub ↗

Takes a string formatting function and wraps logic to deal with thousands and decimal parameters, in the case that they are non-standard and that the input is a (float, complex, int).

(
    formatter: Callable, decimal: str, thousands: str | None
)

Source from the content-addressed store, hash-verified

1908
1909
1910def _wrap_decimal_thousands(
1911 formatter: Callable, decimal: str, thousands: str | None
1912) -> Callable:
1913 """
1914 Takes a string formatting function and wraps logic to deal with thousands and
1915 decimal parameters, in the case that they are non-standard and that the input
1916 is a (float, complex, int).
1917 """
1918
1919 def wrapper(x):
1920 if is_float(x) or is_integer(x) or is_complex(x):
1921 if decimal != "." and thousands is not None and thousands != ",":
1922 return (
1923 formatter(x)
1924 .replace(",", "§_§-") # rare string to avoid "," <-> "." clash.
1925 .replace(".", decimal)
1926 .replace("§_§-", thousands)
1927 )
1928 elif decimal != "." and (thousands is None or thousands == ","):
1929 return formatter(x).replace(".", decimal)
1930 elif decimal == "." and thousands is not None and thousands != ",":
1931 return formatter(x).replace(",", thousands)
1932 return formatter(x)
1933
1934 return wrapper
1935
1936
1937def _str_escape(x, escape):

Callers 1

_maybe_wrap_formatterFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected