Visitar URL original
Add config validator that maps null -> default by deruyter92 · Pull Request #3475 · DeepLabCut/DeepLabCut · GitHub
Skip to content

Add config validator that maps null -> default - #3475

Merged
deruyter92 merged 4 commits into
devfrom
jaap/add-config-null-default-validator
Sep 8, 2026
Merged

deruyter92 merged 4 commits into
devfrom
jaap/add-config-null-default-validator

Conversation

@deruyter92

Copy link
Copy Markdown
Collaborator

Follow-up PR for #3470, introducing a central validator for cases when null needs to be mapped to default.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is small and targeted, removes duplicated logic, and is backed by focused unit tests for both the new DefaultIfNone behavior and related validation helpers.

Pull request overview

This PR introduces a reusable config-validation helper that normalizes explicit null values to a field’s declared default during Pydantic validation, and applies it to the PyTorch detector model config so existing YAML configs with box_score_thresh: null validate to the intended default.

Changes:

  • Added DefaultIfNone[...] annotated type (via a BeforeValidator) that maps explicit None inputs to “use field default”.
  • Replaced the bespoke box_score_thresh field validator in DetectorModelConfig with DefaultIfNone[Fraction].
  • Added a new test module covering DefaultIfNone behavior plus existing validators in deeplabcut.core.config.validation.
File summaries
File Description
deeplabcut/core/config/validation.py Adds DefaultIfNone annotated type using PydanticUseDefault to centralize None -> default normalization.
deeplabcut/pose_estimation_pytorch/config/model.py Switches box_score_thresh to DefaultIfNone[Fraction], removing a one-off field validator.
tests/core/config/test_validation.py Adds unit tests validating DefaultIfNone and other validator utilities/annotated types.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

return list(unique_values(values))


def _use_default_if_none(value: Any) -> Any:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting!

@deruyter92
deruyter92 requested a review from C-Achard September 3, 2026 15:36
@deruyter92
deruyter92 marked this pull request as ready for review September 3, 2026 15:36

@C-Achard C-Achard left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, much cleaner now; thanks for the extra tests!

# ------------------------------------------------------------------


class TestNDArrayInt:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope for this PR but in hindsight I find the name to be slightly confusing. No concerns on functionality at all, just the int part.

@deruyter92 deruyter92 added enhancement New feature or request 3.0.2 labels Sep 7, 2026
@deruyter92 deruyter92 self-assigned this Sep 7, 2026
@deruyter92
deruyter92 merged commit 44b47ca into dev Sep 8, 2026
32 checks passed
@deruyter92
deruyter92 deleted the jaap/add-config-null-default-validator branch September 8, 2026 11:34
@C-Achard C-Achard linked an issue Sep 14, 2026 that may be closed by this pull request
2 tasks done
@C-Achard C-Achard mentioned this pull request Sep 14, 2026
2 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.0.2 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

issue with tensor types

3 participants