99
1010import hashlib
1111from abc import ABC , abstractmethod
12- from typing import TYPE_CHECKING , Any
12+ from typing import Annotated , Any
1313
1414import numpy as np
15+ import pydantic
16+ from pydantic import Field
1517
16- if TYPE_CHECKING :
17- from ..time import ClockType
18+ from ..time import ClockType
1819
1920
2021class EpochSet (ABC ):
@@ -149,7 +150,8 @@ def numepochs(self) -> int:
149150 et , _ = self .epochtable ()
150151 return len (et )
151152
152- def epochclock (self , epoch_number : int ) -> list [ClockType ]:
153+ @pydantic .validate_call
154+ def epochclock (self , epoch_number : Annotated [int , Field (ge = 1 )]) -> list [ClockType ]:
153155 """
154156 Get clock types for an epoch.
155157
@@ -163,13 +165,14 @@ def epochclock(self, epoch_number: int) -> list[ClockType]:
163165 IndexError: If epoch_number is out of range
164166 """
165167 et , _ = self .epochtable ()
166- if epoch_number < 1 or epoch_number > len (et ):
168+ if epoch_number > len (et ):
167169 raise IndexError (f"Epoch { epoch_number } out of range (1..{ len (et )} )" )
168170
169171 entry = et [epoch_number - 1 ]
170172 return entry .get ("epoch_clock" , [])
171173
172- def t0_t1 (self , epoch_number : int ) -> list [tuple [float , float ]]:
174+ @pydantic .validate_call
175+ def t0_t1 (self , epoch_number : Annotated [int , Field (ge = 1 )]) -> list [tuple [float , float ]]:
173176 """
174177 Get time range for an epoch.
175178
@@ -183,13 +186,14 @@ def t0_t1(self, epoch_number: int) -> list[tuple[float, float]]:
183186 IndexError: If epoch_number is out of range
184187 """
185188 et , _ = self .epochtable ()
186- if epoch_number < 1 or epoch_number > len (et ):
189+ if epoch_number > len (et ):
187190 raise IndexError (f"Epoch { epoch_number } out of range (1..{ len (et )} )" )
188191
189192 entry = et [epoch_number - 1 ]
190193 return entry .get ("t0_t1" , [(np .nan , np .nan )])
191194
192- def epochid (self , epoch_number : int ) -> str :
195+ @pydantic .validate_call
196+ def epochid (self , epoch_number : Annotated [int , Field (ge = 1 )]) -> str :
193197 """
194198 Get epoch ID for an epoch number.
195199
@@ -203,11 +207,12 @@ def epochid(self, epoch_number: int) -> str:
203207 IndexError: If epoch_number is out of range
204208 """
205209 et , _ = self .epochtable ()
206- if epoch_number < 1 or epoch_number > len (et ):
210+ if epoch_number > len (et ):
207211 raise IndexError (f"Epoch { epoch_number } out of range (1..{ len (et )} )" )
208212
209213 return et [epoch_number - 1 ].get ("epoch_id" , "" )
210214
215+ @pydantic .validate_call
211216 def epochnumber (self , epoch_id : str ) -> int :
212217 """
213218 Get epoch number for an epoch ID.
@@ -255,7 +260,8 @@ def matchedepochtable(
255260
256261 return matches
257262
258- def epochtableentry (self , epoch_number : int ) -> dict [str , Any ]:
263+ @pydantic .validate_call
264+ def epochtableentry (self , epoch_number : Annotated [int , Field (ge = 1 )]) -> dict [str , Any ]:
259265 """
260266 Get a single epoch table entry.
261267
@@ -269,7 +275,7 @@ def epochtableentry(self, epoch_number: int) -> dict[str, Any]:
269275 IndexError: If epoch_number is out of range
270276 """
271277 et , _ = self .epochtable ()
272- if epoch_number < 1 or epoch_number > len (et ):
278+ if epoch_number > len (et ):
273279 raise IndexError (f"Epoch { epoch_number } out of range (1..{ len (et )} )" )
274280
275281 return et [epoch_number - 1 ]
0 commit comments