From d53458d10489c70e4d956e863d150d5b5a38e88f Mon Sep 17 00:00:00 2001 From: Mark McMahon Date: Mon, 28 Aug 2023 12:14:35 +0200 Subject: [PATCH] Pdf --- src/mridle/extras/datasets/pandas_styler.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/mridle/extras/datasets/pandas_styler.py b/src/mridle/extras/datasets/pandas_styler.py index dfd60a86..27072dc4 100644 --- a/src/mridle/extras/datasets/pandas_styler.py +++ b/src/mridle/extras/datasets/pandas_styler.py @@ -10,17 +10,16 @@ import fsspec import numpy as np -import matplotlib.pyplot as plt from typing import Any, Dict class PandasStylerHtml(AbstractVersionedDataSet): def __init__(self, filepath: str, version: Version = None): - """Creates a new instance of ImageDataSet to load / save image data for given filepath. + """Creates a new instance to load / save image data for given filepath. Args: - filepath: The location of the image file to load / save data. + filepath: The location of the table file to load / save data. """ # parse the path and protocol (e.g. file, http, s3, etc.) protocol, path = get_protocol_and_path(filepath) @@ -35,22 +34,16 @@ def __init__(self, filepath: str, version: Version = None): ) def _load(self) -> np.ndarray: - raise DataSetError("`load` is not supported on AltairDataSet") + raise DataSetError("`load` is not supported on PandasStylerHtml") def _save(self, data) -> None: - """Saves a plotly figure as html to the specified filepath.""" + """Saves a pandas table as html to the specified filepath.""" # using get_filepath_str ensures that the protocol and path are appended correctly for different filesystems save_path = get_filepath_str(self._get_save_path(), self._protocol) df = data.data # Extract the DataFrame from the styler - # df_html = df.to_html(index=False) # Convert DataFrame to HTML - # with open(save_path, "w") as f: - # f.write(df_html) - - df = data.data # Extract the DataFrame from the styler - plt.figure(figsize=(10, 6)) - plt.axis('off') - plt.table(cellText=df.values, colLabels=df.columns, cellLoc='center', loc='center') - plt.savefig(save_path, bbox_inches='tight') + df_html = df.to_html() # Convert DataFrame to HTML + with open(save_path, "w") as f: + f.write(df_html) def _describe(self) -> Dict[str, Any]: """Returns a dict that describes the attributes of the dataset."""