From a5bab23aea84d9fa25a576cc0d33a9dff25b92b4 Mon Sep 17 00:00:00 2001 From: jrycw Date: Wed, 18 Sep 2024 07:04:11 +0800 Subject: [PATCH 1/2] Refactor import statements in `_formats.py` --- great_tables/_formats.py | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/great_tables/_formats.py b/great_tables/_formats.py index 68882e30e..3744bad50 100644 --- a/great_tables/_formats.py +++ b/great_tables/_formats.py @@ -1,6 +1,8 @@ from __future__ import annotations import math +import re +from dataclasses import dataclass from datetime import date, datetime, time from decimal import Decimal from pathlib import Path @@ -3476,9 +3478,6 @@ def fmt_image( return fmt(self, fns=formatter.to_html, columns=columns, rows=rows) -from dataclasses import dataclass - - @dataclass class FmtImage: dispatch_on: DataFrameLike | Agnostic = Agnostic() @@ -3492,8 +3491,6 @@ class FmtImage: SPAN_TEMPLATE: ClassVar = '{}' def to_html(self, val: Any): - from pathlib import Path - # TODO: are we assuming val is a string? (or coercing?) # otherwise... @@ -3561,8 +3558,6 @@ def _get_image_uri(cls, filename: str) -> str: @staticmethod def _get_mime_type(filename: str) -> str: - from pathlib import Path - # note that we strip off the leading "." suffix = Path(filename).suffix[1:] @@ -3969,8 +3964,6 @@ def _generate_data_vals( list[Any]: A list of data values. """ - import re - if is_series(data_vals): data_vals = to_list(data_vals) @@ -4063,8 +4056,6 @@ def _process_number_stream(data_vals: str) -> list[float]: list[float]: A list of numeric values. """ - import re - number_stream = re.sub(r"[;,]", " ", data_vals) number_stream = re.sub(r"\\[|\\]", " ", number_stream) number_stream = re.sub(r"^\\s+|\\s+$", "", number_stream) @@ -4075,9 +4066,6 @@ def _process_number_stream(data_vals: str) -> list[float]: return number_stream -import re - - def _process_time_stream(data_vals: str) -> list[float]: """ Process a string of time values and convert to a list of floats. From e91bbaa873450b256d51c74e4cb49642af8b46c9 Mon Sep 17 00:00:00 2001 From: jrycw Date: Wed, 18 Sep 2024 07:27:08 +0800 Subject: [PATCH 2/2] Add `Returns` section to the doc for `GT.fmt_image()` and `GT.fmt_nanoplot()` --- great_tables/_formats.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/great_tables/_formats.py b/great_tables/_formats.py index 3744bad50..317aaa029 100644 --- a/great_tables/_formats.py +++ b/great_tables/_formats.py @@ -3428,6 +3428,12 @@ def fmt_image( The option to always use Base64 encoding for image paths that are determined to be local. By default, this is `True`. + Returns + ------- + GT + The GT object is returned. This is the same object that the method is called on so that we + can facilitate method chaining. + Examples -------- Using a small portion of `metro` dataset, let's create a new table. We will only include a few @@ -3656,6 +3662,12 @@ def fmt_nanoplot( By using the [`nanoplot_options()`](`great_tables.nanoplot_options`) helper function here, you can alter the layout and styling of the nanoplots in the new column. + Returns + ------- + GT + The GT object is returned. This is the same object that the method is called on so that we + can facilitate method chaining. + Details ------- Nanoplots try to show individual data with reasonably good visibility. Interactivity is included