Skip to content

CLN: Styler Types for CSS variables on ctx object. #39660

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

Merged
merged 22 commits into from
Feb 19, 2021

Conversation

attack68
Copy link
Contributor

@attack68 attack68 commented Feb 7, 2021

  • tests changed / passed
  • Ensure all linting tests pass, see here for how to run them

Styler currently has three formats for keeping track of CSS:

A) CSSList type: [('a1', 'v1'), ('a2', 'v2')]
B) List[str] type: ['a1:v1', 'a2:v2']
C) Str type: 'a1:v1; a2:v2;'

C is only ever used as user input format, and now, as of #39564 C can be used in all cases for user input (albeit A remains available for backwards compatibility in .set_table_styles())

A remains the most algorithimcally accessible, and is what C is already converted to in some cases for internal variables.

B is only ever used by one internal variable. The ctx object is updated with B type converted from C. For final render this B type is converted to A type for looping. In the process, white space is poorly handled.

This PR eliminates B type and converts C directly to A.

Tests using the ctx object needed updating for new type.

@attack68 attack68 marked this pull request as draft February 7, 2021 23:17
@attack68 attack68 added Clean Typing type annotations, mypy/pyright type checking Styler conditional formatting using DataFrame.style labels Feb 8, 2021
@jreback
Copy link
Contributor

jreback commented Feb 11, 2021

looks reasonable. is there any user facing change here?

@attack68 attack68 marked this pull request as ready for review February 15, 2021 06:31
@attack68
Copy link
Contributor Author

@jreback shouldn't have any user facing changes. ctx is internal variable, never referenced in docs - no one should be accessing it directly.

A quick question if you have time: what is the style guideline for private and public class attributes? There are a few in Styler that really are private mechanics only but no leading underscore in the name?

@jreback
Copy link
Contributor

jreback commented Feb 15, 2021

@jreback shouldn't have any user facing changes. ctx is internal variable, never referenced in docs - no one should be accessing it directly.

A quick question if you have time: what is the style guideline for private and public class attributes? There are a few in Styler that really are private mechanics only but no leading underscore in the name?

the entire module should be private as pandas.core is indicated as private. Generally leading underscores are useful to indicate that this function is not used outside of the module. But wouldn't simply change things as that causes huge diffs for no reason.

@attack68
Copy link
Contributor Author

looks reasonable. is there any user facing change here?

ah I just thought of a change (demonstrated by the what_new_0.20.0 file). If the user has code which generated bad-css that was previously silently ignored, it will now raise an error. maybe we need a call on whether raising or silently ignoring is better??

@jreback jreback added this to the 1.3 milestone Feb 17, 2021
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

assume no changes in performance? (I think we have a couple of benchmarks)

@attack68
Copy link
Contributor Author

[ 58.33%] ··· io.style.RenderApply.peakmem_apply                                                                                                                              ok
[ 58.33%] ··· ====== ======= =======
              --           rows     
              ------ ---------------
               cols     12     120  
              ====== ======= =======
                12    77.9M   77.7M 
                24    77.7M   77.7M 
                36    77.9M   77.7M 
              ====== ======= =======

[ 66.67%] ··· io.style.RenderApply.peakmem_render                                                                                                                             ok
[ 66.67%] ··· ====== ======= =======
              --           rows     
              ------ ---------------
               cols     12     120  
              ====== ======= =======
                12     78M    79.4M 
                24    77.9M   80.1M 
                36    78.3M   82.2M 
              ====== ======= =======

[ 75.00%] ··· io.style.RenderApply.time_render                                                                                                                                ok
[ 75.00%] ··· ====== ============ ==========
              --               rows         
              ------ -----------------------
               cols       12         120    
              ====== ============ ==========
                12    12.0±0.1ms   86.7±1ms 
                24    31.2±0.4ms   159±3ms  
                36    46.7±0.3ms   237±3ms  
              ====== ============ ==========

[ 75.00%] · For pandas commit 407e67c1 (round 2/2):
[ 75.00%] ·· Building for virtualenv-py3.8-Cython0.29.21-jinja2-matplotlib-numba-numexpr-numpy-odfpy-openpyxl-pytest-scipy-sqlalchemy-tables-xlrd-xlsxwriter-xlwt...
[ 75.00%] ·· Benchmarking virtualenv-py3.8-Cython0.29.21-jinja2-matplotlib-numba-numexpr-numpy-odfpy-openpyxl-pytest-scipy-sqlalchemy-tables-xlrd-xlsxwriter-xlwt
[ 83.33%] ··· io.style.RenderApply.peakmem_apply                                                                                                                              ok
[ 83.33%] ··· ====== ======= =======
              --           rows     
              ------ ---------------
               cols     12     120  
              ====== ======= =======
                12    77.9M   77.8M 
                24    77.6M   77.8M 
                36    77.9M   77.6M 
              ====== ======= =======

[ 91.67%] ··· io.style.RenderApply.peakmem_render                                                                                                                             ok
[ 91.67%] ··· ====== ======= =======
              --           rows     
              ------ ---------------
               cols     12     120  
              ====== ======= =======
                12     78M    78.8M 
                24    78.1M   80.8M 
                36    78.2M   82.3M 
              ====== ======= =======

[100.00%] ··· io.style.RenderApply.time_render                                                                                                                                ok
[100.00%] ··· ====== ============ ==========
              --               rows         
              ------ -----------------------
               cols       12         120    
              ====== ============ ==========
                12    12.8±0.8ms   88.0±2ms 
                24    50.4±10ms    161±3ms  
                36     46.4±1ms    240±8ms  
              ====== ============ ==========

BENCHMARKS NOT SIGNIFICANTLY CHANGED.

@attack68 attack68 requested a review from jreback February 17, 2021 07:47
@jreback jreback merged commit aa58447 into pandas-dev:master Feb 19, 2021
@jreback
Copy link
Contributor

jreback commented Feb 19, 2021

thanks @attack68

@attack68 attack68 deleted the ctx_clean branch February 19, 2021 06:12
@rhshadrach rhshadrach mentioned this pull request Jun 5, 2021
1 task
@MrLotU
Copy link

MrLotU commented Jul 7, 2021

Hi, when styling Excel sheets (using xlsxwriter), number formats can be passed in to stylers using the number-format CSS attribute, that's than picked up by the Excel engine to apply.

It's common for these formats to include one, or multiple, semicolons since this is how Excel defines styles for positive/negative numbers (ie. number-format: 0_);[Red](0)). In pandas 1.2.x the previous example worked fine, however it seems to have broken in 1.3.x. Looking through the changelog I have found this PR and it seems one of the changes made here has caused this, though unsure what exactly. Any pointers would be greatly appreciated.

For now my processes will be pinned on pandas 1.2.x, but would love to look into how this could be fixed. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean Styler conditional formatting using DataFrame.style Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants