@@ -77,16 +77,47 @@ def test_production_self_consumption_warns_on_negative_values() -> None:
7777 assert_series_equal (result , expected )
7878
7979
80- def test_production_self_share_masks_zero_or_negative_consumption () -> None :
81- """Self-consumption share returns NaN where consumption is not positive."""
82- production = pd .Series ([- 4.0 , - 2 .0 ], index = pd .RangeIndex (2 ))
83- consumption = pd .Series ([3.0 , 0 .0 ], index = production .index )
80+ def test_production_self_share_masks_zero_or_negative_production () -> None :
81+ """Self-consumption share returns NaN where production is not positive."""
82+ production = pd .Series ([- 4.0 , 0 .0 ], index = pd .RangeIndex (2 ))
83+ consumption = pd .Series ([3.0 , 3 .0 ], index = production .index )
8484
8585 result = metrics .production_self_share (production , consumption )
86- expected = pd .Series ([1.0 , float ("nan" )], index = production .index )
86+ expected = pd .Series ([0.75 , float ("nan" )], index = production .index )
87+ assert_series_equal (result , expected )
88+
89+
90+ def test_production_self_usage_masks_zero_or_negative_consumption () -> None :
91+ """Self-usage returns NaN where consumption is not positive."""
92+ production = pd .Series ([- 4.0 , - 2.0 ], index = pd .RangeIndex (2 ))
93+ consumption = pd .Series ([0.0 , - 1.0 ], index = production .index )
94+
95+ with pytest .warns (UserWarning ):
96+ result = metrics .production_self_usage (production , consumption )
97+ expected = pd .Series ([float ("nan" ), float ("nan" )], index = production .index )
8798 assert_series_equal (result , expected )
8899
89100
101+ def test_production_self_usage_computes_expected_values () -> None :
102+ """Self-usage computes expected ratios with PSC inputs."""
103+ production = pd .Series ([- 10.0 , - 5.0 ], index = pd .RangeIndex (2 ))
104+ consumption = pd .Series ([8.0 , 2.0 ], index = production .index )
105+
106+ usage = metrics .production_self_usage (production , consumption )
107+ expected = pd .Series ([1.0 , 1.0 ], index = production .index )
108+ assert_series_equal (usage , expected )
109+
110+
111+ def test_production_self_share_computes_expected_values () -> None :
112+ """Self-share computes expected ratios with PSC inputs."""
113+ production = pd .Series ([- 10.0 , - 5.0 ], index = pd .RangeIndex (2 ))
114+ consumption = pd .Series ([8.0 , 2.0 ], index = production .index )
115+
116+ share = metrics .production_self_share (production , consumption )
117+ expected = pd .Series ([0.8 , 0.4 ], index = production .index )
118+ assert_series_equal (share , expected )
119+
120+
90121def test_consumption_infers_total_and_sets_series_name () -> None :
91122 """Grid, production, and battery power are combined to infer consumption."""
92123 grid = pd .Series ([5 , 4 ], index = pd .RangeIndex (2 ))
0 commit comments