Skip to content

Commit

Permalink
Patch for pydantic v2
Browse files Browse the repository at this point in the history
  • Loading branch information
maread99 committed Jul 3, 2023
1 parent 7df4cd3 commit 23443b8
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/market_prices/mptypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ------------------------------
Expand Down
6 changes: 5 additions & 1 deletion src/market_prices/prices/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down
6 changes: 5 additions & 1 deletion src/market_prices/prices/yahoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from pandas import DataFrame
import pandas as pd
import pydantic
import exchange_calendars as xcals
import yahooquery as yq

Expand All @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion src/market_prices/pt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
6 changes: 5 additions & 1 deletion src/market_prices/utils/calendar_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion src/market_prices/utils/pandas_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion tests/test_base_prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion tests/test_mptypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion tests/test_pt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 23443b8

Please sign in to comment.