Skip to content

Commit 98e58d6

Browse files
committed
🔧 update code
1 parent 33f45f2 commit 98e58d6

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

‎pydantic_extra_types/pandas_types.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
from typing import Any, List, Tuple, Type, TypeVar, Union
22

3-
import pandas as pd
43
from pydantic import GetCoreSchemaHandler
54
from pydantic_core import core_schema
65

6+
try:
7+
import pandas as pd
8+
except ModuleNotFoundError: # pragma: no cover
9+
raise RuntimeError(
10+
'`PhoneNumber` requires "phonenumbers" to be installed. You can install it with "pip install phonenumbers"'
11+
)
12+
713
T = TypeVar('T', str, bytes, bool, int, float, complex, pd.Timestamp, pd.Timedelta, pd.Period)
814

915

@@ -33,7 +39,7 @@ def __getattr__(self, name: str) -> Any:
3339
return getattr(self.value, name)
3440

3541
def __eq__(self, __value: object) -> bool:
36-
return isinstance(__value, pd.Series) or isinstance(__value, Series)
42+
return isinstance(__value, (pd.Series, Series))
3743

3844
def __add__(self, other: Union['Series', List[Any], Tuple[Any], T]) -> 'Series':
3945
if isinstance(other, Series):

‎tests/test_json_schema.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
CountryOfficialName,
1010
CountryShortName,
1111
)
12+
from pydantic_extra_types.pandas_types import Series
1213
from pydantic_extra_types.payment import PaymentCardNumber
1314

1415

@@ -85,6 +86,15 @@
8586
'type': 'object',
8687
},
8788
),
89+
(
90+
Series,
91+
{
92+
'properties': {'x': {'title': 'X'}},
93+
'required': ['x'],
94+
'title': 'Model',
95+
'type': 'object',
96+
},
97+
),
8898
],
8999
)
90100
def test_json_schema(cls, expected):

0 commit comments

Comments
 (0)