Skip to content

Commit

Permalink
Pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmahom5 committed Aug 28, 2023
1 parent 012a1ed commit d53458d
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/mridle/extras/datasets/pandas_styler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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."""
Expand Down

0 comments on commit d53458d

Please sign in to comment.