You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Added kwarg simplify_dtypes to simplify DataFrame returns.
- Added the kwarg `simplify_dtypes` to the functions `ledger`, `cols_operation`, `cols_operation_cumsum` and `cols_operation_balance_by_instrument`. This allows for dtype simplification (see pandas-dev/pandas#58543 (comment)).
- Added some docstrings.
Copy file name to clipboardExpand all lines: lib/simple_portfolio_ledger/src/simple_portfolio_ledger.py
+93-11Lines changed: 93 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -228,20 +228,48 @@ def ledger(
228
228
cols_operation_balance_by_instrument=False,
229
229
thousands_fmt_sep=False,
230
230
thousands_fmt_decimals=1,
231
-
):
231
+
simplify_dtypes=True,
232
+
) ->pd.DataFrame:
233
+
"""Returns The Ledger, with optional additional information.
234
+
235
+
Args:
236
+
cols_operation (bool, optional): Whether to add cols_operation to The Ledger. Defaults to False.
237
+
cols_operation_cumsum (bool, optional): Whether to add cols_operation_cumsum to The Ledger. Defaults to False.
238
+
cols_operation_balance_by_instrument (bool, optional): Whether to add cols_operation_balance_by_instrument to The Ledger. Defaults to False.
239
+
thousands_fmt_sep (bool, optional): Add a thousands separator. Defaults to False.
240
+
thousands_fmt_decimals (int, optional): Decimals to print, used only when thousands_fmt_sep is set to True. Defaults to 1.
241
+
simplify_dtypes (bool, optional): Allows to simplify dtypes, for instance, pass from float64 to int64 if no decimals are present. Doesn't convert to a dtype that supports pd.NA, like `DataFrame.convert_dtypes()` although it uses it. See https://github.com/pandas-dev/pandas/issues/58543#issuecomment-2101240339 . Warning: Might have a performance impact if True. Defaults to True.
242
+
243
+
Returns:
244
+
pd.DataFrame: Returns The Ledger, with optional additional information.
245
+
"""
232
246
iflen(self._ledger_df) ==0:
233
247
warnings.warn('WARNING: Ledger is empty, showing only basic structure.')
"""Returns a dataframe with 1 column per operation.
276
304
277
305
Args:
278
306
show_instr_accnt (bool, optional): Whether or not to show the instrument and the account. Defaults to False.
307
+
simplify_dtypes (bool, optional): Allows to simplify dtypes, for instance, pass from float64 to int64 if no decimals are present. Doesn't convert to a dtype that supports pd.NA, like `DataFrame.convert_dtypes()` although it uses it. See https://github.com/pandas-dev/pandas/issues/58543#issuecomment-2101240339 . Warning: Might have a performance impact if True. Defaults to True.
279
308
280
309
Returns:
281
310
pd.DataFrame: Returns a dataframe with 1 column per operation.
"""Returns a DataFrame with one column per operation but do a cumsum per instrument/account.
362
+
363
+
Args:
364
+
show_instr_accnt (bool, optional): Whether or not to show the instrument and the account. Defaults to False.
365
+
simplify_dtypes (bool, optional): Allows to simplify dtypes, for instance, pass from float64 to int64 if no decimals are present. Doesn't convert to a dtype that supports pd.NA, like `DataFrame.convert_dtypes()` although it uses it. See https://github.com/pandas-dev/pandas/issues/58543#issuecomment-2101240339 . Warning: Might have a performance impact if True. Defaults to True.
366
+
367
+
Returns:
368
+
pd.DataFrame: Returns a DataFrame with one column per operation but do a cumsum per instrument/operation/account.
322
369
"""
323
370
324
371
# List of columns to return, SORTED by self._ops_names
"""Returns a DataFrame with a balance per operation per instrument/account.
623
+
624
+
Args:
625
+
show_instr_accnt (bool, optional): Whether or not to show the instrument and the account. Defaults to False.
626
+
simplify_dtypes (bool, optional): Allows to simplify dtypes, for instance, pass from float64 to int64 if no decimals are present. Doesn't convert to a dtype that supports pd.NA, like `DataFrame.convert_dtypes()` although it uses it. See https://github.com/pandas-dev/pandas/issues/58543#issuecomment-2101240339 . Warning: Might have a performance impact if True. Defaults to True.
627
+
628
+
Returns:
629
+
pd.DataFrame: Returns a DataFrame with a balance per operation per instrument/account.
0 commit comments