Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove pydantic and numpy deprecated features #6

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading