commodutil 3.7.0__tar.gz → 3.7.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {commodutil-3.7.0 → commodutil-3.7.2}/PKG-INFO +1 -1
- {commodutil-3.7.0 → commodutil-3.7.2}/commodutil/convfactors.py +18 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/commodutil.egg-info/PKG-INFO +1 -1
- {commodutil-3.7.0 → commodutil-3.7.2}/tests/test_conv.py +47 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/.coveragerc +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/.github/workflows/1_tests.yml +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/.github/workflows/2_coverage.yml +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/.github/workflows/3_linting.yml +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/.github/workflows/4_release.yml +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/.gitignore +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/.pypirc +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/azure-build-pipelines.yml +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/commodutil/__init__.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/commodutil/arb.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/commodutil/dates.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/commodutil/forward/__init__.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/commodutil/forward/calendar.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/commodutil/forward/continuous.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/commodutil/forward/fly.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/commodutil/forward/quarterly.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/commodutil/forward/spreads.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/commodutil/forward/structure.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/commodutil/forward/util.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/commodutil/forwards.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/commodutil/pandasutil.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/commodutil/stats.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/commodutil/transforms.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/commodutil.egg-info/SOURCES.txt +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/commodutil.egg-info/dependency_links.txt +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/commodutil.egg-info/requires.txt +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/commodutil.egg-info/top_level.txt +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/pyproject.toml +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/requirements-test.txt +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/requirements.txt +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/requirements_dev.txt +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/scripts/rbw_structure_scan.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/setup.cfg +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/tests/__init__.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/tests/conftest.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/tests/forward/__init__.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/tests/forward/conftest.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/tests/forward/test_calendar.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/tests/forward/test_continuous.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/tests/forward/test_fly.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/tests/forward/test_quarterly.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/tests/forward/test_spreads.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/tests/forward/test_structure.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/tests/forward/test_util.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/tests/test_arb.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/tests/test_cl.csv +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/tests/test_dates.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/tests/test_forwards.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/tests/test_pandasutils.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/tests/test_price_conv.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/tests/test_stats.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/tests/test_transforms.py +0 -0
- {commodutil-3.7.0 → commodutil-3.7.2}/tests/test_weekly.csv +0 -0
|
@@ -33,6 +33,24 @@ ureg.define("megatonne = 1e6 metric_ton = Mt")
|
|
|
33
33
|
# normalize_unit helper already maps 'MMBTU' -> 'MMBtu').
|
|
34
34
|
ureg.define("million_british_thermal_unit = 1e6 Btu = MMBtu")
|
|
35
35
|
|
|
36
|
+
# Case-insensitive aliases for the most-quoted energy / power units.
|
|
37
|
+
# Pint is case-sensitive by default, so `ureg('mmbtu')` or `ureg('mw')` raise
|
|
38
|
+
# UndefinedUnitError even though `MMBtu` / `MW` work. Callers (Power Query, ad-hoc
|
|
39
|
+
# scripts, copy-pasted Platts symbols) very commonly use the lowercase / all-caps
|
|
40
|
+
# / underscored forms, so register them explicitly here.
|
|
41
|
+
#
|
|
42
|
+
# Energy: MMBtu + therm + Btu spellings (MMBtu is defined above; therm + Btu are
|
|
43
|
+
# in pint's defaults). `million_btu` is the long-form alias.
|
|
44
|
+
ureg.define("@alias million_british_thermal_unit = mmbtu = MMBTU = million_btu")
|
|
45
|
+
ureg.define("@alias therm = Therm = THERM")
|
|
46
|
+
ureg.define("@alias british_thermal_unit = btu")
|
|
47
|
+
# Power / energy: MW and MWh are SI-prefix forms of `watt` / `watt_hour`, so they
|
|
48
|
+
# cannot be aliased via `@alias`. Register lowercase / all-caps spellings as
|
|
49
|
+
# standalone units with the same magnitude.
|
|
50
|
+
ureg.define("mw = 1e6 watt")
|
|
51
|
+
ureg.define("mwh = 1e6 watt * hour")
|
|
52
|
+
ureg.define("MWH = 1e6 watt * hour")
|
|
53
|
+
|
|
36
54
|
|
|
37
55
|
@dataclass
|
|
38
56
|
class Commodity:
|
|
@@ -340,6 +340,53 @@ class TestUtils:
|
|
|
340
340
|
result = convfactors.convert(simple_series, "bbl/day", "bbl/month")
|
|
341
341
|
assert result.iloc[0] == pytest.approx(3043.75, abs=0.1)
|
|
342
342
|
|
|
343
|
+
def test_case_insensitive_energy_aliases(self):
|
|
344
|
+
"""Lowercase / all-caps / long-form spellings of MMBtu, therm, Btu resolve."""
|
|
345
|
+
from commodutil.convfactors import ureg
|
|
346
|
+
|
|
347
|
+
# MMBtu and its aliases all resolve to the same base magnitude
|
|
348
|
+
canonical_mmbtu = (1 * ureg("MMBtu")).to_base_units().magnitude
|
|
349
|
+
for alias in ("mmbtu", "MMBTU", "million_btu"):
|
|
350
|
+
mag = (1 * ureg(alias)).to_base_units().magnitude
|
|
351
|
+
assert mag == pytest.approx(canonical_mmbtu), (
|
|
352
|
+
f"{alias} should resolve to MMBtu (got {mag} vs {canonical_mmbtu})"
|
|
353
|
+
)
|
|
354
|
+
|
|
355
|
+
# therm + Therm + THERM
|
|
356
|
+
canonical_therm = (1 * ureg("therm")).to_base_units().magnitude
|
|
357
|
+
for alias in ("Therm", "THERM"):
|
|
358
|
+
mag = (1 * ureg(alias)).to_base_units().magnitude
|
|
359
|
+
assert mag == pytest.approx(canonical_therm)
|
|
360
|
+
|
|
361
|
+
# Btu + btu + BTU
|
|
362
|
+
canonical_btu = (1 * ureg("Btu")).to_base_units().magnitude
|
|
363
|
+
for alias in ("btu", "BTU"):
|
|
364
|
+
mag = (1 * ureg(alias)).to_base_units().magnitude
|
|
365
|
+
assert mag == pytest.approx(canonical_btu)
|
|
366
|
+
|
|
367
|
+
# Sanity: 1 MMBtu = 1e6 Btu
|
|
368
|
+
assert canonical_mmbtu == pytest.approx(1e6 * canonical_btu)
|
|
369
|
+
|
|
370
|
+
def test_case_insensitive_power_aliases(self):
|
|
371
|
+
"""Lowercase / all-caps spellings of MW and MWh resolve."""
|
|
372
|
+
from commodutil.convfactors import ureg
|
|
373
|
+
|
|
374
|
+
# MW and mw
|
|
375
|
+
canonical_mw = (1 * ureg("MW")).to_base_units().magnitude
|
|
376
|
+
assert (1 * ureg("mw")).to_base_units().magnitude == pytest.approx(canonical_mw)
|
|
377
|
+
|
|
378
|
+
# MWh, mwh, MWH
|
|
379
|
+
canonical_mwh = (1 * ureg("MWh")).to_base_units().magnitude
|
|
380
|
+
for alias in ("mwh", "MWH"):
|
|
381
|
+
mag = (1 * ureg(alias)).to_base_units().magnitude
|
|
382
|
+
assert mag == pytest.approx(canonical_mwh), (
|
|
383
|
+
f"{alias} should resolve to MWh (got {mag} vs {canonical_mwh})"
|
|
384
|
+
)
|
|
385
|
+
|
|
386
|
+
# Sanity: 1 MWh = 3.6 GJ
|
|
387
|
+
assert (1 * ureg("MWh")).to("GJ").magnitude == pytest.approx(3.6)
|
|
388
|
+
assert (1 * ureg("mwh")).to("GJ").magnitude == pytest.approx(3.6)
|
|
389
|
+
|
|
343
390
|
def test_caching_and_properties(self):
|
|
344
391
|
"""Test caching and property methods"""
|
|
345
392
|
from commodutil.convfactors import converter
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|