-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
to_html formatter not called for float values in a mixed-type column (2) #26000
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
Changes from 10 commits
71e8b31
2a2bb57
1e5615b
4ca48a1
4ef3149
d7a8510
4b60e4b
5ac441b
8a64459
9c1354c
d0df1d6
c74b0aa
4262113
f0cf9b7
d6bee41
1c535a1
5ecf91a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -717,9 +717,11 @@ def _format_col(self, i): | |
frame = self.tr_frame | ||
formatter = self._get_formatter(i) | ||
values_to_format = frame.iloc[:, i]._formatting_values() | ||
shortcut = formatter is not None | ||
return format_array(values_to_format, formatter, | ||
float_format=self.float_format, na_rep=self.na_rep, | ||
space=self.col_space, decimal=self.decimal) | ||
space=self.col_space, decimal=self.decimal, | ||
shortcut=shortcut) | ||
|
||
def to_html(self, classes=None, notebook=False, border=None): | ||
""" | ||
|
@@ -856,7 +858,7 @@ def _get_column_name_list(self): | |
|
||
def format_array(values, formatter, float_format=None, na_rep='NaN', | ||
digits=None, space=None, justify='right', decimal='.', | ||
leading_space=None): | ||
leading_space=None, shortcut=False): | ||
""" | ||
Format an array for printing. | ||
|
||
|
@@ -878,6 +880,9 @@ def format_array(values, formatter, float_format=None, na_rep='NaN', | |
When formatting an Index subclass | ||
(e.g. IntervalIndex._format_native_types), we don't want the | ||
leading space since it should be left-aligned. | ||
shortcut : bool, optional, default False | ||
Whether to shortcut the formatting options. Used when specifying | ||
custom formatters in to_string, to_latex and to_html | ||
|
||
Returns | ||
------- | ||
|
@@ -911,7 +916,7 @@ def format_array(values, formatter, float_format=None, na_rep='NaN', | |
fmt_obj = fmt_klass(values, digits=digits, na_rep=na_rep, | ||
float_format=float_format, formatter=formatter, | ||
space=space, justify=justify, decimal=decimal, | ||
leading_space=leading_space) | ||
leading_space=leading_space, shortcut=shortcut) | ||
|
||
return fmt_obj.get_result() | ||
|
||
|
@@ -920,7 +925,8 @@ class GenericArrayFormatter(object): | |
|
||
def __init__(self, values, digits=7, formatter=None, na_rep='NaN', | ||
space=12, float_format=None, justify='right', decimal='.', | ||
quoting=None, fixed_width=True, leading_space=None): | ||
quoting=None, fixed_width=True, leading_space=None, | ||
shortcut=False): | ||
self.values = values | ||
self.digits = digits | ||
self.na_rep = na_rep | ||
|
@@ -932,12 +938,17 @@ def __init__(self, values, digits=7, formatter=None, na_rep='NaN', | |
self.quoting = quoting | ||
self.fixed_width = fixed_width | ||
self.leading_space = leading_space | ||
self.shortcut = shortcut | ||
|
||
def get_result(self): | ||
fmt_values = self._format_strings() | ||
return _make_fixed_width(fmt_values, self.justify) | ||
|
||
def _format_strings(self): | ||
# shortcut | ||
if self.formatter is not None and self.shortcut: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do you need shortcut at all? isn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the implementation of ExtensionArrayFormatter relies a formatter parameter and not shortcutting. so yes we need a shortcut parameter from to_string etc unless the ExtensionArrayFormatter implementation is changed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would rather do that, this is too hacky There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changing the ExtensionArrayFormatter is unlikely to be trivial. |
||
return [self.formatter(x) for x in self.values] | ||
|
||
if self.float_format is None: | ||
float_format = get_option("display.float_format") | ||
if float_format is None: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<table border="1" class="dataframe"> | ||
<thead> | ||
<tr style="text-align: right;"> | ||
<th></th> | ||
<th>x</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<th>0</th> | ||
<td>a</td> | ||
</tr> | ||
<tr> | ||
<th>1</th> | ||
<td>$0</td> | ||
</tr> | ||
<tr> | ||
<th>2</th> | ||
<td>$10</td> | ||
</tr> | ||
<tr> | ||
<th>3</th> | ||
<td>$3</td> | ||
</tr> | ||
</tbody> | ||
</table> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you give some more explanation here