Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pre-commit.ci] pre-commit autoupdate #138

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ repos:
name: isort (python)

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.7.0"
rev: "v0.8.1"
hooks:
- id: ruff
args: [--fix, --show-fixes]
Expand All @@ -41,12 +41,12 @@ repos:
- id: python-use-type-annotations

- repo: https://github.com/asottile/setup-cfg-fmt
rev: "v2.6.0"
rev: "v2.7.0"
hooks:
- id: setup-cfg-fmt

- repo: https://github.com/asottile/pyupgrade
rev: "v3.18.0"
rev: "v3.19.0"
hooks:
- id: pyupgrade
args: ["--py36-plus"]
Expand All @@ -59,7 +59,7 @@ repos:
additional_dependencies: [flake8-bugbear, flake8-print]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.11.2"
rev: "v1.13.0"
hooks:
- id: mypy
files: histoprint
Expand Down
4 changes: 2 additions & 2 deletions histoprint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from .version import version as __version__

__all__ = (
"print_hist",
"text_hist",
"HistFormatter",
"__version__",
"print_hist",
"text_hist",
)
18 changes: 8 additions & 10 deletions histoprint/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
DEFAULT_FG_COLORS = "WWWWW"
DEFAULT_BG_COLORS = "K0000"

__all__ = ["print_hist", "text_hist", "HistFormatter"]
__all__ = ["HistFormatter", "print_hist", "text_hist"]


class Hixel:
Expand Down Expand Up @@ -149,7 +149,7 @@ def ansi_color_string(self, fg, bg):
fg = subs[fg]
bg = subs[bg] + 10

ret += "\033[%d;%dm" % (fg, bg)
ret += f"\033[{fg:d};{bg:d}m"
return ret


Expand Down Expand Up @@ -197,7 +197,7 @@ def __init__(
self,
scale=1.0,
count_area=True,
tick_format="% #7.3f ",
tick_format="{: #7.3f} ",
tick_mark="_",
no_tick_mark=" ",
print_top_edge=False,
Expand All @@ -210,7 +210,7 @@ def __init__(
self.scale = scale
self.count_area = count_area
self.tick_format = tick_format
self.tick_format_width = len(tick_format % (0.0,))
self.tick_format_width = len(tick_format.format(0.0))
self.tick_mark = tick_mark
self.no_tick_mark = no_tick_mark
self.print_top_edge = print_top_edge
Expand Down Expand Up @@ -316,7 +316,7 @@ def format_bin(self, top, bottom, counts, width=1):

def tick(self, edge):
"""Format the tick mark of a bin."""
return self.tick_format % (edge,) + self.tick_mark
return self.tick_format.format(edge) + self.tick_mark

def no_tick(self):
"""Format the axis without a tick mark."""
Expand Down Expand Up @@ -457,7 +457,7 @@ def format_histogram(self, counts):

# Write the title line
if len(self.title):
hist_string += ("{: ^%ds}\n" % (self.columns,)).format(self.title)
hist_string += f"{self.title: ^{self.columns:d}s}\n"

# Get bin edges
top = np.array(self.edges[:-1])
Expand All @@ -469,16 +469,14 @@ def format_histogram(self, counts):

# Write the first tick, common exponent and horizontal axis
hist_string += self.bin_formatter.tick(top[0])
ce_string = " x 10^%+03d" % (common_exponent,) if common_exponent != 0 else ""
ce_string = f" x 10^{common_exponent:+03.0f}" if common_exponent != 0 else ""

hist_string += ce_string
if self.bin_formatter.count_area:
longest_count = f"{max_c:g}/row"
else:
longest_count = f"{max_c:g}"
hist_string += ("{:>%ds} \u2577\n" % (hist_width - len(ce_string) - 2,)).format(
longest_count
)
hist_string += f"{longest_count:>{hist_width - len(ce_string) - 2:d}s} \u2577\n"

# Write the bins
for c, t, b, w in zip(counts.T, top, bottom, self.bin_lines):
Expand Down
Loading