-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
CLN: Preliminary formatter refactor #20051
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
CLN: Preliminary formatter refactor #20051
Conversation
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.
looks good. just some very minor comments. want to do this refactor w/o really changing much code (as its more transparent that way). next pass will clean / fix more things.
pandas/io/formats/common.py
Outdated
|
||
def buffer_put_lines(buf, lines): | ||
""" | ||
Appends lines to a buffer |
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 use numpy doc string format here
pandas/io/formats/latex.py
Outdated
longtable : boolean, default False | ||
Use a longtable environment instead of tabular. | ||
|
||
See also |
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.
See Also
pandas/io/formats/html.py
Outdated
OrderedDict, unichr) | ||
from pandas.core.config import get_option | ||
from pandas.io.formats.printing import pprint_thing | ||
from pandas.io.formats.common import get_level_lengths, \ |
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.
use parens rather than line continuation \
pandas/io/formats/csv.py
Outdated
from pandas.core.indexes.datetimes import DatetimeIndex | ||
from pandas.core.indexes.period import PeriodIndex | ||
import numpy as np | ||
|
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.
put these import first (csv then numpy)
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.
Cool, just fixed these
Codecov Report
@@ Coverage Diff @@
## master #20051 +/- ##
==========================================
+ Coverage 91.72% 91.73% +<.01%
==========================================
Files 150 152 +2
Lines 49122 49180 +58
==========================================
+ Hits 45057 45114 +57
- Misses 4065 4066 +1
Continue to review full report at Codecov.
|
Hmm. Not sure why Travis failed and AppVeyor succeeded. |
you have a lint error
|
ok I fixed up the imports a bit to make them more idiomatic. I think its possible to completely remove pandas.io.formats.common and just move these 2 functions back to .formats. No real reason to have an extra file here. see if you can do that. |
thanks @shangyian will merge a bit later (after doc sprint) |
@jreback - cool. I also moved the two functions in io.formats.common to formats.format |
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.
great. there is also a _get_level_lengths
in style.py
, you might be able to combine these (can do here or next PR)
pandas/core/frame.py
Outdated
@@ -1841,7 +1842,7 @@ def info(self, verbose=None, buf=None, max_cols=None, memory_usage=None, | |||
- If False, never show counts. | |||
|
|||
""" | |||
from pandas.io.formats.format import _put_lines | |||
from pandas.io.formats.format import buffer_put_lines |
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 can reference this directly as fmt.buffer_put_lines
as fmt is already imported
pandas/core/frame.py
Outdated
@@ -1940,7 +1941,7 @@ def _sizeof_fmt(num, size_qualifier): | |||
mem_usage = self.memory_usage(index=True, deep=deep).sum() | |||
lines.append("memory usage: %s\n" % | |||
_sizeof_fmt(mem_usage, size_qualifier)) | |||
_put_lines(buf, lines) | |||
buffer_put_lines(buf, lines) |
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.
same
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.
Good point, changed those. I'll take a look at the two get_level_lengths
, but may not get around to fixing that today, so it's probably better as a new PR
can you rebase on master. ping on green. |
c9b4504
to
3783ccc
Compare
git diff upstream/master -u -- "*.py" | flake8 --diff
This PR splits the various formatters into different files so that it's easier to refactor a specific formatter.