Skip to content

Commit

Permalink
Add Temporal support in HTable.read (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
legau authored Jun 16, 2022
1 parent ce44ba8 commit 72debe0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
0.6.4
_____

*Features*

- tables : `HTable.read` supports `Temporal`

0.6.3
_____

Expand Down
7 changes: 6 additions & 1 deletion kanon/tables/htable_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
...
Expand All @@ -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] = {
Expand Down
13 changes: 12 additions & 1 deletion kanon/tables/tests/test_htable_reader.py
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -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")
6 changes: 5 additions & 1 deletion kanon/utils/types/dishas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 72debe0

Please sign in to comment.