Skip to content

Commit fba1ace

Browse files
committed
Refactor user_retention_explorer_api.py for improved type safety and clarity
- Updated the type hint for the `partition_func` parameter in the `sql_users_volume` function to specify it as a Callable that takes a Set of Tuples and returns a string, enhancing type safety. - Changed the DataFrame creation for `traders_df` to use a dictionary format for better readability and consistency in data structure. These changes aim to improve code maintainability and clarity in the user retention explorer API.
1 parent 25a9a78 commit fba1ace

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

backend/api/user_retention_explorer_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import os
44
from datetime import datetime, timedelta, timezone
5-
from typing import Dict, List, Tuple, Set, Optional, Any
5+
from typing import Callable, Dict, List, Tuple, Set, Optional, Any
66

77
import pandas as pd
88
from dateutil import tz, parser
@@ -142,7 +142,7 @@ def sql_users_volume(
142142
users: List[str],
143143
start_dt: datetime,
144144
end_dt: datetime,
145-
partition_func: callable,
145+
partition_func: Callable[[Set[Tuple[str, str, str]]], str],
146146
market_index: Optional[int] = None,
147147
exclude_market_index: Optional[int] = None
148148
) -> str:
@@ -223,7 +223,7 @@ async def calculate_retention_for_market(market_name: str, start_date_str: str)
223223
}
224224

225225
# --- Volume Calculation ---
226-
traders_df = pd.DataFrame(mkt_traders, columns=['user'])
226+
traders_df = pd.DataFrame({"user": mkt_traders})
227227

228228
# Define time windows
229229
initial_window_end = start_date + timedelta(days=NEW_TRADER_WINDOW_DAYS)

0 commit comments

Comments
 (0)