File tree Expand file tree Collapse file tree 3 files changed +13
-10
lines changed
Expand file tree Collapse file tree 3 files changed +13
-10
lines changed Original file line number Diff line number Diff line change 11import matplotlib .pyplot as plt
22import requests
33import streamlit as st
4+ from validation import eia_schema
45
56from tests .eia_part3 import (
67 build_df_from_eia_data ,
@@ -59,8 +60,6 @@ def fetch_supply_json(url: str) -> dict:
5960
6061# Filter (2012–present)
6162df = filter_since (df , date_col = "week" , start_date = "2012-01-01" )
62- from tests .validation import eia_schema
63-
6463df = eia_schema .validate (df )
6564
6665weekly_total = sum_by_week (df , date_col = "week" , value_col = "value" )
Original file line number Diff line number Diff line change 11import pandas as pd
2+ import pandera as pa
23import pytest
34from validation import eia_schema
45
56
67def test_schema_rejects_negative_values ():
7- df = pd .DataFrame ({
8- "week" : pd .to_datetime (["2012-01-06" ]),
9- "value" : [- 5 ]
10- })
8+ df = pd .DataFrame (
9+ {
10+ "week" : pd .to_datetime (["2012-01-06" ]),
11+ "value" : [- 5 ],
12+ }
13+ )
14+
15+ with pytest .raises (pa .errors .SchemaError ):
16+ eia_schema .validate (df )
1117
12- with pytest .raises (Exception ):
13- eia_schema .validate (df )
Original file line number Diff line number Diff line change 66 "week" : Column (pa .DateTime ),
77 "value" : Column (
88 pa .Float ,
9- coerce = True ,
10- checks = Check .ge (0 ),
9+ coerce = True ,
10+ checks = Check .ge (0 ),
1111 nullable = False ,
1212 ),
1313 }
You can’t perform that action at this time.
0 commit comments