From 1989b846cdcda1a4fa4d93c37720a9d501183f3e Mon Sep 17 00:00:00 2001 From: KrahmerTUD Date: Wed, 14 Feb 2024 10:16:52 +0100 Subject: [PATCH 1/2] fix: remove constraints for value of Impedance and Admittance Fixes #115 --- pdm.lock | 37 +++++++++++++++++---------------- psdm/quantities/multi_phase.py | 17 +++++++++++++-- psdm/quantities/single_phase.py | 8 ------- 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/pdm.lock b/pdm.lock index 0b79582..55cce67 100644 --- a/pdm.lock +++ b/pdm.lock @@ -50,7 +50,7 @@ files = [ [[package]] name = "black" -version = "24.1.1" +version = "24.2.0" requires_python = ">=3.8" summary = "The uncompromising code formatter." dependencies = [ @@ -63,20 +63,20 @@ dependencies = [ "typing-extensions>=4.0.1; python_version < \"3.11\"", ] files = [ - {file = "black-24.1.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:2588021038bd5ada078de606f2a804cadd0a3cc6a79cb3e9bb3a8bf581325a4c"}, - {file = "black-24.1.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:1a95915c98d6e32ca43809d46d932e2abc5f1f7d582ffbe65a5b4d1588af7445"}, - {file = "black-24.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2fa6a0e965779c8f2afb286f9ef798df770ba2b6cee063c650b96adec22c056a"}, - {file = "black-24.1.1-cp310-cp310-win_amd64.whl", hash = "sha256:5242ecd9e990aeb995b6d03dc3b2d112d4a78f2083e5a8e86d566340ae80fec4"}, - {file = "black-24.1.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:fc1ec9aa6f4d98d022101e015261c056ddebe3da6a8ccfc2c792cbe0349d48b7"}, - {file = "black-24.1.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:0269dfdea12442022e88043d2910429bed717b2d04523867a85dacce535916b8"}, - {file = "black-24.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b3d64db762eae4a5ce04b6e3dd745dcca0fb9560eb931a5be97472e38652a161"}, - {file = "black-24.1.1-cp311-cp311-win_amd64.whl", hash = "sha256:5d7b06ea8816cbd4becfe5f70accae953c53c0e53aa98730ceccb0395520ee5d"}, - {file = "black-24.1.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:e2c8dfa14677f90d976f68e0c923947ae68fa3961d61ee30976c388adc0b02c8"}, - {file = "black-24.1.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:a21725862d0e855ae05da1dd25e3825ed712eaaccef6b03017fe0853a01aa45e"}, - {file = "black-24.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:07204d078e25327aad9ed2c64790d681238686bce254c910de640c7cc4fc3aa6"}, - {file = "black-24.1.1-cp312-cp312-win_amd64.whl", hash = "sha256:a83fe522d9698d8f9a101b860b1ee154c1d25f8a82ceb807d319f085b2627c5b"}, - {file = "black-24.1.1-py3-none-any.whl", hash = "sha256:5cdc2e2195212208fbcae579b931407c1fa9997584f0a415421748aeafff1168"}, - {file = "black-24.1.1.tar.gz", hash = "sha256:48b5760dcbfe5cf97fd4fba23946681f3a81514c6ab8a45b50da67ac8fbc6c7b"}, + {file = "black-24.2.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:6981eae48b3b33399c8757036c7f5d48a535b962a7c2310d19361edeef64ce29"}, + {file = "black-24.2.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:d533d5e3259720fdbc1b37444491b024003e012c5173f7d06825a77508085430"}, + {file = "black-24.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:61a0391772490ddfb8a693c067df1ef5227257e72b0e4108482b8d41b5aee13f"}, + {file = "black-24.2.0-cp310-cp310-win_amd64.whl", hash = "sha256:992e451b04667116680cb88f63449267c13e1ad134f30087dec8527242e9862a"}, + {file = "black-24.2.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:163baf4ef40e6897a2a9b83890e59141cc8c2a98f2dda5080dc15c00ee1e62cd"}, + {file = "black-24.2.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:e37c99f89929af50ffaf912454b3e3b47fd64109659026b678c091a4cd450fb2"}, + {file = "black-24.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4f9de21bafcba9683853f6c96c2d515e364aee631b178eaa5145fc1c61a3cc92"}, + {file = "black-24.2.0-cp311-cp311-win_amd64.whl", hash = "sha256:9db528bccb9e8e20c08e716b3b09c6bdd64da0dd129b11e160bf082d4642ac23"}, + {file = "black-24.2.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:d84f29eb3ee44859052073b7636533ec995bd0f64e2fb43aeceefc70090e752b"}, + {file = "black-24.2.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:1e08fb9a15c914b81dd734ddd7fb10513016e5ce7e6704bdd5e1251ceee51ac9"}, + {file = "black-24.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:810d445ae6069ce64030c78ff6127cd9cd178a9ac3361435708b907d8a04c693"}, + {file = "black-24.2.0-cp312-cp312-win_amd64.whl", hash = "sha256:ba15742a13de85e9b8f3239c8f807723991fbfae24bad92d34a2b12e81904982"}, + {file = "black-24.2.0-py3-none-any.whl", hash = "sha256:e8a6ae970537e67830776488bca52000eaa37fa63b9988e8c487458d9cd5ace6"}, + {file = "black-24.2.0.tar.gz", hash = "sha256:bce4f25c27c3435e4dace4815bcb2008b87e167e3bf4ee47ccdc5ce906eb4894"}, ] [[package]] @@ -415,7 +415,7 @@ files = [ [[package]] name = "ipykernel" -version = "6.29.1" +version = "6.29.2" requires_python = ">=3.8" summary = "IPython Kernel for Jupyter" dependencies = [ @@ -434,8 +434,8 @@ dependencies = [ "traitlets>=5.4.0", ] files = [ - {file = "ipykernel-6.29.1-py3-none-any.whl", hash = "sha256:e5dfba210fc9da74a5dae8fa6c41f816e11bd18d10381b2517d9a0d57cc987c4"}, - {file = "ipykernel-6.29.1.tar.gz", hash = "sha256:1547352b32da95a2761011a8dac2af930c26a0703dfa07690d16b7d74dac0ba1"}, + {file = "ipykernel-6.29.2-py3-none-any.whl", hash = "sha256:50384f5c577a260a1d53f1f59a828c7266d321c9b7d00d345693783f66616055"}, + {file = "ipykernel-6.29.2.tar.gz", hash = "sha256:3bade28004e3ff624ed57974948116670604ac5f676d12339693f3142176d3f0"}, ] [[package]] @@ -746,6 +746,7 @@ files = [ [[package]] name = "pycparser" version = "2.21" +requires_python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" summary = "C parser in Python" files = [ {file = "pycparser-2.21-py2.py3-none-any.whl", hash = "sha256:8ee45429555515e1f6b185e78100aea234072576aa43ab53aefcae078162fca9"}, diff --git a/psdm/quantities/multi_phase.py b/psdm/quantities/multi_phase.py index 5304771..3c8c751 100644 --- a/psdm/quantities/multi_phase.py +++ b/psdm/quantities/multi_phase.py @@ -153,8 +153,6 @@ def check_unit(cls, v: Unit) -> Unit: class Impedance(MultiPhaseQuantity): """Natural impedance.""" - value: NonEmptyTuple[pydantic.confloat(ge=0)] # type: ignore[valid-type] - precision: int = Precision.IMPEDANCE unit: Unit = Unit.OHM @@ -167,6 +165,21 @@ def check_unit(cls, v: Unit) -> Unit: return v +class Admittance(MultiPhaseQuantity): + """Natural admittance.""" + + precision: int = Precision.ADMITTANCE + unit: Unit = Unit.SIEMENS + + @pydantic.field_validator("unit") + def check_unit(cls, v: Unit) -> Unit: + if v is not Unit.SIEMENS.value: + msg = "Input should be Unit.SIEMENS." + raise ValueError(msg) + + return v + + class Power(MultiPhaseQuantity): """Base class for power quantities. diff --git a/psdm/quantities/single_phase.py b/psdm/quantities/single_phase.py index 06424ae..65ab980 100644 --- a/psdm/quantities/single_phase.py +++ b/psdm/quantities/single_phase.py @@ -108,7 +108,6 @@ class Impedance(SinglePhaseQuantity): """Impedance.""" system_type: SystemType = SystemType.NATURAL - value: pydantic.confloat(ge=0) # type: ignore[valid-type] precision: int = Precision.IMPEDANCE unit: Unit = Unit.OHM @@ -138,7 +137,6 @@ def check_system_type(cls, v: SystemType) -> SystemType: class ImpedanceNegSeq(Impedance): """Negative sequence impedance.""" - value: pydantic.confloat(ge=0) # type: ignore[valid-type] system_type: SystemType = SystemType.NEGATIVE_SEQUENCE @pydantic.field_validator("system_type") @@ -153,7 +151,6 @@ def check_system_type(cls, v: SystemType) -> SystemType: class ImpedanceZerSeq(Impedance): """Zero sequence impedance.""" - value: pydantic.confloat(ge=0) # type: ignore[valid-type] system_type: SystemType = SystemType.ZERO_SEQUENCE @pydantic.field_validator("system_type") @@ -168,7 +165,6 @@ def check_system_type(cls, v: SystemType) -> SystemType: class ImpedanceNat(Impedance): """Natural impedance.""" - value: pydantic.confloat(ge=0) # type: ignore[valid-type] system_type: SystemType = SystemType.NATURAL @pydantic.field_validator("system_type") @@ -183,7 +179,6 @@ def check_system_type(cls, v: SystemType) -> SystemType: class Admittance(SinglePhaseQuantity): """Admittance.""" - value: pydantic.confloat(ge=0) # type: ignore[valid-type] precision: int = Precision.ADMITTANCE unit: Unit = Unit.SIEMENS @@ -199,7 +194,6 @@ def check_unit(cls, v: Unit) -> Unit: class AdmittancePosSeq(Admittance): """Positive sequence admittance.""" - value: pydantic.confloat(ge=0) # type: ignore[valid-type] system_type: SystemType = SystemType.POSITIVE_SEQUENCE @pydantic.field_validator("system_type") @@ -214,7 +208,6 @@ def check_system_type(cls, v: SystemType) -> SystemType: class AdmittanceNegSeq(Admittance): """Negative sequence admittance.""" - value: pydantic.confloat(ge=0) # type: ignore[valid-type] system_type: SystemType = SystemType.NEGATIVE_SEQUENCE @pydantic.field_validator("system_type") @@ -229,7 +222,6 @@ def check_system_type(cls, v: SystemType) -> SystemType: class AdmittanceZerSeq(Admittance): """Zero sequence admittance.""" - value: pydantic.confloat(ge=0) # type: ignore[valid-type] system_type: SystemType = SystemType.ZERO_SEQUENCE @pydantic.field_validator("system_type") From ffd4919926a2580251436c9bf8c0a898000aa75e Mon Sep 17 00:00:00 2001 From: KrahmerTUD Date: Wed, 14 Feb 2024 10:27:28 +0100 Subject: [PATCH 2/2] fix tests --- tests/test_multi_phase_quantities.py | 4 ++-- tests/test_single_phase_quantities.py | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/test_multi_phase_quantities.py b/tests/test_multi_phase_quantities.py index 30ad48b..a9ce4dd 100644 --- a/tests/test_multi_phase_quantities.py +++ b/tests/test_multi_phase_quantities.py @@ -153,9 +153,9 @@ class TestImpedance: ((0, 0, 0), True, does_not_raise()), ((1, 1, 1), True, does_not_raise()), ((2, 1, 1), False, does_not_raise()), + ((-2, 1, 1), False, does_not_raise()), ((1, 1, 1), False, pytest.raises(AssertionError)), - ((-2, 1, 1), True, pytest.raises(pydantic.ValidationError)), - ((-2, 1, 1), False, pytest.raises(pydantic.ValidationError)), + ((-2, 1, 1), True, pytest.raises(AssertionError)), ((2, 1, 1), True, pytest.raises(AssertionError)), ], ) diff --git a/tests/test_single_phase_quantities.py b/tests/test_single_phase_quantities.py index ff0d7c1..a2cae8a 100644 --- a/tests/test_single_phase_quantities.py +++ b/tests/test_single_phase_quantities.py @@ -56,7 +56,7 @@ class TestImpedance: [ (0, does_not_raise()), (1, does_not_raise()), - (-2, pytest.raises(pydantic.ValidationError)), + (-2, does_not_raise()), ], ) def test_init( @@ -68,7 +68,7 @@ def test_init( Impedance(value=value, system_type=SystemType.NATURAL) -class TestImpedancePS: +class TestImpedancePosSeq: @pytest.mark.parametrize( ( "value", @@ -77,7 +77,7 @@ class TestImpedancePS: [ (0, does_not_raise()), (1, does_not_raise()), - (-2, pytest.raises(pydantic.ValidationError)), + (-2, does_not_raise()), ], ) def test_init( @@ -90,7 +90,7 @@ def test_init( assert i.system_type == SystemType.POSITIVE_SEQUENCE.value -class TestImpedanceNS: +class TestImpedanceNegSeq: @pytest.mark.parametrize( ( "value", @@ -99,7 +99,7 @@ class TestImpedanceNS: [ (0, does_not_raise()), (1, does_not_raise()), - (-2, pytest.raises(pydantic.ValidationError)), + (-2, does_not_raise()), ], ) def test_init( @@ -112,7 +112,7 @@ def test_init( assert i.system_type == SystemType.NEGATIVE_SEQUENCE.value -class TestImpedanceZS: +class TestImpedanceZerSeq: @pytest.mark.parametrize( ( "value", @@ -121,7 +121,7 @@ class TestImpedanceZS: [ (0, does_not_raise()), (1, does_not_raise()), - (-2, pytest.raises(pydantic.ValidationError)), + (-2, does_not_raise()), ], ) def test_init( @@ -134,7 +134,7 @@ def test_init( assert i.system_type == SystemType.ZERO_SEQUENCE.value -class TestImpedanceN: +class TestImpedanceNat: @pytest.mark.parametrize( ( "value", @@ -143,7 +143,7 @@ class TestImpedanceN: [ (0, does_not_raise()), (1, does_not_raise()), - (-2, pytest.raises(pydantic.ValidationError)), + (-2, does_not_raise()), ], ) def test_init( @@ -165,7 +165,7 @@ class TestAdmittance: [ (0, does_not_raise()), (1, does_not_raise()), - (-2, pytest.raises(pydantic.ValidationError)), + (-2, does_not_raise()), ], ) def test_init(