Skip to content

Commit

Permalink
PLAT-69 PLAT-1370 update python package versions (pandas, websocket)
Browse files Browse the repository at this point in the history
This MR updates the Python API Client's dependencies to the following versions:
* pandas >= 2.0.0
* websocket >= 1.6.0
  • Loading branch information
victoreram committed Dec 20, 2024
1 parent a83a9a6 commit fcbb50c
Show file tree
Hide file tree
Showing 9 changed files with 1,143 additions and 1,074 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ RUN apt-get update && \

RUN pip install --upgrade pip

RUN pip install "poetry==1.5.0" pytest-timeout pytest-xdist
RUN pip install "poetry==1.8.5" pytest-timeout pytest-xdist
COPY pyproject.toml ./poetry.lock ./
RUN poetry config virtualenvs.create false

RUN poetry install --no-root
RUN pip install pandas==1.5.3 numpy==1.26.4
RUN pip install pandas==2.2.3 numpy==1.26.4

COPY ./ ./

Expand Down
4 changes: 2 additions & 2 deletions coinmetrics/_data_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def to_dataframe(
) -> DataFrameType:
df = super().to_dataframe(header=header, dtype_mapper=dtype_mapper, optimize_pandas_types=optimize_pandas_types)
if 'reorg' in df.columns:
df['reorg'] = df['reorg'].apply(lambda reorg: True if reorg == "true" else False)
df['reorg'] = df['reorg'].astype(str).apply(lambda x: x == 'True').fillna(False)
return df


Expand Down Expand Up @@ -490,7 +490,7 @@ def __init__(
parent_data_collection._url_params, parent_data_collection._csv_export_supported,
client=parent_data_collection._client)
self._parallelize_on = self._get_parallelize_on(parallelize_on)
self._executor: Callable[..., Executor] = executor if executor else ThreadPoolExecutor # type: ignore
self._executor: Callable[..., Executor] = executor or ThreadPoolExecutor
self._max_workers = max_workers if max_workers else 10
if self._max_workers > 10:
warnings.warn("Max workers greater than 10 are not permitted due to rate limits restrictions")
Expand Down
3 changes: 2 additions & 1 deletion coinmetrics/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path
from typing import Any, Callable, Dict, IO, List, Tuple, Union, Optional
from coinmetrics.constants import PagingFrom
from websocket import WebSocket
pandas_found = True

try:
Expand All @@ -17,4 +18,4 @@
UrlParamTypes = Union[
str, List[str], Tuple[str], PagingFrom, int, datetime, date, bool, None
]
MessageHandlerType = Optional[Callable[[Any, str], None]]
MessageHandlerType = Optional[Callable[[WebSocket, Any], None]]
29 changes: 23 additions & 6 deletions coinmetrics/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from coinmetrics._exceptions import CoinMetricsClientQueryParamsException
from coinmetrics._typing import (
DataReturnType,
MessageHandlerType,
MessageHandlerType
)
from coinmetrics.constants import PagingFrom, Backfill
from coinmetrics._data_collection import DataCollection, AssetChainsDataCollection, TransactionTrackerDataCollection, CatalogV2DataCollection
Expand Down Expand Up @@ -70,7 +70,7 @@ def run(
self,
on_message: MessageHandlerType = None,
on_error: MessageHandlerType = None,
on_close: Optional[Callable[[websocket.WebSocketApp, int, str], None]] = None,
on_close: Optional[Callable[[websocket.WebSocket, Any, Any], None]] = None,
reconnect: bool = True
) -> None:
if on_message is None:
Expand All @@ -81,7 +81,10 @@ def run(
on_close = self._on_close

ws = websocket.WebSocketApp(
self.ws_url, on_message=on_message, on_error=on_error, on_close=on_close,
self.ws_url,
on_message=on_message,
on_error=on_error,
on_close=on_close,
header={"User-Agent": f"Coinmetrics-Python-API-Client/{version}"}
)
self.ws = ws
Expand All @@ -103,10 +106,10 @@ def handler(signum: int, frame: Optional[FrameType]) -> None:

self._events_handlers_set = True

def _on_message(self, stream: websocket.WebSocketApp, message: str) -> None:
def _on_message(self, stream: websocket.WebSocket, message: str) -> None:
print(f"{message}")

def _on_error(self, stream: websocket.WebSocketApp, message: str) -> None:
def _on_error(self, stream: websocket.WebSocket, message: str) -> None:
print(f"{message}")

def _on_close(self, *args: Any, **kwargs: Any) -> None:
Expand Down Expand Up @@ -4866,7 +4869,21 @@ def get_asset_chains(
"end_inclusive": end_inclusive,
"timezone": timezone,
}
return AssetChainsDataCollection(self._get_data, "timeseries/asset-chains", params, client=self)
return AssetChainsDataCollection(
self._get_data,
"timeseries/asset-chains",
params,
client=self,
dtype_mapper={
"asset": "category",
# "time": "datetime64[ns, UTC]",
"chains_count": "Int64",
"blocks_count_at_tip": "Int64",
"chains": "string",
# "reorg": "string",
"reorg_depth": "Int64"
}
)

def get_asset_metrics(
self,
Expand Down
Loading

0 comments on commit fcbb50c

Please sign in to comment.