Skip to content

Commit

Permalink
Setup: Allow using pydantic 1
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianolorenti committed Jun 14, 2024
1 parent 1672dea commit ef911b6
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 3.0.4
current_version = 3.0.5
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion ceruleo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
CACHE_PATH.mkdir(parents=True, exist_ok=True)


__version__ = "3.0.4"
__version__ = "3.0.5"
4 changes: 3 additions & 1 deletion ceruleo/dataset/analysis/correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from ceruleo.dataset.utils import iterate_over_features
from pydantic import BaseModel

from ceruleo.utils import pydantic_to_dict


class CorrelationAnalysisElement(BaseModel):
mean_correlation: float
Expand All @@ -31,7 +33,7 @@ def get(self, feature_1: str, feature_2: str) -> CorrelationAnalysisElement:
def to_pandas(self) -> pd.DataFrame:
return (
pd.DataFrame.from_dict(
{(k[0], k[1]): v.model_dump() for k, v in self.data.items()},
{(k[0], k[1]): pydantic_to_dict(v) for k, v in self.data.items()},
orient="index",
)
.reset_index()
Expand Down
3 changes: 2 additions & 1 deletion ceruleo/dataset/analysis/sample_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pydantic import BaseModel

from ceruleo.dataset.ts_dataset import AbstractPDMDataset
from ceruleo.utils import pydantic_to_dict

logger = logging.getLogger(__name__)

Expand All @@ -16,7 +17,7 @@ class SampleRateAnalysis(BaseModel):
std: float

def to_pandas(self) -> pd.Series:
return pd.Series(self.model_dump()).to_frame().T
return pd.Series(pydantic_to_dict(self)).to_frame().T


def sample_rate(ds: AbstractPDMDataset, unit: str = "s") -> np.ndarray:
Expand Down
7 changes: 7 additions & 0 deletions ceruleo/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from pydantic import BaseModel, version

def pydantic_to_dict(b:BaseModel):
if version.VERSION.startswith("1"):
return b.dict()
else:
return b.model_dump()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies = [
"antropy >= 0.1.5",
"uncertainties >= 3.1",
"PyWavelets >= 1.3",
"pydantic>=2.6.2",
"pydantic >= 1.0.0,<3.0.0"
]


Expand Down

0 comments on commit ef911b6

Please sign in to comment.