Skip to content

Commit

Permalink
update read_csv to use uint16 for quantity and categoricalDtype for s…
Browse files Browse the repository at this point in the history
…ymbol and display_name to save memory.
  • Loading branch information
cciechad committed Mar 22, 2024
1 parent abd8b02 commit 2faec67
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions AnalyzeLots.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ def main() -> None:
pd.options.mode.copy_on_write = True
if args.file.is_file():
data: pd.DataFrame = pd.read_csv(args.file, header=1, low_memory=False, memory_map=True, parse_dates=['date'],
dtype={'quantity': np.uint32, 'cost': np.float32, 'value': np.float32,
'gain': np.float32},
names=['symbol', 'display_name', 'date', 'cost', 'quantity', 'value', 'gain'])
names=['symbol', 'display_name', 'date', 'cost', 'quantity', 'value', 'gain'],
dtype={'quantity': np.uint16, 'cost': np.float32, 'value': np.float32,
'gain': np.float32, 'symbol': pd.CategoricalDtype(),
'display_name': pd.CategoricalDtype()})
is_short: pd.Series[bool] = data['date'] > (datetime.now() - timedelta(days=(365 - args.days)))
is_long: pd.Series[bool] = ~is_short
if args.live:
Expand Down

0 comments on commit 2faec67

Please sign in to comment.