Skip to content

Commit

Permalink
Merge pull request #450 from jrycw/organize-imports
Browse files Browse the repository at this point in the history
Refactor import statements in `_formats.py`
  • Loading branch information
rich-iannone authored Sep 18, 2024
2 parents 0af5fe4 + e91bbaa commit 079dc83
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions great_tables/_formats.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -3426,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
Expand Down Expand Up @@ -3476,9 +3484,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()
Expand All @@ -3492,8 +3497,6 @@ class FmtImage:
SPAN_TEMPLATE: ClassVar = '<span style="white-space:nowrap;">{}</span>'

def to_html(self, val: Any):
from pathlib import Path

# TODO: are we assuming val is a string? (or coercing?)

# otherwise...
Expand Down Expand Up @@ -3561,8 +3564,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:]

Expand Down Expand Up @@ -3661,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
Expand Down Expand Up @@ -3969,8 +3976,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)

Expand Down Expand Up @@ -4063,8 +4068,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)
Expand All @@ -4075,9 +4078,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.
Expand Down

0 comments on commit 079dc83

Please sign in to comment.