Skip to content

Commit

Permalink
Remove pydantic and numpy deprecated features
Browse files Browse the repository at this point in the history
  • Loading branch information
justinvasel committed Aug 16, 2024
1 parent 23cdcd1 commit d5264ff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
28 changes: 10 additions & 18 deletions snews/models/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

# Third-party modules
import numpy as np
from pydantic import (BaseModel, Field, NonNegativeFloat, ValidationError,
field_validator, model_validator)
from pydantic import (BaseModel, ConfigDict, Field, NonNegativeFloat,
ValidationError, field_validator, model_validator)

# Local modules
from ..__version__ import schema_version
Expand Down Expand Up @@ -61,8 +61,7 @@ class MessageBase(BaseModel):
Base class for all messages.
"""

class Config:
validate_assignment = True
model_config = ConfigDict(validate_assignment=True)

id: Optional[str] = Field(
default=None,
Expand Down Expand Up @@ -174,8 +173,7 @@ class DetectorMessageBase(MessageBase):
Base class for all messages related to a specific detector.
"""

class Config:
validate_assignment = True
model_config = ConfigDict(validate_assignment=True)

detector_name: str = Field(
...,
Expand All @@ -200,8 +198,7 @@ class HeartbeatMessage(DetectorMessageBase):
Heartbeat detector message.
"""

class Config:
validate_assignment = True
model_config = ConfigDict(validate_assignment=True)

detector_status: str = Field(
...,
Expand Down Expand Up @@ -233,8 +230,7 @@ class RetractionMessage(DetectorMessageBase):
Retraction detector message.
"""

class Config:
validate_assignment = True
model_config = ConfigDict(validate_assignment=True)

retract_message_uid: Optional[str] = Field(
default=None,
Expand Down Expand Up @@ -275,8 +271,7 @@ class TierMessageBase(DetectorMessageBase):
Tier base message
"""

class Config:
validate_assignment = True
model_config = ConfigDict(validate_assignment=True)

p_val: Optional[NonNegativeFloat] = Field(
default=None,
Expand All @@ -297,8 +292,7 @@ class TimingTierMessage(TierMessageBase):
Timing tier detector message.
"""

class Config:
validate_assignment = True
model_config = ConfigDict(validate_assignment=True)

timing_series: List[Union[str, int]] = Field(
...,
Expand Down Expand Up @@ -331,8 +325,7 @@ class SignificanceTierMessage(TierMessageBase):
Significance tier detector message.
"""

class Config:
validate_assignment = True
model_config = ConfigDict(validate_assignment=True)

p_values: List[NonNegativeFloat] = Field(
...,
Expand Down Expand Up @@ -373,8 +366,7 @@ class CoincidenceTierMessage(TierMessageBase):
Coincidence tier detector message.
"""

class Config:
validate_assignment = True
model_config = ConfigDict(validate_assignment=True)

neutrino_time_utc: str = Field(
...,
Expand Down
13 changes: 7 additions & 6 deletions snews/models/timing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# Third party imports
import numpy as np
from pydantic import BaseModel, Field, field_validator
from pydantic import BaseModel, ConfigDict, Field, field_validator

# Local imports
from ..data.utilities import num_leap_seconds_between
Expand All @@ -30,8 +30,7 @@ class PrecisionTimestamp(BaseModel, arbitrary_types_allowed=True):
Supported values: "s", "ms", "us", "ns".
"""

class Config:
validate_assignment = True
model_config = ConfigDict(validate_assignment=True)

timestamp: Optional[Union[np.datetime64, datetime, str]] = Field(
default_factory=lambda: datetime.now(UTC),
Expand Down Expand Up @@ -61,12 +60,14 @@ def to_datetime(self):

@field_validator("timestamp")
def _validate_and_cast_timestamp(cls, v):
if isinstance(v, datetime) and v.tzinfo is not None:
v = v.replace(tzinfo=None)

if not isinstance(v, np.datetime64):
print(v)
v = np.datetime64(v)
return v

if isinstance(v, np.datetime64):
return v
return v

def __sub__(self, other) -> np.timedelta64:
if isinstance(other, PrecisionTimestamp):
Expand Down

0 comments on commit d5264ff

Please sign in to comment.