Skip to content

Commit

Permalink
feat(dev-deps): Replace black with ruff (#138)
Browse files Browse the repository at this point in the history
* feat(dev-deps): Replace black with ruff

Signed-off-by: Luka Peschke <[email protected]>

* chore: make format

Signed-off-by: Luka Peschke <[email protected]>

---------

Signed-off-by: Luka Peschke <[email protected]>
  • Loading branch information
lukapeschke authored Nov 14, 2023
1 parent 7f0bbce commit fcebe56
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 65 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Commands
## Python
ruff = ruff python/ *.py
black = black python/ *.py
format = ruff format python/ *.py
mypy = mypy python/ *.py
pytest = python -m pytest
## Rust
Expand All @@ -14,12 +14,12 @@ pdoc = pdoc -o docs python/fastexcel

lint:
$(ruff)
$(black) --check --diff
$(format) --check --diff
$(mypy)
$(clippy)
format:
$(black)
$(ruff) --fix
$(format)
$(fmt)

install-test-requirements:
Expand Down
4 changes: 1 addition & 3 deletions python/tests/test_durations.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ def test_sheet_with_different_time_types() -> None:
"date": [date(2023, 6, 1)],
"datestr": ["2023-06-01T02:03:04+02:00"],
"time": pd.Series([pd.to_timedelta("01:02:03")]).astype("timedelta64[ms]"),
"datetime": pd.Series([pd.to_datetime("2023-06-01 02:03:04")]).astype(
"datetime64[ms]"
),
"datetime": pd.Series([pd.to_datetime("2023-06-01 02:03:04")]).astype("datetime64[ms]"),
}
)
expected_pl = pl.DataFrame(
Expand Down
76 changes: 19 additions & 57 deletions python/tests/test_fastexcel.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ def test_single_sheet_to_pandas():


def test_single_sheet_with_types_to_pandas():
excel_reader = fastexcel.read_excel(
path_for_fixture("fixture-single-sheet-with-types.xlsx")
)
excel_reader = fastexcel.read_excel(path_for_fixture("fixture-single-sheet-with-types.xlsx"))
assert excel_reader.sheet_names == ["Sheet1"]

sheet = excel_reader.load_sheet(0)
Expand Down Expand Up @@ -64,9 +62,7 @@ def test_single_sheet_with_types_to_pandas():
"dates": ["2022-03-02 05:43:04"] * 3,
"floats": [12.35, 42.69, 1234567],
}
).with_columns(
pl.col("dates").str.strptime(pl.Datetime, "%F %T").dt.cast_time_unit("ms")
),
).with_columns(pl.col("dates").str.strptime(pl.Datetime, "%F %T").dt.cast_time_unit("ms")),
)


Expand Down Expand Up @@ -118,9 +114,7 @@ def test_multiple_sheets_to_pandas():


def test_sheets_with_header_line_diff_from_zero():
excel_reader = fastexcel.read_excel(
path_for_fixture("fixture-changing-header-location.xlsx")
)
excel_reader = fastexcel.read_excel(path_for_fixture("fixture-changing-header-location.xlsx"))
assert excel_reader.sheet_names == ["Sheet1", "Sheet2", "Sheet3"]
sheet_by_name = excel_reader.load_sheet("Sheet1", header_row=1)
sheet_by_idx = excel_reader.load_sheet(0, header_row=1)
Expand All @@ -142,9 +136,7 @@ def test_sheets_with_header_line_diff_from_zero():


def test_sheets_with_no_header():
excel_reader = fastexcel.read_excel(
path_for_fixture("fixture-changing-header-location.xlsx")
)
excel_reader = fastexcel.read_excel(path_for_fixture("fixture-changing-header-location.xlsx"))
assert excel_reader.sheet_names == ["Sheet1", "Sheet2", "Sheet3"]
sheet_by_name = excel_reader.load_sheet("Sheet2", header_row=None)
sheet_by_idx = excel_reader.load_sheet(1, header_row=None)
Expand All @@ -170,9 +162,7 @@ def test_sheets_with_no_header():


def test_sheets_with_empty_rows_before_header():
excel_reader = fastexcel.read_excel(
path_for_fixture("fixture-changing-header-location.xlsx")
)
excel_reader = fastexcel.read_excel(path_for_fixture("fixture-changing-header-location.xlsx"))
assert excel_reader.sheet_names == ["Sheet1", "Sheet2", "Sheet3"]
sheet_by_name = excel_reader.load_sheet("Sheet3")
sheet_by_idx = excel_reader.load_sheet(2)
Expand All @@ -194,16 +184,12 @@ def test_sheets_with_empty_rows_before_header():


def test_sheets_with_custom_headers():
excel_reader = fastexcel.read_excel(
path_for_fixture("fixture-changing-header-location.xlsx")
)
excel_reader = fastexcel.read_excel(path_for_fixture("fixture-changing-header-location.xlsx"))
assert excel_reader.sheet_names == ["Sheet1", "Sheet2", "Sheet3"]
sheet_by_name = excel_reader.load_sheet(
"Sheet2", header_row=None, column_names=["foo", "bar", "baz"]
)
sheet_by_idx = excel_reader.load_sheet(
1, header_row=None, column_names=["foo", "bar", "baz"]
)
sheet_by_idx = excel_reader.load_sheet(1, header_row=None, column_names=["foo", "bar", "baz"])

# Metadata
assert sheet_by_name.name == sheet_by_idx.name == "Sheet2"
Expand All @@ -222,13 +208,9 @@ def test_sheets_with_custom_headers():


