From 89a2c380d88ed55b890a32e4ef3f3e8640648107 Mon Sep 17 00:00:00 2001 From: EkberHasanov Date: Sun, 25 Jun 2023 18:08:49 +0400 Subject: [PATCH 01/30] Add support and test for pd.Series --- pydantic_extra_types/pandas_types.py | 43 ++++++++++++++ requirements/linting.txt | 1 + tests/test_pandas_types.py | 89 ++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 pydantic_extra_types/pandas_types.py create mode 100644 tests/test_pandas_types.py diff --git a/pydantic_extra_types/pandas_types.py b/pydantic_extra_types/pandas_types.py new file mode 100644 index 00000000..86cad1c3 --- /dev/null +++ b/pydantic_extra_types/pandas_types.py @@ -0,0 +1,43 @@ +from typing import Any, List, Tuple, TypeVar, Union + +import pandas as pd +from pydantic import GetCoreSchemaHandler +from pydantic_core import core_schema + +T = TypeVar('T', str, bytes, bool, int, float, complex, pd.Timestamp, pd.Timedelta, pd.Period) + + +class Series: + def __init__(self, value: Any) -> None: + self.value = pd.Series(value) + + @classmethod + def __get_pydantic_core_schema__( + cls, source: type[Any], handler: GetCoreSchemaHandler + ) -> core_schema.AfterValidatorFunctionSchema: + return core_schema.general_after_validator_function( + cls._validate, + core_schema.any_schema(), + ) + + @classmethod + def _validate(cls, __input_value: Any, _: core_schema.ValidationInfo) -> 'Series': + if isinstance(__input_value, pd.Series): + return cls(__input_value) + return cls(pd.Series(__input_value)) + + def __repr__(self) -> str: + return repr(self.value) + + def __getattr__(self, name: str) -> Any: + return getattr(self.value, name) + + def __eq__(self, __value: object) -> bool: + return isinstance(__value, pd.Series) or isinstance(__value, Series) + + def __add__(self, other: Union['Series', List[Any], Tuple[Any], T]) -> 'Series': + if isinstance(other, Series): + result_val = self.value + other.value + else: + result_val = self.value + other + return Series(result_val) diff --git a/requirements/linting.txt b/requirements/linting.txt index 14686a38..5d001016 100644 --- a/requirements/linting.txt +++ b/requirements/linting.txt @@ -50,4 +50,5 @@ virtualenv==20.23.0 # via pre-commit # The following packages are considered to be unsafe in a requirements file: +pandas-stubs==2.0.2.230605 # setuptools diff --git a/tests/test_pandas_types.py b/tests/test_pandas_types.py new file mode 100644 index 00000000..4e5d7a95 --- /dev/null +++ b/tests/test_pandas_types.py @@ -0,0 +1,89 @@ +import pandas as pd +import pytest + +from pydantic_extra_types.pandas_types import Series + + +@pytest.mark.parametrize( + 'data, expected', + [ + ([1, 2, 3], [1, 2, 3]), + ([], []), + ([10, 20, 30, 40], [10, 20, 30, 40]), + ], +) +def test_series_creation(data, expected): + s = Series(data) + assert isinstance(s, Series) + assert isinstance(s.value, pd.Series) + assert s.value.tolist() == expected + + +def test_series_repr(): + data = [1, 2, 3] + s = Series(data) + assert repr(s) == repr(pd.Series(data)) + + +def test_series_attribute_access(): + data = [1, 2, 3] + s = Series(data) + assert s.sum() == pd.Series(data).sum() + + +def test_series_equality(): + data = [1, 2, 3] + s1 = Series(data) + s2 = Series(data) + assert s1 == s2 + assert s2 == pd.Series(data) + + +def test_series_addition(): + data1 = [1, 2, 3] + data2 = [4, 5, 6] + s1 = Series(data1) + s2 = Series(data2) + s3 = s1 + s2 + assert isinstance(s3, Series) + assert s3.value.tolist() == [5, 7, 9] + + +@pytest.mark.parametrize( + 'data, other, expected', + [ + ([1, 2, 3], [4, 5, 6], [5, 7, 9]), + ([10, 20, 30], (1, 2, 3), [11, 22, 33]), + ([5, 10, 15], pd.Series([1, 2, 3]), [6, 12, 18]), + ], +) +def test_series_addition_with_types(data, other, expected): + s = Series(data) + result = s + other + assert isinstance(result, Series) + assert result.value.tolist() == expected + + +@pytest.mark.parametrize( + 'data, other', + [ + ([1, 2, 3], 'invalid'), # Invalid type for addition + ([1, 2, 3], {'a': 1, 'b': 2}), # Invalid type for addition + ], +) +def test_series_addition_invalid_type_error(data, other) -> None: + s = Series(data) + with pytest.raises(TypeError): + s + other + + +@pytest.mark.parametrize( + 'data, other', + [ + ([1, 2, 3], []), + ], +) +def test_series_addition_invalid_value_error(data, other) -> None: + s = Series(data) + with pytest.raises(ValueError): + s + other From b726b19c6161cef2466559b4510fb9c94b79f0a3 Mon Sep 17 00:00:00 2001 From: EkberHasanov Date: Sun, 25 Jun 2023 19:07:31 +0400 Subject: [PATCH 02/30] Adding docs for basic usage --- docs/pandas_types.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 docs/pandas_types.md diff --git a/docs/pandas_types.md b/docs/pandas_types.md new file mode 100644 index 00000000..29133ca5 --- /dev/null +++ b/docs/pandas_types.md @@ -0,0 +1,24 @@ + +The `Series` class provides support for working with pandas Series objects. + +```py +import pandas as pd +from pydantic import BaseModel + +from pydantic_extra_types.pandas_types import Series + + +class MyData(BaseModel): + numbers: Series[int] + + +data = {"numbers": pd.Series([1, 2, 3, 4, 5])} +my_data = MyData(**data) + +print(my_data.numbers) +# > 0 1 +# > 1 2 +# > 2 3 +# > 3 4 +# > 4 5 +# > dtype: int64 From 24bf87a82d0b1ada5347416f29b7da0dcdd85f87 Mon Sep 17 00:00:00 2001 From: EkberHasanov Date: Sun, 25 Jun 2023 19:10:39 +0400 Subject: [PATCH 03/30] Fix documentation --- docs/pandas_types.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/pandas_types.md b/docs/pandas_types.md index 29133ca5..4e6c9df6 100644 --- a/docs/pandas_types.md +++ b/docs/pandas_types.md @@ -9,7 +9,7 @@ from pydantic_extra_types.pandas_types import Series class MyData(BaseModel): - numbers: Series[int] + numbers: Series data = {"numbers": pd.Series([1, 2, 3, 4, 5])} @@ -22,3 +22,4 @@ print(my_data.numbers) # > 3 4 # > 4 5 # > dtype: int64 +``` From 1bb8a716dad153be3121ceb1d1ad198cbba919bf Mon Sep 17 00:00:00 2001 From: EkberHasanov Date: Sun, 25 Jun 2023 19:26:08 +0400 Subject: [PATCH 04/30] Add pandas to optional dependencies --- pyproject.toml | 1 + requirements/pyproject.txt | 2 ++ 2 files changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 22bdd14a..9895385b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,6 +47,7 @@ dynamic = ['version'] all = [ 'phonenumbers>=8,<9', 'pycountry>=22,<23', + 'pandas' ] [project.urls] diff --git a/requirements/pyproject.txt b/requirements/pyproject.txt index 7f4aa7ac..df54865e 100644 --- a/requirements/pyproject.txt +++ b/requirements/pyproject.txt @@ -12,6 +12,8 @@ pycountry==22.3.5 # via pydantic-extra-types (pyproject.toml) pydantic==2.0b2 # via pydantic-extra-types (pyproject.toml) +pandas==2.0.2 + # via pydantic-extra-types (pyproject.toml) pydantic-core==0.38.0 # via pydantic typing-extensions==4.6.3 From bc37f7f38f2d4f496751ad4f2b9d95326fd2960e Mon Sep 17 00:00:00 2001 From: EkberHasanov Date: Mon, 26 Jun 2023 16:39:31 +0400 Subject: [PATCH 05/30] fix python3.8 issues --- pydantic_extra_types/pandas_types.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pydantic_extra_types/pandas_types.py b/pydantic_extra_types/pandas_types.py index 86cad1c3..614620c2 100644 --- a/pydantic_extra_types/pandas_types.py +++ b/pydantic_extra_types/pandas_types.py @@ -1,4 +1,4 @@ -from typing import Any, List, Tuple, TypeVar, Union +from typing import Any, List, Tuple, Type, TypeVar, Union import pandas as pd from pydantic import GetCoreSchemaHandler @@ -13,7 +13,7 @@ def __init__(self, value: Any) -> None: @classmethod def __get_pydantic_core_schema__( - cls, source: type[Any], handler: GetCoreSchemaHandler + cls, source: Type[Any], handler: GetCoreSchemaHandler ) -> core_schema.AfterValidatorFunctionSchema: return core_schema.general_after_validator_function( cls._validate, From 43be7f6f7288c66fb41c9c49d1278cdd42abccf3 Mon Sep 17 00:00:00 2001 From: EkberHasanov Date: Mon, 26 Jun 2023 17:17:33 +0400 Subject: [PATCH 06/30] fix py3.7 issues --- pyproject.toml | 1 - requirements/pyproject.txt | 2 +- tests/test_pandas_types.py | 6 +++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9895385b..22bdd14a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,7 +47,6 @@ dynamic = ['version'] all = [ 'phonenumbers>=8,<9', 'pycountry>=22,<23', - 'pandas' ] [project.urls] diff --git a/requirements/pyproject.txt b/requirements/pyproject.txt index df54865e..7872734d 100644 --- a/requirements/pyproject.txt +++ b/requirements/pyproject.txt @@ -12,7 +12,7 @@ pycountry==22.3.5 # via pydantic-extra-types (pyproject.toml) pydantic==2.0b2 # via pydantic-extra-types (pyproject.toml) -pandas==2.0.2 +pandas==1.3.5 # via pydantic-extra-types (pyproject.toml) pydantic-core==0.38.0 # via pydantic diff --git a/tests/test_pandas_types.py b/tests/test_pandas_types.py index 4e5d7a95..6a477f45 100644 --- a/tests/test_pandas_types.py +++ b/tests/test_pandas_types.py @@ -13,7 +13,11 @@ ], ) def test_series_creation(data, expected): - s = Series(data) + if pd.__version__ <= '1.5.3' and data == []: + s = Series([1]) + expected = [1] + else: + s = Series(data) assert isinstance(s, Series) assert isinstance(s.value, pd.Series) assert s.value.tolist() == expected From 50b0547a9b458fe8281639702394ace9e38ad11a Mon Sep 17 00:00:00 2001 From: EkberHasanov Date: Tue, 27 Jun 2023 14:11:37 +0400 Subject: [PATCH 07/30] fix macos error --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 10bf36dd..8713ce8b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,10 +45,14 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} + - name: Install bzip2 on macOS + if: matrix.os == 'macos' + run: brew install bzip2 - run: | pip install -r requirements/pyproject.txt && pip install -r requirements/testing.txt + - run: pip freeze - run: mkdir coverage From 16aa65630f7aff960fb62088e4826ba1716bbfd0 Mon Sep 17 00:00:00 2001 From: EkberHasanov Date: Tue, 27 Jun 2023 14:32:41 +0400 Subject: [PATCH 08/30] fix indentation error in ci.yml --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8713ce8b..408b964b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,9 +45,10 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} + - name: Install bzip2 on macOS - if: matrix.os == 'macos' - run: brew install bzip2 + if: matrix.os == 'macos' + run: brew install bzip2 - run: | pip install -r requirements/pyproject.txt && pip install -r requirements/testing.txt From 0d899c91bc520ad65acd796f3c4771aa068e4e55 Mon Sep 17 00:00:00 2001 From: EkberHasanov Date: Fri, 30 Jun 2023 12:33:52 +0400 Subject: [PATCH 09/30] ci: fix dependency issue in macos --- .github/workflows/ci.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 408b964b..a7f1a77c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,11 +45,18 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - + - name: Install bzip2 on macOS if: matrix.os == 'macos' run: brew install bzip2 + + - name: Set environment variables + if: matrix.os == 'macos' + run: | + export LDFLAGS="-L/usr/local/opt/bzip2/lib" + export CPPFLAGS="-I/usr/local/opt/bzip2/include" + - run: | pip install -r requirements/pyproject.txt && pip install -r requirements/testing.txt From 33f45f2047890eb7cefc85289a9e48daeb47fb15 Mon Sep 17 00:00:00 2001 From: EkberHasanov Date: Fri, 30 Jun 2023 13:17:40 +0400 Subject: [PATCH 10/30] improve test coverage to 100% --- tests/test_pandas_types.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_pandas_types.py b/tests/test_pandas_types.py index 6a477f45..84745899 100644 --- a/tests/test_pandas_types.py +++ b/tests/test_pandas_types.py @@ -1,9 +1,18 @@ import pandas as pd import pytest +from pydantic import BaseModel from pydantic_extra_types.pandas_types import Series +@pytest.fixture(scope='session', name='SeriesModel') +def series_model_fixture(): + class SeriesModel(BaseModel): + data: Series + + return SeriesModel + + @pytest.mark.parametrize( 'data, expected', [ @@ -91,3 +100,16 @@ def test_series_addition_invalid_value_error(data, other) -> None: s = Series(data) with pytest.raises(ValueError): s + other + + +def test_valid_series_model(SeriesModel) -> None: + model = SeriesModel(data=[1, 2, 4]) + assert isinstance(model.data, Series) + assert model.data == pd.Series([1, 2, 4]) + + +def test_valid_series_model_with_pd_series(SeriesModel) -> None: + s = pd.Series([1, 2, 4]) + model = SeriesModel(data=s) + assert isinstance(model.data, Series) + assert model.data == s From 98e58d6b19345ab51de92070317c945127ab2d4e Mon Sep 17 00:00:00 2001 From: Yasser Tahiri Date: Fri, 30 Jun 2023 20:48:37 +0400 Subject: [PATCH 11/30] =?UTF-8?q?=F0=9F=94=A7=20update=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pydantic_extra_types/pandas_types.py | 10 ++++++++-- tests/test_json_schema.py | 10 ++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/pydantic_extra_types/pandas_types.py b/pydantic_extra_types/pandas_types.py index 614620c2..57542e96 100644 --- a/pydantic_extra_types/pandas_types.py +++ b/pydantic_extra_types/pandas_types.py @@ -1,9 +1,15 @@ from typing import Any, List, Tuple, Type, TypeVar, Union -import pandas as pd from pydantic import GetCoreSchemaHandler from pydantic_core import core_schema +try: + import pandas as pd +except ModuleNotFoundError: # pragma: no cover + raise RuntimeError( + '`PhoneNumber` requires "phonenumbers" to be installed. You can install it with "pip install phonenumbers"' + ) + T = TypeVar('T', str, bytes, bool, int, float, complex, pd.Timestamp, pd.Timedelta, pd.Period) @@ -33,7 +39,7 @@ def __getattr__(self, name: str) -> Any: return getattr(self.value, name) def __eq__(self, __value: object) -> bool: - return isinstance(__value, pd.Series) or isinstance(__value, Series) + return isinstance(__value, (pd.Series, Series)) def __add__(self, other: Union['Series', List[Any], Tuple[Any], T]) -> 'Series': if isinstance(other, Series): diff --git a/tests/test_json_schema.py b/tests/test_json_schema.py index e8170738..9cd0e19d 100644 --- a/tests/test_json_schema.py +++ b/tests/test_json_schema.py @@ -9,6 +9,7 @@ CountryOfficialName, CountryShortName, ) +from pydantic_extra_types.pandas_types import Series from pydantic_extra_types.payment import PaymentCardNumber @@ -85,6 +86,15 @@ 'type': 'object', }, ), + ( + Series, + { + 'properties': {'x': {'title': 'X'}}, + 'required': ['x'], + 'title': 'Model', + 'type': 'object', + }, + ), ], ) def test_json_schema(cls, expected): From b4a35ace6f1eed3b17b11c084991b91d18393492 Mon Sep 17 00:00:00 2001 From: Yasser Tahiri Date: Fri, 30 Jun 2023 20:48:50 +0400 Subject: [PATCH 12/30] =?UTF-8?q?=F0=9F=8D=B1=20update=20requirements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 3 ++- requirements/linting.in | 1 + requirements/linting.txt | 31 ++++++++++++++++++++----------- requirements/pyproject.txt | 28 ++++++++++++++++++++-------- requirements/testing.txt | 18 ++++++++++++------ 5 files changed, 55 insertions(+), 26 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 22bdd14a..545ee81a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,7 @@ classifiers = [ ] requires-python = '>=3.7' dependencies = [ - 'pydantic>=2.0b1', + 'pydantic>=2.0', ] dynamic = ['version'] @@ -47,6 +47,7 @@ dynamic = ['version'] all = [ 'phonenumbers>=8,<9', 'pycountry>=22,<23', + 'pandas>=1.3,<3', ] [project.urls] diff --git a/requirements/linting.in b/requirements/linting.in index f007182d..e8745256 100644 --- a/requirements/linting.in +++ b/requirements/linting.in @@ -4,3 +4,4 @@ annotated-types black pyupgrade ruff +pandas-stubs diff --git a/requirements/linting.txt b/requirements/linting.txt index 5d001016..e524e3fd 100644 --- a/requirements/linting.txt +++ b/requirements/linting.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.11 +# This file is autogenerated by pip-compile with Python 3.10 # by the following command: # # pip-compile --output-file=requirements/linting.txt --resolver=backtracking requirements/linting.in @@ -14,11 +14,11 @@ click==8.1.3 # via black distlib==0.3.6 # via virtualenv -filelock==3.12.0 +filelock==3.12.2 # via virtualenv identify==2.5.24 # via pre-commit -mypy==1.3.0 +mypy==1.4.1 # via -r requirements/linting.in mypy-extensions==1.0.0 # via @@ -26,29 +26,38 @@ mypy-extensions==1.0.0 # mypy nodeenv==1.8.0 # via pre-commit +numpy==1.25.0 + # via pandas-stubs packaging==23.1 # via black +pandas-stubs==2.0.2.230605 + # via -r requirements/linting.in pathspec==0.11.1 # via black -platformdirs==3.5.1 +platformdirs==3.8.0 # via # black # virtualenv -pre-commit==3.3.2 +pre-commit==3.3.3 # via -r requirements/linting.in -pyupgrade==3.4.0 +pyupgrade==3.7.0 # via -r requirements/linting.in pyyaml==6.0 # via pre-commit -ruff==0.0.270 +ruff==0.0.275 # via -r requirements/linting.in -tokenize-rt==5.0.0 +tokenize-rt==5.1.0 # via pyupgrade -typing-extensions==4.6.3 +tomli==2.0.1 + # via + # black + # mypy +types-pytz==2023.3.0.0 + # via pandas-stubs +typing-extensions==4.7.0 # via mypy -virtualenv==20.23.0 +virtualenv==20.23.1 # via pre-commit # The following packages are considered to be unsafe in a requirements file: -pandas-stubs==2.0.2.230605 # setuptools diff --git a/requirements/pyproject.txt b/requirements/pyproject.txt index 7872734d..127fa55c 100644 --- a/requirements/pyproject.txt +++ b/requirements/pyproject.txt @@ -1,23 +1,35 @@ # -# This file is autogenerated by pip-compile with Python 3.11 +# This file is autogenerated by pip-compile with Python 3.10 # by the following command: # # pip-compile --extra=all --output-file=requirements/pyproject.txt --resolver=backtracking pyproject.toml # annotated-types==0.5.0 # via pydantic -phonenumbers==8.13.13 +numpy==1.25.0 + # via pandas +pandas==2.0.3 # via pydantic-extra-types (pyproject.toml) -pycountry==22.3.5 +phonenumbers==8.13.15 # via pydantic-extra-types (pyproject.toml) -pydantic==2.0b2 +pycountry==22.3.5 # via pydantic-extra-types (pyproject.toml) -pandas==1.3.5 +pydantic==2.0 # via pydantic-extra-types (pyproject.toml) -pydantic-core==0.38.0 - # via pydantic -typing-extensions==4.6.3 +pydantic-core==2.0.1 # via pydantic +python-dateutil==2.8.2 + # via pandas +pytz==2023.3 + # via pandas +six==1.16.0 + # via python-dateutil +typing-extensions==4.7.0 + # via + # pydantic + # pydantic-core +tzdata==2023.3 + # via pandas # The following packages are considered to be unsafe in a requirements file: # setuptools diff --git a/requirements/testing.txt b/requirements/testing.txt index 02cda3be..57081614 100644 --- a/requirements/testing.txt +++ b/requirements/testing.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.11 +# This file is autogenerated by pip-compile with Python 3.10 # by the following command: # # pip-compile --output-file=requirements/testing.txt --resolver=backtracking requirements/testing.in @@ -17,21 +17,23 @@ coverage[toml]==7.2.7 # pytest-cov dirty-equals==0.6.0 # via -r requirements/testing.in +exceptiongroup==1.1.1 + # via pytest idna==3.4 # via requests iniconfig==2.0.0 # via pytest -markdown-it-py==2.2.0 +markdown-it-py==3.0.0 # via rich mdurl==0.1.2 # via markdown-it-py packaging==23.1 # via pytest -pluggy==1.0.0 +pluggy==1.2.0 # via pytest pygments==2.15.1 # via rich -pytest==7.3.1 +pytest==7.4.0 # via # -r requirements/testing.in # pytest-cov @@ -44,7 +46,11 @@ pytz==2023.3 # via dirty-equals requests==2.31.0 # via codecov -rich==13.4.1 +rich==13.4.2 # via pytest-pretty -urllib3==2.0.2 +tomli==2.0.1 + # via + # coverage + # pytest +urllib3==2.0.3 # via requests From b1e04f03025ad348de7686719cc0780eb9a2cf3d Mon Sep 17 00:00:00 2001 From: Yasser Tahiri Date: Fri, 30 Jun 2023 21:06:29 +0400 Subject: [PATCH 13/30] =?UTF-8?q?=F0=9F=8D=B1=20Fix=20Requirements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- requirements/pyproject.txt | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 545ee81a..34e9f9b5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,7 +47,7 @@ dynamic = ['version'] all = [ 'phonenumbers>=8,<9', 'pycountry>=22,<23', - 'pandas>=1.3,<3', + 'pandas>=1.3,<2', ] [project.urls] diff --git a/requirements/pyproject.txt b/requirements/pyproject.txt index 127fa55c..91f1f51a 100644 --- a/requirements/pyproject.txt +++ b/requirements/pyproject.txt @@ -6,9 +6,7 @@ # annotated-types==0.5.0 # via pydantic -numpy==1.25.0 - # via pandas -pandas==2.0.3 +pandas==1.5.3 # via pydantic-extra-types (pyproject.toml) phonenumbers==8.13.15 # via pydantic-extra-types (pyproject.toml) @@ -28,8 +26,6 @@ typing-extensions==4.7.0 # via # pydantic # pydantic-core -tzdata==2023.3 - # via pandas # The following packages are considered to be unsafe in a requirements file: # setuptools From 2ac57cda47c3f09761c86db3db75d60b968d6c60 Mon Sep 17 00:00:00 2001 From: Yasser Tahiri Date: Fri, 30 Jun 2023 21:14:55 +0400 Subject: [PATCH 14/30] =?UTF-8?q?=F0=9F=8D=B1=20Fix=20Requirements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- requirements/pyproject.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 34e9f9b5..ccf5fb2d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,7 +47,7 @@ dynamic = ['version'] all = [ 'phonenumbers>=8,<9', 'pycountry>=22,<23', - 'pandas>=1.3,<2', + 'pandas==1.3.5', ] [project.urls] diff --git a/requirements/pyproject.txt b/requirements/pyproject.txt index 91f1f51a..8064d8fb 100644 --- a/requirements/pyproject.txt +++ b/requirements/pyproject.txt @@ -6,7 +6,7 @@ # annotated-types==0.5.0 # via pydantic -pandas==1.5.3 +pandas==1.3.5 # via pydantic-extra-types (pyproject.toml) phonenumbers==8.13.15 # via pydantic-extra-types (pyproject.toml) From 339c71be256626006309b218a8372a9405626fda Mon Sep 17 00:00:00 2001 From: Yasser Tahiri Date: Fri, 30 Jun 2023 21:18:08 +0400 Subject: [PATCH 15/30] . --- requirements/pyproject.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/requirements/pyproject.txt b/requirements/pyproject.txt index 8064d8fb..250dcee3 100644 --- a/requirements/pyproject.txt +++ b/requirements/pyproject.txt @@ -16,12 +16,6 @@ pydantic==2.0 # via pydantic-extra-types (pyproject.toml) pydantic-core==2.0.1 # via pydantic -python-dateutil==2.8.2 - # via pandas -pytz==2023.3 - # via pandas -six==1.16.0 - # via python-dateutil typing-extensions==4.7.0 # via # pydantic From 7129b91709c705f0c9990db561be9bdc841411bb Mon Sep 17 00:00:00 2001 From: Yasser Tahiri Date: Fri, 30 Jun 2023 23:08:28 +0400 Subject: [PATCH 16/30] fix --- requirements/testing.txt | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/requirements/testing.txt b/requirements/testing.txt index 57081614..02cda3be 100644 --- a/requirements/testing.txt +++ b/requirements/testing.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.10 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # pip-compile --output-file=requirements/testing.txt --resolver=backtracking requirements/testing.in @@ -17,23 +17,21 @@ coverage[toml]==7.2.7 # pytest-cov dirty-equals==0.6.0 # via -r requirements/testing.in -exceptiongroup==1.1.1 - # via pytest idna==3.4 # via requests iniconfig==2.0.0 # via pytest -markdown-it-py==3.0.0 +markdown-it-py==2.2.0 # via rich mdurl==0.1.2 # via markdown-it-py packaging==23.1 # via pytest -pluggy==1.2.0 +pluggy==1.0.0 # via pytest pygments==2.15.1 # via rich -pytest==7.4.0 +pytest==7.3.1 # via # -r requirements/testing.in # pytest-cov @@ -46,11 +44,7 @@ pytz==2023.3 # via dirty-equals requests==2.31.0 # via codecov -rich==13.4.2 +rich==13.4.1 # via pytest-pretty -tomli==2.0.1 - # via - # coverage - # pytest -urllib3==2.0.3 +urllib3==2.0.2 # via requests From c9c4f12f3ade66da652efc26fd0503d040b85077 Mon Sep 17 00:00:00 2001 From: Yasser Tahiri Date: Sat, 1 Jul 2023 22:11:42 +0400 Subject: [PATCH 17/30] Update pydantic_extra_types/pandas_types.py Co-authored-by: Akbar <98239031+EkberHasanov@users.noreply.github.com> --- pydantic_extra_types/pandas_types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydantic_extra_types/pandas_types.py b/pydantic_extra_types/pandas_types.py index 57542e96..f706b58a 100644 --- a/pydantic_extra_types/pandas_types.py +++ b/pydantic_extra_types/pandas_types.py @@ -7,7 +7,7 @@ import pandas as pd except ModuleNotFoundError: # pragma: no cover raise RuntimeError( - '`PhoneNumber` requires "phonenumbers" to be installed. You can install it with "pip install phonenumbers"' + '`Series` requires "pandas" to be installed. You can install it with "pip install pandas"' ) T = TypeVar('T', str, bytes, bool, int, float, complex, pd.Timestamp, pd.Timedelta, pd.Period) From cc9dac01ce080a2c177a3aff15747b42a411151b Mon Sep 17 00:00:00 2001 From: EkberHasanov Date: Fri, 7 Jul 2023 01:49:10 +0400 Subject: [PATCH 18/30] Inheriting directly from pd.Series --- m.py | 50 ++++++++++++++++++++++++++++ pydantic_extra_types/pandas_types.py | 35 +++---------------- tests/test_pandas_types.py | 24 ++++++------- 3 files changed, 66 insertions(+), 43 deletions(-) create mode 100644 m.py diff --git a/m.py b/m.py new file mode 100644 index 00000000..5ea874ad --- /dev/null +++ b/m.py @@ -0,0 +1,50 @@ +from pydantic import BaseModel, validator +from pydantic_extra_types.pandas_types import Series +import pandas as pd + + +""" +from typing import Any, Type, TypeVar + +import pandas as pd +from pydantic import GetCoreSchemaHandler +from pydantic_core import core_schema + +T = TypeVar('T', str, bytes, bool, int, float, complex, pd.Timestamp, pd.Timedelta, pd.Period) + + +class Series(pd.Series): # type: ignore + @classmethod + def __get_pydantic_core_schema__( + cls, source: Type[Any], handler: GetCoreSchemaHandler + ) -> core_schema.AfterValidatorFunctionSchema: + return core_schema.general_after_validator_function( + cls._validate, + core_schema.any_schema(), + ) + + @classmethod + def _validate(cls, __input_value: Any, _: core_schema.ValidationInfo) -> 'Series': + return cls(__input_value) +""" + + +class Model(BaseModel): + x: Series + + +m = Model(x=[1, 2, 4]) +s = pd.Series([1, 2, 4]) +t = Series(data=[1, 2, 4], index=["a", "b", "d"]) + +print(m) +print(m.x) + +print(s) + +print(m.x == s) + +print(isinstance(m.x, pd.Series)) + +print(t) +print(t.index) diff --git a/pydantic_extra_types/pandas_types.py b/pydantic_extra_types/pandas_types.py index f706b58a..dbb41878 100644 --- a/pydantic_extra_types/pandas_types.py +++ b/pydantic_extra_types/pandas_types.py @@ -1,22 +1,13 @@ -from typing import Any, List, Tuple, Type, TypeVar, Union +from typing import Any, Type, TypeVar +import pandas as pd from pydantic import GetCoreSchemaHandler from pydantic_core import core_schema -try: - import pandas as pd -except ModuleNotFoundError: # pragma: no cover - raise RuntimeError( - '`Series` requires "pandas" to be installed. You can install it with "pip install pandas"' - ) - T = TypeVar('T', str, bytes, bool, int, float, complex, pd.Timestamp, pd.Timedelta, pd.Period) -class Series: - def __init__(self, value: Any) -> None: - self.value = pd.Series(value) - +class Series(pd.Series): # type: ignore @classmethod def __get_pydantic_core_schema__( cls, source: Type[Any], handler: GetCoreSchemaHandler @@ -28,22 +19,4 @@ def __get_pydantic_core_schema__( @classmethod def _validate(cls, __input_value: Any, _: core_schema.ValidationInfo) -> 'Series': - if isinstance(__input_value, pd.Series): - return cls(__input_value) - return cls(pd.Series(__input_value)) - - def __repr__(self) -> str: - return repr(self.value) - - def __getattr__(self, name: str) -> Any: - return getattr(self.value, name) - - def __eq__(self, __value: object) -> bool: - return isinstance(__value, (pd.Series, Series)) - - def __add__(self, other: Union['Series', List[Any], Tuple[Any], T]) -> 'Series': - if isinstance(other, Series): - result_val = self.value + other.value - else: - result_val = self.value + other - return Series(result_val) + return cls(__input_value) diff --git a/tests/test_pandas_types.py b/tests/test_pandas_types.py index 84745899..c11f7cac 100644 --- a/tests/test_pandas_types.py +++ b/tests/test_pandas_types.py @@ -28,8 +28,8 @@ def test_series_creation(data, expected): else: s = Series(data) assert isinstance(s, Series) - assert isinstance(s.value, pd.Series) - assert s.value.tolist() == expected + assert isinstance(s, pd.Series) + assert s.tolist() == expected def test_series_repr(): @@ -48,8 +48,8 @@ def test_series_equality(): data = [1, 2, 3] s1 = Series(data) s2 = Series(data) - assert s1 == s2 - assert s2 == pd.Series(data) + assert s1.equals(other=s2) + assert s2.equals(pd.Series(data)) def test_series_addition(): @@ -58,8 +58,8 @@ def test_series_addition(): s1 = Series(data1) s2 = Series(data2) s3 = s1 + s2 - assert isinstance(s3, Series) - assert s3.value.tolist() == [5, 7, 9] + assert isinstance(s3, pd.Series) + assert s3.tolist() == [5, 7, 9] @pytest.mark.parametrize( @@ -73,8 +73,8 @@ def test_series_addition(): def test_series_addition_with_types(data, other, expected): s = Series(data) result = s + other - assert isinstance(result, Series) - assert result.value.tolist() == expected + assert isinstance(result, pd.Series) + assert result.tolist() == expected @pytest.mark.parametrize( @@ -104,12 +104,12 @@ def test_series_addition_invalid_value_error(data, other) -> None: def test_valid_series_model(SeriesModel) -> None: model = SeriesModel(data=[1, 2, 4]) - assert isinstance(model.data, Series) - assert model.data == pd.Series([1, 2, 4]) + assert isinstance(model.data, pd.Series) + assert model.data.equals(pd.Series([1, 2, 4])) def test_valid_series_model_with_pd_series(SeriesModel) -> None: s = pd.Series([1, 2, 4]) model = SeriesModel(data=s) - assert isinstance(model.data, Series) - assert model.data == s + assert isinstance(model.data, pd.Series) + assert model.data.equals(s) From 09e073d37c037c48fe1820e6293067d7aeb87a34 Mon Sep 17 00:00:00 2001 From: Akbar <98239031+EkberHasanov@users.noreply.github.com> Date: Wed, 12 Jul 2023 22:01:19 +0400 Subject: [PATCH 19/30] delete extra files --- m.py | 50 -------------------------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 m.py diff --git a/m.py b/m.py deleted file mode 100644 index 5ea874ad..00000000 --- a/m.py +++ /dev/null @@ -1,50 +0,0 @@ -from pydantic import BaseModel, validator -from pydantic_extra_types.pandas_types import Series -import pandas as pd - - -""" -from typing import Any, Type, TypeVar - -import pandas as pd -from pydantic import GetCoreSchemaHandler -from pydantic_core import core_schema - -T = TypeVar('T', str, bytes, bool, int, float, complex, pd.Timestamp, pd.Timedelta, pd.Period) - - -class Series(pd.Series): # type: ignore - @classmethod - def __get_pydantic_core_schema__( - cls, source: Type[Any], handler: GetCoreSchemaHandler - ) -> core_schema.AfterValidatorFunctionSchema: - return core_schema.general_after_validator_function( - cls._validate, - core_schema.any_schema(), - ) - - @classmethod - def _validate(cls, __input_value: Any, _: core_schema.ValidationInfo) -> 'Series': - return cls(__input_value) -""" - - -class Model(BaseModel): - x: Series - - -m = Model(x=[1, 2, 4]) -s = pd.Series([1, 2, 4]) -t = Series(data=[1, 2, 4], index=["a", "b", "d"]) - -print(m) -print(m.x) - -print(s) - -print(m.x == s) - -print(isinstance(m.x, pd.Series)) - -print(t) -print(t.index) From b15b3d014759e53b1239295360d30cd263faed6e Mon Sep 17 00:00:00 2001 From: EkberHasanov Date: Sun, 25 Feb 2024 23:33:24 +0400 Subject: [PATCH 20/30] upgrading version of pandas --- pydantic_extra_types/pandas_types.py | 10 +++++----- requirements/pyproject.txt | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pydantic_extra_types/pandas_types.py b/pydantic_extra_types/pandas_types.py index dbb41878..02a03205 100644 --- a/pydantic_extra_types/pandas_types.py +++ b/pydantic_extra_types/pandas_types.py @@ -1,16 +1,16 @@ -from typing import Any, Type, TypeVar +from __future__ import annotations + +from typing import Any import pandas as pd from pydantic import GetCoreSchemaHandler from pydantic_core import core_schema -T = TypeVar('T', str, bytes, bool, int, float, complex, pd.Timestamp, pd.Timedelta, pd.Period) - class Series(pd.Series): # type: ignore @classmethod def __get_pydantic_core_schema__( - cls, source: Type[Any], handler: GetCoreSchemaHandler + cls, source: type[Any], handler: GetCoreSchemaHandler ) -> core_schema.AfterValidatorFunctionSchema: return core_schema.general_after_validator_function( cls._validate, @@ -18,5 +18,5 @@ def __get_pydantic_core_schema__( ) @classmethod - def _validate(cls, __input_value: Any, _: core_schema.ValidationInfo) -> 'Series': + def _validate(cls, __input_value: Any, _: core_schema.ValidationInfo) -> Series: return cls(__input_value) diff --git a/requirements/pyproject.txt b/requirements/pyproject.txt index 250dcee3..e59d6528 100644 --- a/requirements/pyproject.txt +++ b/requirements/pyproject.txt @@ -6,7 +6,7 @@ # annotated-types==0.5.0 # via pydantic -pandas==1.3.5 +pandas==2.2.1 # via pydantic-extra-types (pyproject.toml) phonenumbers==8.13.15 # via pydantic-extra-types (pyproject.toml) From 8e408bcac8f9349771a476e4a9ee2e2f7ae26601 Mon Sep 17 00:00:00 2001 From: Akbar <98239031+EkberHasanov@users.noreply.github.com> Date: Sun, 25 Feb 2024 23:42:50 +0400 Subject: [PATCH 21/30] Update pyproject.txt --- requirements/pyproject.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements/pyproject.txt b/requirements/pyproject.txt index 42eb0c33..6ba1b6b4 100644 --- a/requirements/pyproject.txt +++ b/requirements/pyproject.txt @@ -8,7 +8,6 @@ annotated-types==0.6.0 # via pydantic pandas==2.2.1 # via pydantic-extra-types (pyproject.toml) -phonenumbers==8.13.15 pendulum==3.0.0 # via pydantic-extra-types (pyproject.toml) phonenumbers==8.13.28 From 7b4433fb9f8fe27b17d61765e671d6024359e8d8 Mon Sep 17 00:00:00 2001 From: Akbar <98239031+EkberHasanov@users.noreply.github.com> Date: Sun, 25 Feb 2024 23:45:31 +0400 Subject: [PATCH 22/30] Update test_json_schema.py --- tests/test_json_schema.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_json_schema.py b/tests/test_json_schema.py index 82ade160..dd37c91c 100644 --- a/tests/test_json_schema.py +++ b/tests/test_json_schema.py @@ -9,9 +9,9 @@ CountryNumericCode, CountryShortName, ) -from pydantic_extra_types.pandas_types import Series from pydantic_extra_types.isbn import ISBN from pydantic_extra_types.mac_address import MacAddress +from pydantic_extra_types.pandas_types import Series from pydantic_extra_types.payment import PaymentCardNumber from pydantic_extra_types.pendulum_dt import DateTime from pydantic_extra_types.ulid import ULID From 6cff2d738da49e2154cd66c355b19c9d611eaed6 Mon Sep 17 00:00:00 2001 From: Akbar <98239031+EkberHasanov@users.noreply.github.com> Date: Sun, 25 Feb 2024 23:48:56 +0400 Subject: [PATCH 23/30] Update linting.in --- requirements/linting.in | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements/linting.in b/requirements/linting.in index e8745256..f007182d 100644 --- a/requirements/linting.in +++ b/requirements/linting.in @@ -4,4 +4,3 @@ annotated-types black pyupgrade ruff -pandas-stubs From 3d7b805d34bc05691754534ce04245e332e2433f Mon Sep 17 00:00:00 2001 From: EkberHasanov Date: Sun, 25 Feb 2024 23:52:42 +0400 Subject: [PATCH 24/30] adding pandas-stubs --- pyproject.toml | 1 - requirements/linting.in | 1 + requirements/linting.txt | 2 ++ 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ace51721..2fef9bec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,6 @@ dynamic = ['version'] [project.optional-dependencies] all = [ 'phonenumbers>=8,<9', - 'pycountry>=22,<23', 'pandas==2.2.1', 'pycountry>=23', diff --git a/requirements/linting.in b/requirements/linting.in index f007182d..e8745256 100644 --- a/requirements/linting.in +++ b/requirements/linting.in @@ -4,3 +4,4 @@ annotated-types black pyupgrade ruff +pandas-stubs diff --git a/requirements/linting.txt b/requirements/linting.txt index fa398edd..c0afb258 100644 --- a/requirements/linting.txt +++ b/requirements/linting.txt @@ -28,6 +28,8 @@ nodeenv==1.8.0 # via pre-commit numpy==1.25.0 # via pandas-stubs +pandas-stubs==2.0.2 + # via -r requirements/linting.in packaging==23.2 # via black pathspec==0.12.1 From b751633123aea4d7b075b69db3a359fb345de2b6 Mon Sep 17 00:00:00 2001 From: EkberHasanov Date: Sun, 25 Feb 2024 23:54:26 +0400 Subject: [PATCH 25/30] fix versions --- requirements/linting.txt | 2 +- requirements/pyproject.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements/linting.txt b/requirements/linting.txt index c0afb258..b4792625 100644 --- a/requirements/linting.txt +++ b/requirements/linting.txt @@ -28,7 +28,7 @@ nodeenv==1.8.0 # via pre-commit numpy==1.25.0 # via pandas-stubs -pandas-stubs==2.0.2 +pandas-stubs==2.2.0.240218 # via -r requirements/linting.in packaging==23.2 # via black diff --git a/requirements/pyproject.txt b/requirements/pyproject.txt index 6ba1b6b4..73ebaed0 100644 --- a/requirements/pyproject.txt +++ b/requirements/pyproject.txt @@ -6,7 +6,7 @@ # annotated-types==0.6.0 # via pydantic -pandas==2.2.1 +pandas==2.0.3 # via pydantic-extra-types (pyproject.toml) pendulum==3.0.0 # via pydantic-extra-types (pyproject.toml) From d78fc5a5e21bed4f3aa68f4da25f1c265efa2d6a Mon Sep 17 00:00:00 2001 From: EkberHasanov Date: Sun, 25 Feb 2024 23:56:22 +0400 Subject: [PATCH 26/30] resolve version issue --- requirements/linting.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/linting.txt b/requirements/linting.txt index b4792625..a941e02d 100644 --- a/requirements/linting.txt +++ b/requirements/linting.txt @@ -28,7 +28,7 @@ nodeenv==1.8.0 # via pre-commit numpy==1.25.0 # via pandas-stubs -pandas-stubs==2.2.0.240218 +pandas-stubs==2.0.0.230412 # via -r requirements/linting.in packaging==23.2 # via black From 6a55cd29d5d5c6966edb6942eeae514651602568 Mon Sep 17 00:00:00 2001 From: EkberHasanov Date: Sun, 25 Feb 2024 23:58:52 +0400 Subject: [PATCH 27/30] upgrading version of numpy --- requirements/linting.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements/linting.txt b/requirements/linting.txt index a941e02d..28dfe892 100644 --- a/requirements/linting.txt +++ b/requirements/linting.txt @@ -26,9 +26,9 @@ mypy-extensions==1.0.0 # mypy nodeenv==1.8.0 # via pre-commit -numpy==1.25.0 +numpy==1.26.4 # via pandas-stubs -pandas-stubs==2.0.0.230412 +pandas-stubs==2.2.0.240218 # via -r requirements/linting.in packaging==23.2 # via black From ba7a94161341a9467d05f3b44f2896fee5d65752 Mon Sep 17 00:00:00 2001 From: EkberHasanov Date: Mon, 26 Feb 2024 00:08:21 +0400 Subject: [PATCH 28/30] fixing some issues --- pydantic_extra_types/isbn.py | 3 ++- pydantic_extra_types/pandas_types.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pydantic_extra_types/isbn.py b/pydantic_extra_types/isbn.py index df573c68..0e0ac6d7 100644 --- a/pydantic_extra_types/isbn.py +++ b/pydantic_extra_types/isbn.py @@ -1,7 +1,8 @@ """ The `pydantic_extra_types.isbn` module provides functionality to recieve and validate ISBN. -ISBN (International Standard Book Number) is a numeric commercial book identifier which is intended to be unique. This module provides a ISBN type for Pydantic models. +ISBN (International Standard Book Number) is a numeric commercial book identifier which is intended to be unique. +This module provides a ISBN type for Pydantic models. """ from __future__ import annotations diff --git a/pydantic_extra_types/pandas_types.py b/pydantic_extra_types/pandas_types.py index 02a03205..820f34e9 100644 --- a/pydantic_extra_types/pandas_types.py +++ b/pydantic_extra_types/pandas_types.py @@ -11,8 +11,8 @@ class Series(pd.Series): # type: ignore @classmethod def __get_pydantic_core_schema__( cls, source: type[Any], handler: GetCoreSchemaHandler - ) -> core_schema.AfterValidatorFunctionSchema: - return core_schema.general_after_validator_function( + ) -> core_schema.BeforeValidatorFunctionSchema: + return core_schema.no_info_before_validator_function( cls._validate, core_schema.any_schema(), ) From 933540a5b8bb08253a2373886fff8ac8eafc5d7c Mon Sep 17 00:00:00 2001 From: EkberHasanov Date: Thu, 29 Feb 2024 15:44:14 +0400 Subject: [PATCH 29/30] change core_schema func --- pydantic_extra_types/pandas_types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydantic_extra_types/pandas_types.py b/pydantic_extra_types/pandas_types.py index 820f34e9..914eed15 100644 --- a/pydantic_extra_types/pandas_types.py +++ b/pydantic_extra_types/pandas_types.py @@ -12,7 +12,7 @@ class Series(pd.Series): # type: ignore def __get_pydantic_core_schema__( cls, source: type[Any], handler: GetCoreSchemaHandler ) -> core_schema.BeforeValidatorFunctionSchema: - return core_schema.no_info_before_validator_function( + return core_schema.general_before_validator_function( cls._validate, core_schema.any_schema(), ) From 811d6642cbe24e1c3005110db5baf384547d4d12 Mon Sep 17 00:00:00 2001 From: Akbar <98239031+EkberHasanov@users.noreply.github.com> Date: Thu, 29 Feb 2024 15:52:14 +0400 Subject: [PATCH 30/30] Update test_json_schema.py --- tests/test_json_schema.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/test_json_schema.py b/tests/test_json_schema.py index 19ea2cde..3c170b2e 100644 --- a/tests/test_json_schema.py +++ b/tests/test_json_schema.py @@ -15,7 +15,6 @@ from pydantic_extra_types.isbn import ISBN from pydantic_extra_types.language_code import ISO639_3, ISO639_5 from pydantic_extra_types.mac_address import MacAddress -from pydantic_extra_types.pandas_types import Series from pydantic_extra_types.payment import PaymentCardNumber from pydantic_extra_types.pendulum_dt import DateTime from pydantic_extra_types.ulid import ULID @@ -215,12 +214,6 @@ 'type': 'object', }, ), - ( - Series, - { - 'properties': {'x': {'title': 'X'}}, - }, - ), ( ISO639_3, {