Drop NaN rows before validation

This commit is contained in:
thePR0M3TH3AN committed 2025-05-31 22:04:08 -04:00
1 parent 02a89740bb
commit f33fac02c2
2 files changed
+64 -18

No files matched your search

+54 -17
View File
@@ -12,15 +12,25 @@ from scripts.bitcoin_m2_chart import plot_bitcoin_m2, main as btc_m2_main
def sample_data():
dates = pd.date_range("2021-01-01", periods=5, freq="D")
btc = pd.DataFrame({"value": [10, 11, 12, 13, 14]}, index=dates)
m2 = pd.DataFrame({"value": [1, 2, 3, 4, 5]}, index=dates)
btc_dates = pd.date_range("2024-07-01", periods=10, freq="D")
btc = pd.DataFrame({"value": range(10, 20)}, index=btc_dates)
m2_dates = btc_dates
m2 = pd.DataFrame({"value": range(1, 11)}, index=m2_dates)
return btc, m2
def sample_data_with_nan():
btc_dates = pd.date_range("2024-07-01", periods=10, freq="D")
btc = pd.DataFrame({"value": range(10, 20)}, index=btc_dates)
m2_dates = btc_dates
m2_values = list(range(1, 10)) + [pd.NA]
m2 = pd.DataFrame({"value": m2_values}, index=m2_dates)
return btc, m2
def test_plot_bitcoin_m2_returns_figure():
btc, m2 = sample_data()
fig = plot_bitcoin_m2(btc, m2, 94, 1)
fig = plot_bitcoin_m2(btc, m2, 0, 1)
assert len(fig.axes) == 2
assert any(ax.get_lines() for ax in fig.axes)
@@ -32,19 +42,44 @@ def test_btc_m2_main(monkeypatch):
return btc, m2
monkeypatch.setattr("scripts.bitcoin_m2_chart.fetch_series", fake_fetch)
fig = btc_m2_main([
"--btc-series",
"BTC",
"--m2-series",
"M2",
"--width",
"8",
"--height",
"4",
"--dpi",
"150",
"--no-show",
])
fig = btc_m2_main(
[
"--btc-series",
"BTC",
"--m2-series",
"M2",
"--offset",
"0",
"--width",
"8",
"--height",
"4",
"--dpi",
"150",
"--no-show",
]
)
assert len(fig.axes) == 2
def test_main_handles_trailing_nan(monkeypatch):
btc, m2 = sample_data_with_nan()
def fake_fetch(*_args, **_kwargs):
return btc, m2
monkeypatch.setattr("scripts.bitcoin_m2_chart.fetch_series", fake_fetch)
fig = btc_m2_main(
[
"--btc-series",
"BTC",
"--m2-series",
"M2",
"--offset",
"0",
"--no-show",
]
)
assert len(fig.axes) == 2
@@ -64,6 +99,8 @@ def test_btc_m2_main_saves_output(tmp_path, monkeypatch):
"M2",
"--output",
str(out_file),
"--offset",
"0",
"--width",
"8",
"--height",