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

ci: pre-commit checks #78

Merged
merged 3 commits into from
Dec 12, 2023
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
18 changes: 18 additions & 0 deletions .github/workflows/code-checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Code Checks

on:
workflow_dispatch:
push:
branches: ['main', 'dev-*']
pull_request:
release:
types: [published]

jobs:
pre-commit:
name: "Run pre-commit"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: pre-commit/[email protected]
22 changes: 22 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
exclude: "(.*\\.svg)|(.*\\.qmd)|(.*\\.ambr)|(.*\\.csv)|(.*\\.txt)"
repos:
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
types:
- python
additional_dependencies:
- flake8-pyproject
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
args: ["--unsafe"]
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 23.11.0
hooks:
- id: black
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"justMyCode": true
}
]
}
}
8 changes: 4 additions & 4 deletions great_tables/_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -1869,7 +1869,7 @@ def _value_to_decimal_notation(
result = result.rstrip(dec_mark)

# Add in a trailing decimal mark under specific circumstances
if drop_trailing_dec_mark is False and not dec_mark in result:
if drop_trailing_dec_mark is False and dec_mark not in result:
result = result + dec_mark

# Force the positive sign to be present if the `force_sign` option is taken
Expand Down Expand Up @@ -1957,7 +1957,7 @@ def _format_number_n_sigfig(
formatted_integer = ""
formatted_decimal = dec_mark + decimal_part if decimal_part else ""

if preserve_integer and not "." in formatted_value:
if preserve_integer and "." not in formatted_value:
formatted_value = "{:0.0f}".format(value)

# Insert grouping separators within the integer part
Expand Down Expand Up @@ -2833,7 +2833,7 @@ def _validate_date_style(date_style: str) -> None:
Returns:
None
"""
if not date_style in _get_date_formats_dict():
if date_style not in _get_date_formats_dict():
raise ValueError(f"date_style must be one of: {', '.join(_get_date_formats_dict().keys())}")

return
Expand All @@ -2852,7 +2852,7 @@ def _validate_time_style(time_style: str) -> None:
Returns:
None
"""
if not time_style in _get_time_formats_dict():
if time_style not in _get_time_formats_dict():
raise ValueError(f"time_style must be one of: {', '.join(_get_time_formats_dict().keys())}")

return
Expand Down
2 changes: 1 addition & 1 deletion great_tables/_gt_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class Body:
def __init__(self, body: Union[pd.DataFrame, TblData]):
self.body = body

def render_formats(self, data_tbl: TblData, formats: List[FormatInfo], context: Context):
def render_formats(self, data_tbl: TblData, formats: List[FormatInfo], context: Any):
for fmt in formats:
eval_func = getattr(fmt.func, context, fmt.func.default)
if eval_func is None:
Expand Down
2 changes: 1 addition & 1 deletion great_tables/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _as_css_font_family_attr(fonts: List[str], value_only: bool = False) -> str:
def _object_as_dict(v: Any) -> Any:
try:
return v.object_as_dict()
except:
except Exception:
pass
if type(v) == pd.DataFrame:
return v.to_dict()
Expand Down
11 changes: 7 additions & 4 deletions great_tables/_utils_render_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,17 +328,20 @@ def create_columns_component_h(data: GTData) -> str:
table_col_headings = tags.tr(level_1_spanners, class_="gt_col_headings gt_spanner_row")

if _get_spanners_matrix_height(data=data) > 2:
higher_spanner_rows_idx = seq_len(nrow(spanner_ids) - 2)
# TODO: functions like seq_len don't exist
higher_spanner_rows_idx = seq_len(nrow(spanner_ids) - 2) # noqa

higher_spanner_rows = TagList()

for i in higher_spanner_rows_idx:
spanner_ids_row = spanner_ids[i]
spanners_row = spanners[i]
spanners_vars = list(set(spanner_ids_row[~np.isnan(spanner_ids_row)].tolist()))
# TODO: shouldn't use np here
spanners_vars = list(set(spanner_ids_row[~np.isnan(spanner_ids_row)].tolist())) # noqa

# Replace NA values in spanner_ids_row with an empty string
spanner_ids_row[np.isnan(spanner_ids_row)] = ""
# TODO: shouldn't use np here
spanner_ids_row[np.isnan(spanner_ids_row)] = "" # noqa

spanners_rle = [(k, len(list(g))) for k, g in groupby(list(spanner_ids_row))]

Expand Down Expand Up @@ -490,7 +493,7 @@ def create_body_component_h(data: GTData) -> str:
cell_styles = ""

if is_stub_cell:
body_cells.append(f' <th class="gt_row gt_left gt_stub">' + cell_str + "</th>")
body_cells.append(' <th class="gt_row gt_left gt_stub">' + cell_str + "</th>")
else:
body_cells.append(
f' <td {cell_styles}class="gt_row gt_{cell_alignment}">' + cell_str + "</td>"
Expand Down
15 changes: 14 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,19 @@ dev = [
]

[tool.flake8]
exclude = ["docs", ".venv"]
exclude = ["docs", ".venv", "tests/*"]

ignore = [
"E402", # module level import not at top of file
"E501", # line too long (maximum 100 characters)
"W503", # line break before binary operator
"F811", # redefinition of unused name
"E203", # whitespace before ':'
"F401", # 'module' imported but unused
"F841", # local variable 'name' is assigned to but never used
]

max-line-length = 100

[tool.pytest.ini_options]
minversion = "6.0"
Expand All @@ -75,5 +87,6 @@ asyncio_mode = "strict"
testpaths = [
"tests"
]

[tool.black]
line-length = 100
Loading