Skip to content

Commit

Permalink
fix #108
Browse files Browse the repository at this point in the history
  • Loading branch information
PaleNeutron committed Dec 2, 2023
1 parent cad3efa commit ecf6392
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion dataframe_image/_pandas_accessor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import io
from pathlib import Path
from typing import Literal

Expand Down Expand Up @@ -82,7 +83,11 @@ def export(
from .converter.matplotlib_table import MatplotlibTableConverter

# get extension from filename without dot
extension = Path(filename).suffix
if isinstance(filename, io.IOBase):
extension = "png"
else:
extension = Path(filename).suffix

if extension.startswith("."):
extension = extension[1:]
converter = MatplotlibTableConverter(
Expand Down
18 changes: 18 additions & 0 deletions tests/test_df_image.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from io import BytesIO
import random
import string

Expand Down Expand Up @@ -34,6 +35,18 @@ def test_styled(document_name, converter, dpi):
dpi=dpi,
)

@pytest.mark.parametrize("converter", converters)
def test_styled2(document_name, converter):
col_headers = {
"selector": ".col_heading, thead",
"props": "color: white; background-color: #1d5632; font-size: 11px"
}

df = pd.DataFrame(np.random.rand(6, 4))
df_styled = df.style.set_table_styles([col_headers])
dfi.export(df_styled, f"tests/test_output/{document_name}.png", table_conversion=converter)



@pytest.mark.parametrize("dpi", test_dpi_values)
@pytest.mark.parametrize("converter", converters)
Expand Down Expand Up @@ -81,3 +94,8 @@ def test_long_column_headers(document_name, converter, dpi):
dpi=dpi,
max_rows=-1,
)


def test_save_using_bytesio():
buf = BytesIO()
df.dfi.export(buf, table_conversion='matplotlib')

0 comments on commit ecf6392

Please sign in to comment.