-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
Custom column formatters for HTML in IPython, e.g. can show np 2D-array as image #9579
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fe05026
format.py - escape info column specific (optionally)
5d8de3d
frame.py - repr_html - read _formatters_html attr
15f7ca2
format.py - justify info column specific (optionally)
0238a95
format.py/frame.py - html formatters as arg
dfb0e40
frame.py - html formatters with multiindex columns
acdb295
bugfix/hack - use numpy's __str__ instead of custom formatter
20ce7ad
bugfix newline to comma
68d8544
Merge branch 'feature'
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1468,14 +1468,38 @@ def to_html(self, buf=None, columns=None, col_space=None, colSpace=None, | |
max_cols : int, optional | ||
Maximum number of columns to show before truncating. If None, show | ||
all. | ||
|
||
formatters : callabable or dict/list/tuple of callables, optional | ||
The keys to the dict are the column names, any missing or additional | ||
names will be given defaults or ignored respectively. If list/tuple | ||
the length should match the columns exactly. | ||
Each callable can have an optional boolean `escape` attribute, | ||
and an optional string `justify` attribute. See `_make_fixed_width` | ||
function in `format.py` for meaning of `justify`. If `escape` is | ||
not provided the primary `escape` argument is used (see above). | ||
""" | ||
|
||
if colSpace is not None: # pragma: no cover | ||
warnings.warn("colSpace is deprecated, use col_space", | ||
FutureWarning, stacklevel=2) | ||
col_space = colSpace | ||
|
||
# convert dict/single callable to list | ||
if isinstance(formatters,dict): | ||
formatters_list = [] | ||
for cname in self.columns: | ||
if cname in formatters: | ||
formatters_list.append(formatters[cname]) | ||
elif isinstance(cname,tuple): | ||
# look through all the names in tuple and take the first | ||
# matching name form the supplied formatters | ||
formatters_list.append(next((formatters[n] for n in cname\ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need the backslash here inside parentheses. |
||
if n in formatters),None)) | ||
else: | ||
formatters_list.append(None) | ||
formatters = tuple(formatters_list) | ||
elif callable(formatters): | ||
formatters = (formatters,)*len(self.columns) | ||
|
||
formatter = fmt.DataFrameFormatter(self, buf=buf, columns=columns, | ||
col_space=col_space, na_rep=na_rep, | ||
formatters=formatters, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could you please give a brief description instead of referring to the source code? Also -- maybe add an example to the HTML a export docs? http://pandas-docs.github.io/pandas-docs-travis/io.html#io-html