Skip to content
Snippets Groups Projects
Commit dde86e7b authored by Maxim Gonchar's avatar Maxim Gonchar
Browse files

feat: `ParametersStorage.to_table` setup truncation

parent 4fc03ce0
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,11 @@ import pandas as pd
pd.set_option('display.max_rows', None)
pd.set_option('display.max_colwidth', 100)
from shutil import get_terminal_size
def trunc(text: str, width: int) -> str:
return '\n'.join(line[:width] for line in text.split('\n'))
class ParametersStorage(NestedMKDict):
def to_dict(self, **kwargs) -> list:
return self.visit(ParametersVisitor(kwargs)).data
......@@ -39,11 +44,24 @@ class ParametersStorage(NestedMKDict):
df = self.to_df()
return df.to_string(**kwargs)
def to_table(self, *, df_kwargs: dict={}, **kwargs) -> str:
def to_table(
self,
*,
df_kwargs: dict={},
truncate: Union[int, bool] = False,
**kwargs
) -> str:
df = self.to_df(**df_kwargs)
kwargs.setdefault('headers', df.columns)
ret = tabulate(df, **kwargs)
if truncate:
if isinstance(truncate, bool):
truncate = get_terminal_size().columns
return trunc(ret, width=truncate)
return ret
def to_latex(self, *, return_df: bool=False, **kwargs) -> Union[str, Tuple[str, DataFrame]]:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment