-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
implemented additionally functionality of formatters_col in to_latex #37552
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,7 +84,11 @@ | |
|
||
|
||
FormattersType = Union[ | ||
List[Callable], Tuple[Callable, ...], Mapping[Union[str, int], Callable] | ||
List[Callable], | ||
Tuple[Callable, ...], | ||
List[str], | ||
List[Union[Callable, str]], | ||
Mapping[Union[str, int], Callable], | ||
] | ||
ColspaceType = Mapping[Label, Union[str, int]] | ||
ColspaceArgType = Union[ | ||
|
@@ -106,7 +110,7 @@ | |
Whether to print index (row) labels. | ||
na_rep : str, optional, default 'NaN' | ||
String representation of ``NaN`` to use. | ||
formatters : list, tuple or dict of one-param. functions, optional | ||
formatters : list, tuple or dict of one-param. functions, str, optional | ||
Formatter functions to apply to columns' elements by position or | ||
name. | ||
The result of each function must be a unicode string. | ||
|
@@ -576,6 +580,24 @@ def _initialize_sparsify(self, sparsify: Optional[bool]) -> bool: | |
def _initialize_formatters( | ||
self, formatters: Optional[FormattersType] | ||
) -> FormattersType: | ||
if is_list_like(formatters) and not isinstance(formatters, dict): | ||
formatter_elems_type = all( | ||
isinstance(elem, str) or callable(elem) for elem in formatters | ||
Comment on lines
+583
to
+585
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. I believe the failures in tests occur because the logic added is not properly incorporated into the remaining items in this method. 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. Probably should look like this:
Also raising ValueError should be in agreement (probably need to update the error message on what formatter elements should look like). 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. With the ordering you proposed that second if statement would always be evaluated true and it wouldn't convert the fstrings to corresponding functions. I'm not too sure how to fix the error, been looking over it slowly past few days. I think mypy is treating the two-folded lambda function as a different type (Like |
||
) | ||
if formatter_elems_type: | ||
# two fold lambda is required to bypass lambda replication | ||
# issues in list comprehensions | ||
formatters = [ | ||
(lambda style: lambda x: "{0:{1}}".format(x, style))(style) | ||
if isinstance(style, str) | ||
else style | ||
for style in formatters | ||
] | ||
else: | ||
raise ValueError( | ||
"Formatters elements should be f-strings or callable functions" | ||
) | ||
|
||
if formatters is None: | ||
return {} | ||
elif len(self.frame.columns) == len(formatters) or isinstance(formatters, dict): | ||
|
Uh oh!
There was an error while loading. Please reload this page.