Skip to content

Commit

Permalink
clean up imports for numpy
Browse files Browse the repository at this point in the history
  • Loading branch information
cciechad committed Mar 30, 2024
1 parent b3f9730 commit 3da1949
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions AnalyzeLots.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from multiprocessing import Pool
from pathlib import Path

import numpy as np
import pandas as pd
from numpy import uint16, float32
from pandas import DataFrame, Series


Expand All @@ -15,8 +15,8 @@ def main() -> None:
if args.file.is_file():
data: DataFrame = pd.read_csv(args.file, header=1, low_memory=False, memory_map=True, parse_dates=['date'],
names=['symbol', 'display_name', 'date', 'cost', 'quantity', 'value', 'gain'],
dtype={'quantity': np.uint16, 'cost': np.float32, 'value': np.float32,
'gain': np.float32, 'symbol': 'category', 'display_name': 'category'})
dtype={'quantity': uint16, 'cost': float32, 'value': float32, 'gain': float32,
'symbol': 'category', 'display_name': 'category'})
is_short: Series[bool] = data['date'] > (datetime.now() - timedelta(days=(365 - args.days)))
is_long: Series[bool] = ~is_short
symbols: list[str] = data['symbol'].unique().tolist()
Expand Down Expand Up @@ -73,7 +73,7 @@ def summary(data: DataFrame, is_long: Series, is_short: Series) -> None:

def live_update(data: DataFrame, symbols: list[str]) -> DataFrame:
with Pool() as p:
data['price'] = data['symbol'].map(dict(p.imap_unordered(get_price, symbols, chunksize=2))).astype(np.float32)
data['price'] = data['symbol'].map(dict(p.imap_unordered(get_price, symbols, chunksize=2))).astype(float32)
data['value'] = data['quantity'] * data['price']
data['gain'] = data['value'] - data['cost']
return data.drop(columns=['price'])
Expand Down

0 comments on commit 3da1949

Please sign in to comment.