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

chore: drop pydantic v1 support #697

Merged
merged 3 commits into from
Jan 17, 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
25 changes: 0 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ jobs:
python-version:
- "3.10"
- "3.11"
pydantic-version:
- "^1.10"
- "^2.0"

steps:
- uses: actions/checkout@v4
Expand All @@ -24,15 +21,6 @@ jobs:
- name: install_system_deps
run: sudo make install_system_deps

- name: Update Pydantic version on the toml & lock
run: |
pip install -U pip poetry
# we update the pydantic version corresponding to the matrix
sed -i "s/pydantic = \".*\"/pydantic = \"${PYDANTIC_VERSION}\"/" pyproject.toml
poetry lock --no-update
env:
PYDANTIC_VERSION: ${{ matrix.pydantic-version }}

- name: install
run: make install

Expand All @@ -49,9 +37,6 @@ jobs:
python-version:
- "3.10"
- "3.11"
pydantic-version:
- "^1.10"
- "^2.0"

steps:
- uses: actions/checkout@v4
Expand All @@ -63,23 +48,13 @@ jobs:
- name: install_system_deps
run: sudo make install_system_deps

- name: Update Pydantic version on the toml & lock
run: |
pip install -U pip poetry
# we update the pydantic version corresponding to the matrix
sed -i "s/pydantic = \".*\"/pydantic = \"${PYDANTIC_VERSION}\"/" pyproject.toml
poetry lock --no-update
env:
PYDANTIC_VERSION: ${{ matrix.pydantic-version }}

- name: install
run: make install

- name: test
run: make test
env:
FTP_PATH: ${{ secrets.FTP_PATH }}
PYDANTIC_VERSION: ${{ matrix.pydantic-version }}

- name: Upload coverage
uses: codecov/codecov-action@v3
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### Changed

- Drop support for pydantic V1.

## [0.12.1] - 2023-11-15

### Fixed
Expand Down
37 changes: 9 additions & 28 deletions peakina/datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from urllib.parse import urlparse, uses_netloc, uses_params, uses_relative

import pandas as pd
from pydantic import ConfigDict, __version__ as pydantic_version
from pydantic import ConfigDict
from pydantic.dataclasses import dataclass
from slugify import slugify

Expand All @@ -36,9 +36,6 @@
PD_VALID_URLS = set(uses_relative + uses_netloc + uses_params) | AVAILABLE_SCHEMES


_PYDANTIC_VERSION_ONE = pydantic_version.startswith("1.")


@dataclass
class DataSource:
uri: str
Expand All @@ -48,33 +45,17 @@ class DataSource:
reader_kwargs: dict[str, Any] = field(default_factory=dict)
fetcher_kwargs: dict[str, Any] = field(default_factory=dict)

# TODO: This is temporary, in the future we will only support V2
# and get rid of this condition + update the CI (link/test)
if _PYDANTIC_VERSION_ONE:

def __post_init_post_parse__(self) -> None:
self._fetcher: Fetcher | None = None
self.scheme = urlparse(self.uri).scheme
if self.scheme not in PD_VALID_URLS:
raise AttributeError(f"Invalid scheme {self.scheme!r}")

self.type = self.type or detect_type(urlparse(self.uri).path, is_regex=bool(self.match))

validate_kwargs(self.reader_kwargs, self.type)

else:

def __post_init__(self) -> None:
self._fetcher: Fetcher | None = None # type: ignore[no-redef]
self.scheme = urlparse(self.uri).scheme
if self.scheme not in PD_VALID_URLS:
raise AttributeError(f"Invalid scheme {self.scheme!r}")
def __post_init__(self) -> None:
self._fetcher: Fetcher | None = None
self.scheme = urlparse(self.uri).scheme
if self.scheme not in PD_VALID_URLS:
raise AttributeError(f"Invalid scheme {self.scheme!r}")

self.type = self.type or detect_type(urlparse(self.uri).path, is_regex=bool(self.match))
self.type = self.type or detect_type(urlparse(self.uri).path, is_regex=bool(self.match))

validate_kwargs(self.reader_kwargs, self.type)
validate_kwargs(self.reader_kwargs, self.type)

model_config = ConfigDict(arbitrary_types_allowed=True)
model_config = ConfigDict(arbitrary_types_allowed=True)

@property
def fetcher(self) -> Fetcher:
Expand Down
3 changes: 2 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ chardet = ">=4,<6"
jq = "^1.2.1"
pandas = ">=1.5.3,<3.0.0"
paramiko = ">=2.9.2,<4.0.0"
pydantic = ">=1.9,<3.0"
pydantic = "^2.4.2"
python-slugify = ">=5.0.2,<9.0.0"
s3fs = ">=2022.1,<2024.0"
tables = "^3.7.0"
Expand Down
Loading