Skip to content
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
9 changes: 9 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ jobs:
- name: Install dependencies
run: uv sync --dev

- name: Lint Python code with Ruff
run: uv run ruff check .

- name: Check Python formatting with Ruff
run: uv run ruff format --check .

- name: Lint YAML files
run: uv run yamllint .

- name: Run unit tests
run: uv run pytest tests/ -v --cov=scripts --cov-report=term-missing

Expand Down
38 changes: 38 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
# yamllint configuration for named-functions project
# Validates both formula YAMLs and GitHub workflow YAMLs

extends: default

rules:
# Line length - allow long lines for formulas
line-length:
max: 120
level: warning

# Indentation - 2 spaces (GitHub Actions standard)
indentation:
spaces: 2
indent-sequences: true

# Allow inline mappings (common in GitHub Actions)
braces:
min-spaces-inside: 0
max-spaces-inside: 1

# Document start (---) not required
document-start: disable

# Allow truthy values (yes/no, on/off) in GitHub Actions
truthy:
allowed-values: ['true', 'false', 'yes', 'no', 'on', 'off']
check-keys: false

# Comments - allow reasonable comment formatting
comments:
min-spaces-from-content: 1

# Allow empty values (common in formulas)
empty-values:
forbid-in-block-mappings: false
forbid-in-flow-mappings: false
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2332,22 +2332,22 @@ v1.0.2 Transforms wide-format data into long-format (tidy data) by unpivoting sp
ac, IF(OR(attributecol = "", ISBLANK(attributecol)), "Attribute", attributecol),
vc, IF(OR(valuecol = "", ISBLANK(valuecol)), "Value", valuecol),
fillna_val, (MAP(fillna, LAMBDA(v, IF(ISBLANK(v), "", v)))),

num_rows, ROWS(data),
num_cols, COLUMNS(data),

_validate_dims, IF(OR(num_rows < 2, num_cols < 2),
(XLOOKUP("Data must have at least 2 rows and 2 columns", IF(FALSE, {1}), IF(FALSE, {1}))),
TRUE
),

_validate_fc, IF(OR(fc < 1, fc >= num_cols),
(XLOOKUP("fixedcols must be between 1 and " & (num_cols - 1), IF(FALSE, {1}), IF(FALSE, {1}))),
TRUE
),

all_headers, INDEX(data, 1, SEQUENCE(1, num_cols)),

selected_cols, IF(OR(select_columns = "", ISBLANK(select_columns)),
SEQUENCE(1, num_cols - fc, fc + 1),
IF(ISTEXT(INDEX(select_columns, 1, 1)),
Expand Down Expand Up @@ -2379,39 +2379,39 @@ v1.0.2 Transforms wide-format data into long-format (tidy data) by unpivoting sp
)
)
),

ncols, COLUMNS(selected_cols),
nrows, num_rows - 1,
total_output, nrows * ncols,

unpivoted, MAKEARRAY(total_output, fc + 2, LAMBDA(r, c,
LET(
source_row, INT((r - 1) / ncols) + 2,
col_idx, MOD(r - 1, ncols) + 1,
value_col_num, INDEX(selected_cols, 1, col_idx),

cell_value, IF(c <= fc,
INDEX(data, source_row, c),
IF(c = fc + 1,
INDEX(data, 1, value_col_num),
INDEX(data, source_row, value_col_num)
)
),

IF(AND(c = fc + 2, cell_value = "", fillna_val <> ""),
fillna_val,
cell_value
)
)
)),

output_headers, MAKEARRAY(1, fc + 2, LAMBDA(r, c,
IF(c <= fc,
INDEX(data, 1, c),
IF(c = fc + 1, ac, vc)
)
)),

VSTACK(output_headers, unpivoted)
)
```
Expand Down
22 changes: 11 additions & 11 deletions formulas/unpivot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,22 @@ formula: |
ac, IF(OR(attributecol = "", ISBLANK(attributecol)), "Attribute", attributecol),
vc, IF(OR(valuecol = "", ISBLANK(valuecol)), "Value", valuecol),
fillna_val, BLANKTOEMPTY(fillna),

num_rows, ROWS(data),
num_cols, COLUMNS(data),

_validate_dims, IF(OR(num_rows < 2, num_cols < 2),
ERROR("Data must have at least 2 rows and 2 columns"),
TRUE
),

_validate_fc, IF(OR(fc < 1, fc >= num_cols),
ERROR("fixedcols must be between 1 and " & (num_cols - 1)),
TRUE
),

all_headers, INDEX(data, 1, SEQUENCE(1, num_cols)),

selected_cols, IF(OR(select_columns = "", ISBLANK(select_columns)),
SEQUENCE(1, num_cols - fc, fc + 1),
IF(ISTEXT(INDEX(select_columns, 1, 1)),
Expand Down Expand Up @@ -88,38 +88,38 @@ formula: |
)
)
),

ncols, COLUMNS(selected_cols),
nrows, num_rows - 1,
total_output, nrows * ncols,

unpivoted, MAKEARRAY(total_output, fc + 2, LAMBDA(r, c,
LET(
source_row, INT((r - 1) / ncols) + 2,
col_idx, MOD(r - 1, ncols) + 1,
value_col_num, INDEX(selected_cols, 1, col_idx),

cell_value, IF(c <= fc,
INDEX(data, source_row, c),
IF(c = fc + 1,
INDEX(data, 1, value_col_num),
INDEX(data, source_row, value_col_num)
)
),

IF(AND(c = fc + 2, cell_value = "", fillna_val <> ""),
fillna_val,
cell_value
)
)
)),

output_headers, MAKEARRAY(1, fc + 2, LAMBDA(r, c,
IF(c <= fc,
INDEX(data, 1, c),
IF(c = fc + 1, ac, vc)
)
)),

VSTACK(output_headers, unpivoted)
)
59 changes: 59 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ dependencies = [
dev = [
"pytest>=7.0",
"pytest-cov>=4.0",
"ruff>=0.8.0",
"yamllint>=1.35.0",
]

[build-system]
Expand All @@ -39,3 +41,60 @@ markers = [
"integration: Integration tests for complete workflows",
"slow: Tests that take significant time to run",
]

[tool.ruff]
# Line length to match common Python standards
line-length = 100

# Target Python 3.8+ (matching project requirements)
target-version = "py38"

# Exclude common directories
exclude = [
".git",
".pytest_cache",
"__pycache__",
"*.egg-info",
]

[tool.ruff.lint]
# Enable recommended rulesets
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"I", # isort (import sorting)
"N", # pep8-naming
"UP", # pyupgrade (modern Python syntax)
"B", # flake8-bugbear (common bugs)
"C4", # flake8-comprehensions
"SIM", # flake8-simplify
"RET", # flake8-return
]

# Disable specific rules that conflict with project style
ignore = [
"E501", # Line too long (handled by formatter)
"RET504", # Unnecessary variable assignment before return (sometimes clearer)
"SIM108", # Use ternary operator (sometimes if/else is clearer)
]

# Allow auto-fixing for safe rules
fixable = ["ALL"]
unfixable = []

[tool.ruff.lint.isort]
# Import sorting configuration
known-first-party = ["scripts"]
force-single-line = false
lines-after-imports = 2

[tool.ruff.format]
# Use double quotes for strings
quote-style = "double"

# Indent with spaces
indent-style = "space"

# Unix-style line endings
line-ending = "lf"
Loading
Loading