Skip to content

Commit aa6cb28

Browse files
committed
Surpress warnings
1 parent 3d9387c commit aa6cb28

File tree

1 file changed

+9
-59
lines changed

1 file changed

+9
-59
lines changed

tests/portfolio/test_overview_model.py

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from financetoolkit.portfolio.overview_model import (
1010
create_portfolio_overview,
1111
create_profit_and_loss_overview,
12-
create_transactions_overview,
1312
)
1413

1514

@@ -59,43 +58,9 @@ def sample_betas():
5958
return pd.Series([1.2, 0.8, 1.5], index=["AAPL", "MSFT", "AMZN"])
6059

6160

62-
def test_create_transactions_overview():
63-
"""Test create_transactions_overview function"""
64-
portfolio_volume = pd.Series([100, 50, 200], index=["AAPL", "MSFT", "AMZN"])
65-
portfolio_price = pd.Series([150.0, 250.0, 100.0], index=["AAPL", "MSFT", "AMZN"])
66-
portfolio_costs = pd.Series([1.0, 2.0, 3.0], index=["AAPL", "MSFT", "AMZN"])
67-
latest_returns = pd.Series([160.0, 255.0, 110.0], index=["AAPL", "MSFT", "AMZN"])
68-
69-
result = create_transactions_overview(
70-
portfolio_volume=portfolio_volume,
71-
portfolio_price=portfolio_price,
72-
portfolio_costs=portfolio_costs,
73-
latest_returns=latest_returns,
74-
)
75-
76-
assert isinstance(result, pd.DataFrame)
77-
assert len(result) == 3
78-
assert "Invested Amount" in result.columns
79-
assert "Current Value" in result.columns
80-
assert "% Return" in result.columns
81-
assert "Return" in result.columns
82-
83-
# Check calculations
84-
expected_invested = portfolio_volume * portfolio_price + abs(portfolio_costs)
85-
expected_current = portfolio_volume * latest_returns
86-
expected_return_pct = (expected_current / expected_invested) - 1
87-
88-
pd.testing.assert_series_equal(
89-
result["Invested Amount"], expected_invested, check_names=False
90-
)
91-
pd.testing.assert_series_equal(
92-
result["Current Value"], expected_current, check_names=False
93-
)
94-
pd.testing.assert_series_equal(
95-
result["% Return"], expected_return_pct, check_names=False
96-
)
97-
98-
61+
@pytest.mark.filterwarnings(
62+
"ignore:DataFrameGroupBy.apply operated on the grouping columns:DeprecationWarning"
63+
)
9964
def test_create_profit_and_loss_overview():
10065
"""Test create_profit_and_loss_overview function"""
10166
transactions_overview = pd.DataFrame(
@@ -122,6 +87,9 @@ def test_create_profit_and_loss_overview():
12287
assert "Cumulative PnL" in result.columns
12388

12489

90+
@pytest.mark.filterwarnings(
91+
"ignore:DataFrameGroupBy.apply operated on the grouping columns:DeprecationWarning"
92+
)
12593
def test_create_profit_and_loss_overview_lifo():
12694
"""Test create_profit_and_loss_overview with LIFO method"""
12795
transactions_overview = pd.DataFrame(
@@ -148,6 +116,9 @@ def test_create_profit_and_loss_overview_lifo():
148116
assert "Cumulative PnL" in result.columns
149117

150118

119+
@pytest.mark.filterwarnings(
120+
"ignore:DataFrameGroupBy.apply operated on the grouping columns:DeprecationWarning"
121+
)
151122
def test_create_profit_and_loss_overview_average():
152123
"""Test create_profit_and_loss_overview with AVERAGE method"""
153124
transactions_overview = pd.DataFrame(
@@ -202,24 +173,3 @@ def test_create_portfolio_overview_with_missing_data():
202173
betas=betas,
203174
include_portfolio=True,
204175
)
205-
206-
207-
def test_create_transactions_overview_with_negative_costs():
208-
"""Test create_transactions_overview with negative costs"""
209-
portfolio_volume = pd.Series([100, 50], index=["AAPL", "MSFT"])
210-
portfolio_price = pd.Series([150.0, 250.0], index=["AAPL", "MSFT"])
211-
portfolio_costs = pd.Series([-1.0, -2.0], index=["AAPL", "MSFT"]) # Negative costs
212-
latest_returns = pd.Series([160.0, 255.0], index=["AAPL", "MSFT"])
213-
214-
result = create_transactions_overview(
215-
portfolio_volume=portfolio_volume,
216-
portfolio_price=portfolio_price,
217-
portfolio_costs=portfolio_costs,
218-
latest_returns=latest_returns,
219-
)
220-
221-
# Should handle negative costs by taking absolute value
222-
assert result.loc["AAPL", "Invested Amount"] == 100 * 150.0 + 1.0 # abs(-1.0)
223-
assert result.loc["MSFT", "Invested Amount"] == 50 * 250.0 + 2.0 # abs(-2.0)
224-
225-
assert result.loc["MSFT", "Invested Amount"] == 50 * 250.0 + 2.0 # abs(-2.0)

0 commit comments

Comments
 (0)