Skip to content
This repository has been archived by the owner on Mar 12, 2021. It is now read-only.

Commit

Permalink
fix failing calls
Browse files Browse the repository at this point in the history
  • Loading branch information
RileyMShea committed Feb 12, 2021
1 parent 855dcd2 commit e9028ec
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions upoly/polygon_plus.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from datetime import datetime, timedelta
from math import ceil
from time import perf_counter
from typing import Iterator, List, Literal, Optional, Tuple
from typing import Any, Callable, Iterator, List, Literal, Optional, Tuple, TypeVar, cast

import httpx
import nest_asyncio
Expand All @@ -24,7 +24,9 @@
from .models import PolyAggResponse
from .settings import unwrap

cachedir = "./.joblib_cache"
dirname = os.path.dirname(__file__)
cachedir = os.path.join(dirname, ".joblib_cache")

memory = Memory(cachedir, verbose=0)

NY = pytz.timezone("America/New_York")
Expand All @@ -37,6 +39,17 @@
except NameError:
uvloop.install()

F = TypeVar("F", bound=Callable[..., Any])


def typed_cache(
fn: F,
) -> F:
def wrapper(*args, **kwargs):
return memory.cache(fn)(*args, **kwargs)

return cast(F, wrapper)


async def _produce_polygon_aggs(
polygon_id: str,
Expand Down Expand Up @@ -244,9 +257,9 @@ def inner_wrapper(
f"{expected_sessions=}\t{actual_sessions=}\tpct_diff: {(actual_sessions/expected_sessions)-1.:+.2%}"
)

expected_minutes = valid_minutes.to_frame().count()
expected_minutes = valid_minutes.shape[0]

actual_minutes = df.count()
actual_minutes = df.loc[~df.isnull().all(axis="columns")].shape[0]

print(
f"{expected_minutes=}\t{actual_minutes=}\tpct_diff: {(actual_minutes/expected_minutes)-1.:+.2%}"
Expand All @@ -267,7 +280,7 @@ def inner_wrapper(
print("After Reindexing by trading calender:")

actual_sessions = df.groupby(df.index.date).count().shape[0] # type:ignore
actual_minutes = df.count()
actual_minutes = df.loc[~df.isnull().all(axis="columns")].shape[0]

print(f"{expected_sessions = }\t{actual_sessions = }")
print(f"{expected_minutes = }\t{actual_minutes = }")
Expand Down

0 comments on commit e9028ec

Please sign in to comment.