Skip to content

Commit

Permalink
replace matplotlib dependency with webcolors
Browse files Browse the repository at this point in the history
  • Loading branch information
alanderex authored and FlorianWilhelm committed Jun 18, 2024
1 parent 0e36d0f commit 42ebf85
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies = [
"gspread<6.0", # newer version breaks worksheet.spreadsheet
"gspread-dataframe",
"gspread-formatting",
"matplotlib",
"webcolors",
]
dynamic = ["version"]

Expand Down
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by hatch-pip-compile with Python 3.10
# This file is autogenerated by hatch-pip-compile with Python 3.12
#
# - coverage[toml]>=6.2
# - pytest
Expand All @@ -15,12 +15,12 @@
# - gspread<6.0
# - httpx
# - httpx-auth
# - matplotlib
# - pandas>=2
# - pydantic>=2.5
# - structlog
# - tomli
# - tqdm
# - webcolors
# - highspy
# - ipywidgets
# - pillow
Expand Down Expand Up @@ -220,7 +220,6 @@ markupsafe==2.1.3
# nbconvert
matplotlib==3.8.2
# via
# hatch.envs.default
# pyomo
# seaborn
matplotlib-inline==0.1.6
Expand Down
23 changes: 12 additions & 11 deletions src/pytanis/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
)
from gspread_formatting.dataframe import format_with_dataframe
from gspread_formatting.models import cellFormat
from matplotlib.colors import to_rgb
from structlog import get_logger
from webcolors import name_to_rgb

from pytanis.config import Config, get_cfg

Expand Down Expand Up @@ -118,7 +118,7 @@ def _wait_for_worksheet(self, spreadsheet_id: str, worksheet_name: str):
time.sleep(1)

def gsheet(
self, spreadsheet_id: str, worksheet_name: str | None = None, *, create_ws: bool = False
self, spreadsheet_id: str, worksheet_name: str | None = None, *, create_ws: bool = False
) -> Worksheet | Spreadsheet:
"""Retrieve a Google sheet by its id and the name
Expand Down Expand Up @@ -152,14 +152,14 @@ def _exception_feedback(self, error: APIError):
raise error

def save_df_as_gsheet(
self,
df: pd.DataFrame,
spreadsheet_id: str,
worksheet_name: str,
*,
create_ws: bool = False,
default_fmt: bool = True,
**kwargs: str | (bool | int),
self,
df: pd.DataFrame,
spreadsheet_id: str,
worksheet_name: str,
*,
create_ws: bool = False,
default_fmt: bool = True,
**kwargs: str | (bool | int),
):
"""Save the given dataframe as worksheet in a spreadsheet
Expand Down Expand Up @@ -242,6 +242,7 @@ def mark_rows(worksheet, mask: pd.Series, color: ColorType):
https://matplotlib.org/stable/gallery/color/named_colors.html#css-colors
"""
rows = gsheet_rows_for_fmt(mask, worksheet.col_count)
fmt = cellFormat(backgroundColor=Color(*to_rgb(color)))
color_rgb = name_to_rgb(color)if isinstance(color, str) else color[:3]
fmt = cellFormat(backgroundColor=Color(*color_rgb))
if rows:
format_cell_ranges(worksheet, [(rng, fmt) for rng in rows])

0 comments on commit 42ebf85

Please sign in to comment.