Add v0.2.0 features: discovery API, caching, constants, and Jupyter support - #6
Merged
Merged
Conversation
…pyter repr Add conversion factor caching (@lru_cache) for up to 10x speedup on repeated lookups. Add unit/substance/currency discovery methods (Quantity.list_units(), list_substances(), list_currencies(), list_dimensions()). Add unit constants module (energyunits.units) for IDE autocompletion. Implement __sub__ operator. Add _repr_html_ for rich Jupyter display. Improve error messages with close-match suggestions and conversion hints. Warn on substance metadata loss during arithmetic with mixed substances. 291 tests passing. https://claude.ai/code/session_015zwEzhrnDuP91JXPxwMkJm
README: fix inaccurate substance list (removed nonexistent biogas, ethanol, steel, cement, aluminum), add v0.2.0 features (discovery API, unit constants, subtraction, Jupyter repr, currency conversions), document all 5 currencies, add time units section, fix License heading. ARCHITECTURE: bump to v0.2.0, update component diagram with ExchangeRateRegistry and units module, update test count (291+), mark caching as implemented, update future enhancements roadmap. Examples: add discovery_api(), unit_constants_example(), subtraction_example(), currency_conversion_example(). Fix ugly manual .unit assignment pattern. Import unit constants. Fix duplicate USD in ExchangeRateRegistry.get_supported_currencies(). https://claude.ai/code/session_015zwEzhrnDuP91JXPxwMkJm
1. Precision: replace hardcoded 0.2778 with 1/3.6 in heating value conversions (registry.py). Eliminates ~0.008% systematic error that compounds in large-scale calculations. 2. Data: fix wood_pellets LHV from 17.0 to 18.5 MJ/kg to match DATA_SOURCES.md documented value and physical expectations (HHV/LHV ratio was 0.85, now correct 0.925). 3. Security: escape user-provided strings (substance, basis, unit) in _repr_html_() to prevent HTML injection in Jupyter notebooks. 4. Consistency: align substance metadata logic in __add__/__sub__ with __mul__/__truediv__ — preserve substance when one operand has None instead of always dropping it. 5. Bug: renewable CO2 conversion no longer hardcodes "t" unit — preserves source mass unit (e.g., "kg" stays "kg"). 6. Logic: currency detection now uses component-based matching instead of substring matching, preventing false positives (e.g., "EUR" no longer matches inside "NEURON"). https://claude.ai/code/session_015zwEzhrnDuP91JXPxwMkJm
- Add Fixed section to CHANGELOG with all v0.2.0 bug fixes - Fix pyproject.toml license format for twine compatibility - Add License classifier - Replace non-existent readthedocs URL with ARCHITECTURE.md link https://claude.ai/code/session_015zwEzhrnDuP91JXPxwMkJm
- Update conf.py: furo theme, autodoc, intersphinx, myst, version from __init__ - Add API reference page with autodoc for all public classes - Add architecture and changelog pages (include from root .md files) - Add .readthedocs.yaml with Python 3.11 and pip install - Update docs/requirements.txt with furo and myst-parser - Point pyproject.toml Documentation URL to readthedocs https://claude.ai/code/session_015zwEzhrnDuP91JXPxwMkJm
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.
Summary
This release adds significant quality-of-life improvements to EnergyUnits, including a discovery API for exploring available units and substances, performance optimizations through caching, IDE-friendly unit constants, and rich Jupyter notebook support.
Key Changes
Discovery API
Quantity.list_units(dimension=None)to list available units, optionally filtered by dimensionQuantity.list_dimensions()to list all available dimensions (ENERGY, POWER, MASS, etc.)Quantity.list_substances(has_property=None)to list substances with optional property filteringQuantity.list_currencies()to list supported currenciesSubstanceRegistry.get_properties(substance_id)to retrieve all properties for a substanceUnitRegistryfor direct registry accessPerformance Optimization
@lru_cache(maxsize=256)onUnitRegistry.get_dimension()andget_conversion_factor()for up to 10x speedup on repeated conversionsload_units()Unit Constants Module
energyunits.unitsmodule with IDE-friendly string constantsfrom energyunits.units import MWh, GJ, USDSubtraction Operator
__sub__()method onQuantityclassJupyter/IPython Support
_repr_html_()method for rich HTML display in notebooksImproved Error Messages
difflib.get_close_matches()Substance Metadata Handling
__add__()and__sub__()to properly handle None values for substance/basisImplementation Details
UnitRegistry.get_dimension()to provide helpful error messages with suggestionsSubstanceRegistry.__getitem__()to suggest close matches on lookup failureExchangeRateRegistry.get_supported_currencies()to return sorted listtest_v020_features.py) with 83 tests covering all new featurespyproject.tomland__init__.pyTesting
Added 83 new tests in
test_v020_features.pycovering:https://claude.ai/code/session_015zwEzhrnDuP91JXPxwMkJm