-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Conversation
pandas/io/formats/excel.py
Outdated
@@ -64,10 +64,11 @@ class CSSToExcelConverter: | |||
# without monkey-patching. | |||
|
|||
def __init__(self, inherited: Optional[str] = None): | |||
self.inherited: Optional[Dict[str, str]] |
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.
this goes outside of __init__
:
class Foo:
inherited : SomeType
def __init__(self, ...):
self.inherited = ...
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.
Changed as you suggested.
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.
some comments.
pandas/io/formats/css.py
Outdated
@@ -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 |
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.
you really need this assert?
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.
No, indeed, that one I forgot. Thank you.
pandas/io/formats/css.py
Outdated
# 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(): |
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.
don't copy in the interable, rather copy first and iterate over the original.
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.
Changed it. But, out of curiosity, why would it matter?
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.
doesn't matter, just style-wise its easier to read, e.g. less things then going on in the iteration part
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.
nice!
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
Refactor
__call__
method ofCSSResolver
.