326-numpy-unittest

Validate NumPy unit tests with numpy.testing assertions and tolerance checks.

Updated May 21, 2026
One-click install
npx skills add https://github.com/ulf1/trading-regime --skill 326-numpy-unittest
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: 326-numpy-unittest
Source: https://github.com/ulf1/trading-regime/tree/main/.agent/skills/326-numpy-unittest
Command: npx skills add https://github.com/ulf1/trading-regime --skill 326-numpy-unittest

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires numpy, pytest, and includes assets (resource) components.

What problem does it solve?

It prevents fragile or incorrect unit tests for NumPy code by enforcing correct comparison semantics, numerically stable tolerance handling, and reliable checks for shapes, dtypes, and mutation side effects.

Core Features & Use Cases

  • Correct NumPy Assertions: Use numpy.testing array-aware assertions instead of brittle == comparisons to avoid truth-value errors and hidden mismatches.
  • Precision-Safe Validation: Require explicit rtol and atol for floating-point results, including guidance for stable comparisons of probabilities and mathematical outputs.
  • Robust Invariant and Edge-Case Coverage: Validate shapes/dtypes, test mathematically meaningful invariants (e.g., sums-to-1), and cover boundary and numerical stability cases such as NaN/Inf and overflow.
  • Side-Effect Guardrails: Detect unintended input mutation and verify consistent behavior on non-contiguous/strided views.

Quick Start

Use the skill when you are writing or reviewing a pytest/unittest for any NumPy function, especially one that compares array values, checks shapes/dtypes, or must be tolerant of floating-point precision differences.

Frequently Asked Questions about 326-numpy-unittest

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test NumPy array outputs in pytest without getting truth value errors?

To test NumPy arrays in pytest without truth value errors, use array-aware assertions from numpy.testing instead of brittle equality comparisons to validate array values, shapes, and dtypes accurately.

What is the best way to handle floating-point tolerance when unit testing NumPy functions?

The best way to handle floating-point tolerance in NumPy unit tests is to use explicit relative tolerance (rtol) and absolute tolerance (atol) parameters. This ensures numerically stable comparisons for probabilities and mathematical outputs.

How do I check for unintended input mutation in NumPy unit tests?

To check for unintended input mutation in NumPy unit tests, implement side-effect guardrails that audit input arrays. This verifies consistent behavior on non-contiguous or strided views, ensuring functions do not alter inputs unexpectedly.

Does this NumPy testing approach cover edge cases like NaN, Inf, and empty arrays?

Yes, this NumPy testing approach covers edge cases like NaN, Inf, and empty arrays. It enforces robust invariant and edge-case coverage to test mathematical invariants and boundary conditions under numerical stability constraints.

Can I use unittest instead of pytest to validate NumPy array shapes and dtypes?

Yes, you can use unittest instead of pytest to validate NumPy array shapes and dtypes. The testing principles apply to both workflows, utilizing numpy.testing assertions to ensure correct comparison semantics across parametrized cases.