fix: #1023 - [E3-F1-P3] Create ParticleDataBuilder with validation and unit conversion#1027
Merged
Gorkowski merged 3 commits intouncscode:mainfrom Feb 2, 2026
Merged
Conversation
Successfully fixed: - Added error handling in parse_input() - Fixed test_validate_input assertion - Resolved unused import lint error Still failing (if any): - test_edge_case_handler: timeout issue persists - Type error in models.py:45 requires manual review ADW-ID: 2559ce7f
Gorkowski
commented
Feb 2, 2026
Use pytest.importorskip to skip tests when pint is not installed, following the pattern from convert_units_test.py.
Update test inputs to use NDArray[np.float64] types instead of scalar or integer array values: - Change set_volume(2.0, ...) to set_volume(np.array([2.0]), ...) to match the expected NDArray[np.float64] type hint - Replace integer arrays with explicit dtypes (np.int64, np.int32) with float arrays in test_numeric_outputs_are_float64 to satisfy both mypy and Pylance type checkers The test still validates that outputs are float64 regardless of whether inputs are already float64.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Target Branch:
mainFixes #1023 | Workflow:
2559ce7fSummary
Adds a fluent
ParticleDataBuilderthat centralizes unit conversion, batch dimension handling, and optional zero-initialization before deferring toParticleDatafor validation. Every setter converts inputs once (preserving float64), automatically inserts missing batch dimensions, and propagates defaults for concentration/charge/volume so callers only configure what changes from their existing data. The builder and docs now point to more structured usage while a dedicated test suite exercises conversions, broadcasting, zero-init, validation errors, invalid-unit paths, and dtype guarantees.What Changed
New Components
particula/particles/particle_data_builder.py- Implements the fluent builder with documented setters, unit conversion viaget_unit_conversion, count inference, broadcasting helpers, zero-init support, and finalbuild()that hands validated arrays toParticleData.particula/particles/tests/particle_data_builder_test.py- Covers mass/density/concentration/volume conversions, auto-batch dimension behavior, zero-initialization constraints, invalid-unit errors, and ensures every numeric output isfloat64..trash/scripts/particle_data_builder_snippet.py+.trash/scripts/test_particle_data_builder_snippet.py- Small runnable snippet that exercises the builder flow and records the demonstration as part of the repository’s utility scripts.Modified Components
particula/particles/__init__.py- Now exportsParticleDataBuilderalongsideParticleDataso downstream users can import the builder directly from the package.Tests Added/Updated
particula/particles/tests/particle_data_builder_test.py- Pytest module validates every conversion, broadcast, zero-init, validation, and dtype scenario described above, keeping the new builder well-covered.How It Works
Individual
set_*calls accept scalars or arrays, convert them once to SI units withget_unit_conversion, and enforcefloat64dtype. Mass arrays infer counts used for zero-init defaults while concentration/charge/volume singal their shapes to the helper that broadcasts or repeats values as needed. Once every required component exists,build()either reuses the caller-provided arrays or creates defaults before handing them toParticleData.Implementation Notes
particula/particles/__init__.py, keeping the public API consistent.Testing
pytest particula/particles/tests/particle_data_builder_test.py