def test_sheets_with_skipping_headers():
excel_reader = fastexcel.read_excel(
path_for_fixture("fixture-changing-header-location.xlsx")
)
excel_reader = fastexcel.read_excel(path_for_fixture("fixture-changing-header-location.xlsx"))
assert excel_reader.sheet_names == ["Sheet1", "Sheet2", "Sheet3"]
sheet_by_name = excel_reader.load_sheet(
"Sheet2", header_row=1, column_names=["Bugs"]
)
sheet_by_name = excel_reader.load_sheet("Sheet2", header_row=1, column_names=["Bugs"])
sheet_by_idx = excel_reader.load_sheet(1, header_row=1, column_names=["Bugs"])

# Metadata
Expand All @@ -252,9 +234,7 @@ def test_sheets_with_skipping_headers():


def test_sheet_with_pagination():
excel_reader = fastexcel.read_excel(
path_for_fixture("fixture-single-sheet-with-types.xlsx")
)
excel_reader = fastexcel.read_excel(path_for_fixture("fixture-single-sheet-with-types.xlsx"))
assert excel_reader.sheet_names == ["Sheet1"]

sheet = excel_reader.load_sheet(0, skip_rows=1, n_rows=1)
Expand All @@ -269,9 +249,7 @@ def test_sheet_with_pagination():
{
"__UNNAMED__0": [1.0],
"bools": [False],
"dates": pd.Series([pd.Timestamp("2022-03-02 05:43:04")]).astype(
"datetime64[ms]"
),
"dates": pd.Series([pd.Timestamp("2022-03-02 05:43:04")]).astype("datetime64[ms]"),
"floats": [42.69],
}
),
Expand All @@ -286,16 +264,12 @@ def test_sheet_with_pagination():
"dates": ["2022-03-02 05:43:04"],
"floats": [42.69],
}
).with_columns(
pl.col("dates").str.strptime(pl.Datetime, "%F %T").dt.cast_time_unit("ms")
),
).with_columns(pl.col("dates").str.strptime(pl.Datetime, "%F %T").dt.cast_time_unit("ms")),
)


def test_sheet_with_skip_rows():
excel_reader = fastexcel.read_excel(
path_for_fixture("fixture-single-sheet-with-types.xlsx")
)
excel_reader = fastexcel.read_excel(path_for_fixture("fixture-single-sheet-with-types.xlsx"))
assert excel_reader.sheet_names == ["Sheet1"]

sheet = excel_reader.load_sheet(0, skip_rows=1)
Expand Down Expand Up @@ -326,16 +300,12 @@ def test_sheet_with_skip_rows():
"dates": ["2022-03-02 05:43:04"] * 2,
"floats": [42.69, 1234567],
}
).with_columns(
pl.col("dates").str.strptime(pl.Datetime, "%F %T").dt.cast_time_unit("ms")
),
).with_columns(pl.col("dates").str.strptime(pl.Datetime, "%F %T").dt.cast_time_unit("ms")),
)


def test_sheet_with_n_rows():
excel_reader = fastexcel.read_excel(
path_for_fixture("fixture-single-sheet-with-types.xlsx")
)
excel_reader = fastexcel.read_excel(path_for_fixture("fixture-single-sheet-with-types.xlsx"))
assert excel_reader.sheet_names == ["Sheet1"]

sheet = excel_reader.load_sheet(0, n_rows=1)
Expand All @@ -349,9 +319,7 @@ def test_sheet_with_n_rows():
{
"__UNNAMED__0": [0.0],
"bools": [True],
"dates": pd.Series([pd.Timestamp("2022-03-02 05:43:04")]).astype(
"datetime64[ms]"
),
"dates": pd.Series([pd.Timestamp("2022-03-02 05:43:04")]).astype("datetime64[ms]"),
"floats": [12.35],
}
),
Expand All @@ -366,16 +334,12 @@ def test_sheet_with_n_rows():
"dates": ["2022-03-02 05:43:04"],
"floats": [12.35],
}
).with_columns(
pl.col("dates").str.strptime(pl.Datetime, "%F %T").dt.cast_time_unit("ms")
),
).with_columns(pl.col("dates").str.strptime(pl.Datetime, "%F %T").dt.cast_time_unit("ms")),
)


def test_sheet_with_pagination_and_without_headers():
excel_reader = fastexcel.read_excel(
path_for_fixture("fixture-single-sheet-with-types.xlsx")
)
excel_reader = fastexcel.read_excel(path_for_fixture("fixture-single-sheet-with-types.xlsx"))
assert excel_reader.sheet_names == ["Sheet1"]

sheet = excel_reader.load_sheet(
Expand Down Expand Up @@ -419,9 +383,7 @@ def test_sheet_with_pagination_and_without_headers():


def test_sheet_with_pagination_out_of_bound():
excel_reader = fastexcel.read_excel(
path_for_fixture("fixture-single-sheet-with-types.xlsx")
)
excel_reader = fastexcel.read_excel(path_for_fixture("fixture-single-sheet-with-types.xlsx"))
assert excel_reader.sheet_names == ["Sheet1"]

with pytest.raises(RuntimeError, match="To many rows skipped. Max height is 4"):
Expand Down
3 changes: 1 addition & 2 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
mypy>=1,<2
black>=22.8.0,<24
openpyxl>=3.1.2<4
pre-commit>=2.20.0,<4
pytest>=7.1.3
pytest-benchmark>=4.0.0,<5
ruff>=0.1,<0.2
ruff>=0.1.5,<0.2
xlrd>=2.0.1<3

0 comments on commit fcebe56

Please sign in to comment.