From 72debe0978208bbf324bfcae6eac4d084b3410f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9ni?= Date: Thu, 16 Jun 2022 19:16:31 +0200 Subject: [PATCH] Add Temporal support in HTable.read (#74) --- CHANGES.rst | 7 +++++++ kanon/tables/htable_reader.py | 7 ++++++- kanon/tables/tests/test_htable_reader.py | 13 ++++++++++++- kanon/utils/types/dishas.py | 6 +++++- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 9f6e4e0..d4dded5 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,10 @@ +0.6.4 +_____ + +*Features* + +- tables : `HTable.read` supports `Temporal` + 0.6.3 _____ diff --git a/kanon/tables/htable_reader.py b/kanon/tables/htable_reader.py index 14e59a1..03bfe22 100644 --- a/kanon/tables/htable_reader.py +++ b/kanon/tables/htable_reader.py @@ -7,7 +7,7 @@ from kanon.models.meta import TableType, models from kanon.tables.symmetries import Symmetry from kanon.units import Historical, Sexagesimal -from kanon.units.definitions import IntegerAndSexagesimal +from kanon.units.definitions import IntegerAndSexagesimal, Temporal from kanon.utils import Sign from kanon.utils.types.dishas import DSymmetry, NumberType, TableContent, UnitType from kanon.utils.types.number_types import Real @@ -58,6 +58,10 @@ def read_historical(values: List[int], shift: int, sign: Sign = 1) -> Historical ) +def read_temporal(values: List[int], shift: int, sign: Sign = 1) -> Temporal: + return sign * (values[0] + Temporal((), values[1:])) + + class NumberReader(Protocol): def __call__(self, values: List[int], shift: int, sign: Sign = 1) -> Real: ... @@ -68,6 +72,7 @@ def __call__(self, values: List[int], shift: int, sign: Sign = 1) -> Real: "floating sexagesimal": read_sexag_array, "integer and sexagesimal": read_intsexag_array, "historical": read_historical, + "temporal": read_temporal, } unit_reader: Dict[UnitType, Unit] = { diff --git a/kanon/tables/tests/test_htable_reader.py b/kanon/tables/tests/test_htable_reader.py index d77de17..5d848fb 100644 --- a/kanon/tables/tests/test_htable_reader.py +++ b/kanon/tables/tests/test_htable_reader.py @@ -1,5 +1,10 @@ -from kanon.tables.htable_reader import read_historical, read_intsexag_array +from kanon.tables.htable_reader import ( + read_historical, + read_intsexag_array, + read_temporal, +) from kanon.units import Historical, IntegerAndSexagesimal +from kanon.units.definitions import Temporal def test_read_historical(): @@ -17,3 +22,9 @@ def test_read_intsexag(): assert read_intsexag_array([1, 12, 0], 2, -1) == IntegerAndSexagesimal("-1; 12, 0") assert read_intsexag_array([0, 12, 0], 2, -1) == IntegerAndSexagesimal("-0; 12, 0") assert read_intsexag_array([121, 12, 0], 2) == IntegerAndSexagesimal("121; 12, 0") + + +def test_read_temporal(): + + assert read_temporal([28, 18, 2, 6], 3, 1) == Temporal("28 ; 18,02,06") + assert read_temporal([253, 18, 2, 6], 3, -1) == Temporal("-253 ; 18,02,06") diff --git a/kanon/utils/types/dishas.py b/kanon/utils/types/dishas.py index 7da9f7c..e09749b 100644 --- a/kanon/utils/types/dishas.py +++ b/kanon/utils/types/dishas.py @@ -11,7 +11,11 @@ class OriginalValue(TypedDict): NumberType = Literal[ - "sexagesimal", "floating sexagesimal", "integer and sexagesimal", "historical" + "sexagesimal", + "floating sexagesimal", + "integer and sexagesimal", + "historical", + "temporal", ] SymmetryType = Literal["mirror", "periodic"] SymmetryOperation = Literal["opposite", "identity", "addition", "substraction"]