Skip to content

REF: refactor/cleanup CSSResolver #36581

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 7 commits into from
Sep 24, 2020
Merged

Conversation

ivanovmg
Copy link
Member

  • closes #xxxx
  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

Refactor __call__ method of CSSResolver.

  • Extract methods
  • Reorder class attributes
  • Add type annotations

@@ -64,10 +64,11 @@ class CSSToExcelConverter:
# without monkey-patching.

def __init__(self, inherited: Optional[str] = None):
self.inherited: Optional[Dict[str, str]]
Copy link
Member

Choose a reason for hiding this comment

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

this goes outside of __init__:

class Foo:
    inherited : SomeType
    
    def __init__(self, ...):
         self.inherited = ...
      

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed as you suggested.

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.

some comments.

@@ -75,101 +130,79 @@ def __call__(self, declarations_str, inherited=None):
props = dict(self.atomize(self.parse(declarations_str)))
if inherited is None:
inherited = {}
assert inherited is not None
Copy link
Contributor

Choose a reason for hiding this comment

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

you really need this assert?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, indeed, that one I forgot. Thank you.

# 1. resolve inherited, initial
for prop, val in inherited.items():
if prop not in props:
props[prop] = val

for prop, val in list(props.items()):
for prop, val in props.copy().items():
Copy link
Contributor

Choose a reason for hiding this comment

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

don't copy in the interable, rather copy first and iterate over the original.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed it. But, out of curiosity, why would it matter?

Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't matter, just style-wise its easier to read, e.g. less things then going on in the iteration part

@jreback jreback added IO HTML read_html, to_html, Styler.apply, Styler.applymap Refactor Internal refactoring of code labels Sep 24, 2020
@jreback jreback added this to the 1.2 milestone Sep 24, 2020
@ivanovmg ivanovmg requested a review from jreback September 24, 2020 19:00
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.

nice!

@jreback jreback merged commit d65417c into pandas-dev:master Sep 24, 2020
@ivanovmg ivanovmg deleted the refactor/css branch October 4, 2020 13:24
kesmit13 pushed a commit to kesmit13/pandas that referenced this pull request Nov 2, 2020
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 Refactor Internal refactoring of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants