Skip to content

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

Conversation

simonjayhawkins
Copy link
Member

@simonjayhawkins simonjayhawkins commented Apr 5, 2019

resubmit of #25983

@simonjayhawkins
Copy link
Member Author

considering #24134 (comment) , this PR may need to revert some of #24134 which i think caused the regression in #25984

@jreback jreback added IO HTML read_html, to_html, Styler.apply, Styler.applymap Output-Formatting __repr__ of pandas objects, to_string labels Apr 5, 2019
@simonjayhawkins
Copy link
Member Author

i'm going to close this for now, since while the implementation of ExtensionArrayFormatter relies on formatting options AND a formatters parameter, it is not possible to add the shortcut for custom formatters. Changing this is outside the scope of this PR so i'll circle back to this once that's resolved.

@simonjayhawkins
Copy link
Member Author

@jreback ; gone with bypassing format_array altogether when formatters are passed . it's a bit hacky, but on the bright side it closes the original issue, gets round the leading space bug #26002 and gets an additional test in play.

@simonjayhawkins simonjayhawkins marked this pull request as ready for review April 5, 2019 22:45
@codecov
Copy link

codecov bot commented Apr 5, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@77e6556). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #26000   +/-   ##
=========================================
  Coverage          ?   91.86%           
=========================================
  Files             ?      180           
  Lines             ?    50717           
  Branches          ?        0           
=========================================
  Hits              ?    46592           
  Misses            ?     4125           
  Partials          ?        0
Flag Coverage Δ
#multiple 90.46% <100%> (?)
#single 41.1% <50%> (?)
Impacted Files Coverage Δ
pandas/io/formats/format.py 98.02% <100%> (ø)
pandas/core/arrays/integer.py 96.3% <100%> (ø)
pandas/core/arrays/interval.py 93.1% <100%> (ø)
pandas/core/arrays/categorical.py 95.92% <100%> (ø)
pandas/core/indexes/base.py 96.71% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 77e6556...5ecf91a. Read the comment docs.

@codecov
Copy link

codecov bot commented Apr 5, 2019

Codecov Report

Merging #26000 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #26000      +/-   ##
==========================================
- Coverage   91.82%   91.82%   -0.01%     
==========================================
  Files         175      175              
  Lines       52551    52555       +4     
==========================================
+ Hits        48256    48257       +1     
- Misses       4295     4298       +3
Flag Coverage Δ
#multiple 90.38% <100%> (ø) ⬆️
#single 40.74% <50%> (-0.12%) ⬇️
Impacted Files Coverage Δ
pandas/io/formats/format.py 97.9% <100%> (ø) ⬆️
pandas/io/gbq.py 75% <0%> (-12.5%) ⬇️
pandas/core/frame.py 96.79% <0%> (-0.12%) ⬇️
pandas/util/testing.py 90.72% <0%> (+0.1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 181f972...9c1354c. Read the comment docs.


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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need shortcut at all? isn't self.formatter is not None enough?

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather do that, this is too hacky

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing the ExtensionArrayFormatter is unlikely to be trivial.

@@ -938,6 +938,10 @@ def get_result(self):
return _make_fixed_width(fmt_values, self.justify)

def _format_strings(self):
# shortcut
Copy link
Contributor

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

@jreback
Copy link
Contributor

jreback commented Jun 8, 2019

@simonjayhawkins can you merge master, what's the status?

@simonjayhawkins
Copy link
Member Author

@simonjayhawkins can you merge master, what's the status?

changing ExtensionArrayFormatter is necessary but outside the scope of this PR.

did make a change here in this PR and ci passing. I think that is more an indication of missing tests than a solution.

will do a precursor PR instead. I'm not really happy with the implementation of ExtensionArrayFormatter but don't know why it was done this way. There presumably needs to a mechanism for 3rd party creators of EA types to display a repr. not sure if this was the reason and that is the solution though.

@simonjayhawkins
Copy link
Member Author

while the implementation of ExtensionArrayFormatter relies on formatting options AND a formatters parameter, it is not possible to add the shortcut for custom formatters.

changed formatters to be a pre-formatter instead of a shortcut so this is no longer an issue. @jorisvandenbossche

@simonjayhawkins
Copy link
Member Author

latest commit also closes #26002 (again), two spaces between columns now as for other DataFrame columns

@jreback
Copy link
Contributor

jreback commented Jun 19, 2019

lgtm. @jorisvandenbossche @TomAugspurger if you want to have a look.

@jreback
Copy link
Contributor

jreback commented Jun 21, 2019

@simonjayhawkins is this orthogonal to your formatters refactor?

@simonjayhawkins
Copy link
Member Author

@jreback

The two PRs are addressing orthogonal issues, but the implementations are not 100% orthogonal.

The other PR is a more important issue. This PR addresses a case which is probably rarely encountered by users.

This should probably be put on hold while the Extension Array formatting is discussed, since this PR does change some Extension Array formatting code.

I could probably pull out a couple of these changes into a separate PR. Changing the formatter parameter to format_array to be optional is probably not contentious and adding a test for na_rep of IntegarNA would be a good thing.

@jreback jreback removed this from the 0.25.0 milestone Jun 28, 2019
@TomAugspurger
Copy link
Contributor

TomAugspurger commented Jul 2, 2019

@simonjayhawkins there's a merge conflict.

Is this ready for 0.25? Haven't had time to look at the change, but I'm happy to trust others if the tests are passing.

@simonjayhawkins
Copy link
Member Author

Is this ready for 0.25?

i don't believe it is wise to merge this at this time, so closing for now and will revisit at a later date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO HTML read_html, to_html, Styler.apply, Styler.applymap Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging this pull request may close these issues.

to_html formatter not called for float values in a mixed-type column
3 participants