diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index cea42cbffa906..570c9999843c8 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -654,6 +654,7 @@ I/O - :meth:`to_excel` and :meth:`to_markdown` support writing to fsspec URLs such as S3 and Google Cloud Storage (:issue:`33987`) - Bug in :meth:`read_fw` was not skipping blank lines (even with ``skip_blank_lines=True``) (:issue:`37758`) - :meth:`read_fwf` was inferring compression with ``compression=None`` which was not consistent with the other :meth:``read_*`` functions (:issue:`37909`) +- :meth:`DataFrame.to_html` was ignoring ``formatters`` argument for ``ExtensionDtype`` columns (:issue:`36525`) Period ^^^^^^ diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 8ede35912a492..082c539d034eb 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1537,7 +1537,9 @@ class ExtensionArrayFormatter(GenericArrayFormatter): def _format_strings(self) -> List[str]: values = extract_array(self.values, extract_numpy=True) - formatter = values._formatter(boxed=True) + formatter = self.formatter + if formatter is None: + formatter = values._formatter(boxed=True) if is_categorical_dtype(values.dtype): # Categorical is special for now, so that we can preserve tzinfo @@ -1553,7 +1555,9 @@ def _format_strings(self) -> List[str]: digits=self.digits, space=self.space, justify=self.justify, + decimal=self.decimal, leading_space=self.leading_space, + quoting=self.quoting, ) return fmt_values diff --git a/pandas/tests/io/formats/data/html/various_dtypes_formatted.html b/pandas/tests/io/formats/data/html/various_dtypes_formatted.html new file mode 100644 index 0000000000000..7d2ede3379213 --- /dev/null +++ b/pandas/tests/io/formats/data/html/various_dtypes_formatted.html @@ -0,0 +1,36 @@ +
+ | i | +f | +I | +s | +b | +c | +o | +
---|---|---|---|---|---|---|---|
0 | +formatted | +formatted | +formatted | +formatted | +formatted | +formatted | +formatted | +
1 | +formatted | +formatted | +formatted | +formatted | +formatted | +formatted | +formatted | +