Skip to content

Commit 800c2f2

Browse files
committed
Fix formatting with pre-commit hooks
1 parent 3049fe3 commit 800c2f2

File tree

4 files changed

+41
-26
lines changed

4 files changed

+41
-26
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ repos:
88
- repo: https://github.com/pre-commit/mirrors-mypy
99
rev: v1.7.1
1010
hooks:
11-
- id: mypy
12-
additional_dependencies: [types-all]
11+
- id: mypy

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
requires = ["hatchling"]
33
build-backend = "hatchling.build"
44

5+
[tool.hatch.build.targets.wheel]
6+
packages = ["src/starter_repo"]
7+
58
[project]
69
name = "starter-repo"
710
version = "0.1.0"

src/starter_repo/plot_data.py

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,40 @@
11
#!/usr/bin/env python3
22

3-
from pathlib import Path
43
import argparse
5-
import pandas as pd
4+
from pathlib import Path
5+
from typing import List, Tuple
6+
67
import matplotlib.pyplot as plt
7-
from typing import list, tuple
8+
import pandas as pd
9+
810

9-
def read_csv_data(file_path: Path, x_col: str, y_col: str) -> tuple[list[float], list[float]]:
11+
def read_csv_data(file_path: Path, x_col: str, y_col: str) -> Tuple[List[float], List[float]]:
1012
"""Read data from a CSV file and return specified columns.
11-
13+
1214
Args:
1315
file_path: Path to the CSV file
1416
x_col: Name of the column to use for x-axis
1517
y_col: Name of the column to use for y-axis
16-
18+
1719
Returns:
1820
Tuple of x and y data as lists
1921
"""
2022
df = pd.read_csv(file_path)
2123
return df[x_col].tolist(), df[y_col].tolist()
2224

23-
def create_plot(x_data: list[float], y_data: list[float],
24-
x_label: str, y_label: str, title: str) -> plt.Figure:
25+
26+
def create_plot(
27+
x_data: List[float], y_data: List[float], x_label: str, y_label: str, title: str
28+
) -> plt.Figure:
2529
"""Create a plot from the provided data.
26-
30+
2731
Args:
2832
x_data: Data for x-axis
2933
y_data: Data for y-axis
3034
x_label: Label for x-axis
3135
y_label: Label for y-axis
3236
title: Plot title
33-
37+
3438
Returns:
3539
matplotlib Figure object
3640
"""
@@ -41,22 +45,30 @@ def create_plot(x_data: list[float], y_data: list[float],
4145
ax.set_title(title)
4246
return fig
4347

48+
4449
def main() -> None:
4550
parser = argparse.ArgumentParser(description="Create plots from CSV data")
4651
parser.add_argument("file_path", type=Path, help="Path to the CSV file")
4752
parser.add_argument("x_column", type=str, help="Column name for x-axis")
4853
parser.add_argument("y_column", type=str, help="Column name for y-axis")
49-
parser.add_argument("--output", "-o", type=Path, default=Path("plot.png"),
50-
help="Output file path (default: plot.png)")
51-
parser.add_argument("--title", "-t", type=str, default="Data Plot",
52-
help="Plot title (default: Data Plot)")
53-
54+
parser.add_argument(
55+
"--output",
56+
"-o",
57+
type=Path,
58+
default=Path("plot.png"),
59+
help="Output file path (default: plot.png)",
60+
)
61+
parser.add_argument(
62+
"--title", "-t", type=str, default="Data Plot", help="Plot title (default: Data Plot)"
63+
)
64+
5465
args = parser.parse_args()
55-
66+
5667
x_data, y_data = read_csv_data(args.file_path, args.x_column, args.y_column)
5768
fig = create_plot(x_data, y_data, args.x_column, args.y_column, args.title)
5869
fig.savefig(args.output)
5970
plt.close(fig)
6071

72+
6173
if __name__ == "__main__":
62-
main()
74+
main()

tests/test_plot_data.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
from pathlib import Path
2+
23
import pandas as pd
34
import pytest
4-
from starter_repo.plot_data import read_csv_data, create_plot
5+
from starter_repo.plot_data import create_plot, read_csv_data
6+
57

68
@pytest.fixture
79
def sample_csv(tmp_path: Path) -> Path:
810
"""Create a sample CSV file for testing."""
9-
df = pd.DataFrame({
10-
'x': [1, 2, 3, 4, 5],
11-
'y': [2, 4, 6, 8, 10]
12-
})
11+
df = pd.DataFrame({"x": [1, 2, 3, 4, 5], "y": [2, 4, 6, 8, 10]})
1312
file_path = tmp_path / "test.csv"
1413
df.to_csv(file_path, index=False)
1514
return file_path
1615

16+
1717
def test_read_csv_data(sample_csv: Path) -> None:
1818
"""Test reading data from CSV file."""
19-
x_data, y_data = read_csv_data(sample_csv, 'x', 'y')
19+
x_data, y_data = read_csv_data(sample_csv, "x", "y")
2020
assert x_data == [1, 2, 3, 4, 5]
2121
assert y_data == [2, 4, 6, 8, 10]
2222

23+
2324
def test_create_plot() -> None:
2425
"""Test plot creation."""
2526
x_data = [1, 2, 3]
@@ -30,4 +31,4 @@ def test_create_plot() -> None:
3031
ax = fig.axes[0]
3132
assert ax.get_xlabel() == "X"
3233
assert ax.get_ylabel() == "Y"
33-
assert ax.get_title() == "Test Plot"
34+
assert ax.get_title() == "Test Plot"

0 commit comments

Comments
 (0)