Skip to content

Commit

Permalink
fix: Pandas FutureWarning for concat with empty Series
Browse files Browse the repository at this point in the history
concat None if Series is empty

FutureWarning: The behavior of array concatenation with empty entries is deprecated. In a future version, this will no longer exclude empty items when determining the result dtype. To retain the old behavior, exclude the empty entries before the concat operation.
  • Loading branch information
chilango74 committed Dec 30, 2023
1 parent 6cd7f27 commit 82c24ed
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
11 changes: 3 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import matplotlib.pyplot as plt
import okama as ok

indexes = ["RGBITR.INDX", "RUCBTRNS.INDX", "MCFTR.INDX", "GC.COMM"]
bounds = [(0, 0.7), (0, 0.7), (0, 1), (0, 0.19)]
ef = ok.EfficientFrontier(indexes, ccy="RUB", full_frontier=False, bounds=bounds, inflation=False)
tg = ef.get_tangency_portfolio(rf_return=0.08)
s = tg["Weights"].sum()
print(s)
## TODO: replace ValueError: Weights sum is not equal to one. with custom error mesage

weights = [0.32, 0.31, 0.18, .19]
portf = ok.Portfolio(['RGBITR.INDX', 'RUCBTRNS.INDX', 'MCFTR.INDX', 'GC.COMM'], ccy="RUB", weights=weights, inflation=True, symbol="portf.PF", rebalancing_period='year')
portf.describe()
8 changes: 2 additions & 6 deletions okama/common/helpers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,7 @@ def wealth_ts(self, weights: list, ror: pd.DataFrame) -> pd.Series:
inv_period_spread = np.asarray(weights) * initial_inv # rebalancing
assets_wealth_indexes = inv_period_spread * (1 + df).cumprod()
wealth_index_local = assets_wealth_indexes.sum(axis=1)
wealth_index = pd.concat([wealth_index, wealth_index_local], verify_integrity=True, sort=False)
# TODO: FutureWarning: The behavior of array concatenation with empty entries is deprecated.
# In a future version, this will no longer exclude empty items when determining the result dtype.
# To retain the old behavior, exclude the empty entries before the concat operation.

wealth_index = pd.concat([None if wealth_index.empty else wealth_index, wealth_index_local], sort=False)
initial_inv = wealth_index.iloc[-1]
return wealth_index

Expand All @@ -421,7 +417,7 @@ def assets_wealth_ts(self, weights: list, ror: pd.DataFrame) -> pd.DataFrame:
sort=False,
)
wealth_index_local = assets_wealth_indexes_local.sum(axis=1)
wealth_index = pd.concat([wealth_index, wealth_index_local], verify_integrity=True, sort=False)
wealth_index = pd.concat([None if wealth_index.empty else wealth_index, wealth_index_local], sort=False)
initial_inv = wealth_index.iloc[-1]
return assets_wealth_indexes

Expand Down

0 comments on commit 82c24ed

Please sign in to comment.