diff --git a/src/market_prices/mptypes.py b/src/market_prices/mptypes.py index d063513..8dd3d05 100644 --- a/src/market_prices/mptypes.py +++ b/src/market_prices/mptypes.py @@ -17,10 +17,14 @@ from typing import Any, Dict, List, Tuple, TypedDict, Union import pandas as pd -import pydantic import pytz from exchange_calendars import ExchangeCalendar +import pydantic + +if int(next(c for c in pydantic.__version__ if c.isdigit())) > 1: + from pydantic import v1 as pydantic + # pylint: disable=too-few-public-methods # nature of pydantic types. # ----------------------------- Type aliases ------------------------------ diff --git a/src/market_prices/prices/base.py b/src/market_prices/prices/base.py index 46a6310..1c91e9b 100644 --- a/src/market_prices/prices/base.py +++ b/src/market_prices/prices/base.py @@ -19,7 +19,6 @@ import exchange_calendars as xcals import numpy as np import pandas as pd -import pydantic import pytz from market_prices import data @@ -30,6 +29,11 @@ from market_prices.utils import calendar_utils as calutils from market_prices.utils import pandas_utils as pdutils +import pydantic + +if int(next(c for c in pydantic.__version__ if c.isdigit())) > 1: + from pydantic import v1 as pydantic + # pylint: disable=too-many-lines diff --git a/src/market_prices/prices/yahoo.py b/src/market_prices/prices/yahoo.py index d154c58..20e94a5 100644 --- a/src/market_prices/prices/yahoo.py +++ b/src/market_prices/prices/yahoo.py @@ -10,7 +10,6 @@ from pandas import DataFrame import pandas as pd -import pydantic import exchange_calendars as xcals import yahooquery as yq @@ -20,6 +19,11 @@ from ..mptypes import Calendar, Symbols from .config import config_yahoo +import pydantic + +if int(next(c for c in pydantic.__version__ if c.isdigit())) > 1: + from pydantic import v1 as pydantic + class PricesYahoo(base.PricesBase): """Retrieve and serve price data sourced via yahooquery. diff --git a/src/market_prices/pt.py b/src/market_prices/pt.py index c9a88d9..038a415 100644 --- a/src/market_prices/pt.py +++ b/src/market_prices/pt.py @@ -11,7 +11,6 @@ import exchange_calendars as xcals import numpy as np import pandas as pd -import pydantic import pytz from pytz import BaseTzInfo @@ -23,6 +22,10 @@ from .mptypes import Symbols from .utils.calendar_utils import CompositeCalendar +import pydantic + +if int(next(c for c in pydantic.__version__ if c.isdigit())) > 1: + from pydantic import v1 as pydantic # pylint: disable=too-many-lines diff --git a/src/market_prices/utils/calendar_utils.py b/src/market_prices/utils/calendar_utils.py index 2aab473..bf7c7e6 100644 --- a/src/market_prices/utils/calendar_utils.py +++ b/src/market_prices/utils/calendar_utils.py @@ -14,12 +14,16 @@ import exchange_calendars as xcals # type: ignore[import] import numpy as np import pandas as pd -import pydantic import pytz from exchange_calendars.calendar_helpers import Date, Minute, Session, TradingMinute from market_prices import helpers, intervals, errors from market_prices.utils import pandas_utils as pdutils +import pydantic + +if int(next(c for c in pydantic.__version__ if c.isdigit())) > 1: + from pydantic import v1 as pydantic + def get_exchange_info() -> pd.DataFrame: """Retrieve information on exchanges for which calendars available. diff --git a/src/market_prices/utils/pandas_utils.py b/src/market_prices/utils/pandas_utils.py index a227dbb..cd611d9 100644 --- a/src/market_prices/utils/pandas_utils.py +++ b/src/market_prices/utils/pandas_utils.py @@ -10,11 +10,15 @@ import numpy as np import pandas as pd from pandas import DataFrame, Series -import pydantic import pytz from market_prices import mptypes +import pydantic + +if int(next(c for c in pydantic.__version__ if c.isdigit())) > 1: + from pydantic import v1 as pydantic + def pdfreq_to_offset(pdfreq: str) -> pd.offsets.BaseOffset: # type: ignore[name-defined] """Pandas frequency string to a pandas offset. diff --git a/tests/test_base_prices.py b/tests/test_base_prices.py index bc43736..d2d34ae 100644 --- a/tests/test_base_prices.py +++ b/tests/test_base_prices.py @@ -24,7 +24,6 @@ import exchange_calendars as xcals import pandas as pd from pandas.testing import assert_index_equal, assert_frame_equal -import pydantic import pytest import pytz from pytz import UTC @@ -39,6 +38,10 @@ from .utils import get_resource_pbt +import pydantic + +if int(next(c for c in pydantic.__version__ if c.isdigit())) > 1: + from pydantic import v1 as pydantic # pylint: disable=missing-function-docstring, missing-type-doc # pylint: disable=missing-param-doc, missing-any-param-doc, redefined-outer-name diff --git a/tests/test_mptypes.py b/tests/test_mptypes.py index 7a527bb..a04d380 100644 --- a/tests/test_mptypes.py +++ b/tests/test_mptypes.py @@ -9,12 +9,15 @@ import re import pandas as pd -import pydantic import pytest import pytz from market_prices import mptypes +import pydantic + +if int(next(c for c in pydantic.__version__ if c.isdigit())) > 1: + from pydantic import v1 as pydantic # pylint: disable=missing-function-docstring, missing-type-doc # pylint: disable=missing-param-doc, missing-any-param-doc, redefined-outer-name diff --git a/tests/test_pt.py b/tests/test_pt.py index f51e185..37dcdf2 100644 --- a/tests/test_pt.py +++ b/tests/test_pt.py @@ -11,7 +11,6 @@ import numpy as np import pandas as pd from pandas.testing import assert_frame_equal, assert_index_equal, assert_series_equal -import pydantic import pytest import pytz @@ -22,6 +21,10 @@ from .utils import get_resource, multiple_sessions_freq +import pydantic + +if int(next(c for c in pydantic.__version__ if c.isdigit())) > 1: + from pydantic import v1 as pydantic # pylint: disable=missing-function-docstring, missing-type-doc # pylint: disable=missing-param-doc, missing-any-param-doc, redefined-outer-name