|
1 | 1 | from __future__ import annotations
|
2 |
| -from pydantic import BaseModel |
| 2 | + |
| 3 | +import inspect |
| 4 | +import random |
| 5 | +import string |
| 6 | +import textwrap |
| 7 | +from functools import lru_cache |
| 8 | +from pathlib import Path |
3 | 9 | from typing import (
|
4 |
| - Tuple, |
5 | 10 | Callable,
|
6 |
| - Union, |
7 |
| - List, |
8 |
| - TypeVar, |
9 |
| - Generic, |
10 | 11 | Dict,
|
11 |
| - Optional, |
| 12 | + Generic, |
12 | 13 | Iterable,
|
| 14 | + List, |
| 15 | + Optional, |
| 16 | + Tuple, |
| 17 | + TypeVar, |
| 18 | + Union, |
13 | 19 | )
|
14 |
| -from pathlib import Path |
15 |
| -from functools import lru_cache |
16 |
| -import string |
17 |
| -import random |
18 |
| -import textwrap |
19 |
| -import inspect |
| 20 | + |
20 | 21 | import numpy as np
|
21 | 22 | import pandas as pd
|
22 |
| -from datastream import tools |
| 23 | +from pydantic import BaseModel, ConfigDict |
23 | 24 |
|
| 25 | +from datastream import tools |
24 | 26 |
|
25 | 27 | T = TypeVar("T")
|
26 | 28 | R = TypeVar("R")
|
@@ -53,9 +55,10 @@ class Dataset(BaseModel, Generic[T]):
|
53 | 55 | length: int
|
54 | 56 | get_item: Callable[[pd.DataFrame, int], T]
|
55 | 57 |
|
56 |
| - class Config: |
57 |
| - arbitrary_types_allowed = True |
58 |
| - allow_mutation = False |
| 58 | + model_config = ConfigDict( |
| 59 | + arbitrary_types_allowed=True, |
| 60 | + frozen=True, |
| 61 | + ) |
59 | 62 |
|
60 | 63 | @staticmethod
|
61 | 64 | def from_subscriptable(subscriptable) -> Dataset:
|
@@ -96,7 +99,7 @@ def from_dataframe(dataframe: pd.DataFrame) -> Dataset[pd.Series]:
|
96 | 99 |
|
97 | 100 | @staticmethod
|
98 | 101 | def from_paths(paths: Iterable[str, Path], pattern: str) -> Dataset[pd.Series]:
|
99 |
| - """ |
| 102 | + r""" |
100 | 103 | Create ``Dataset`` from paths using regex pattern that extracts information
|
101 | 104 | from the path itself.
|
102 | 105 | :func:`Dataset.__getitem__` will return a row from the dataframe and
|
@@ -154,7 +157,7 @@ def __eq__(self: Dataset[T], other: Dataset[R]) -> bool:
|
154 | 157 | return True
|
155 | 158 |
|
156 | 159 | def replace(self, **kwargs):
|
157 |
| - new_dict = self.dict() |
| 160 | + new_dict = self.model_dump() |
158 | 161 | new_dict.update(**kwargs)
|
159 | 162 | return type(self)(**new_dict)
|
160 | 163 |
|
|
0 commit comments