|
1 | 1 | """ |
2 | | -Phase 13.26.ADF — dtype_overrides on read_tree |
| 2 | +Phase 13.26.ADF — dtype_overrides on read_tree (D1-D10) |
| 3 | +Phase 13.27.ADF — skip_branches on read_tree (D11-D14) |
3 | 4 |
|
4 | 5 | D1: regex pattern matching converts float64→float16 |
5 | 6 | D2: first-match-wins precedence |
|
8 | 9 | D5: NaN preserved across float downcast |
9 | 10 | D6: schema dtype_hints not overridden when no override matches |
10 | 11 | D7: round-trip: write float64, read with override, values within tolerance |
| 12 | +D8: schema round-trip preserves overridden dtype |
| 13 | +D9: entry_range with overrides consistent |
| 14 | +D10: overflow warning shows correct original→target dtype |
| 15 | +D11: skip_branches excludes branch from DataFrame |
| 16 | +D12: skip reduces column count; remaining data correct |
| 17 | +D13: skip + dtype_override work together independently |
| 18 | +D14: skip with no match is a no-op |
11 | 19 | """ |
12 | 20 |
|
13 | 21 | import os |
@@ -228,3 +236,60 @@ def test_D10_override_warning_shows_correct_dtypes(self, tmp_root_file): |
228 | 236 |
|
229 | 237 | if __name__ == '__main__': |
230 | 238 | pytest.main([__file__, '-v', '-s']) |
| 239 | + |
| 240 | + |
| 241 | +# =========================================================================== |
| 242 | +# Phase 13.27.ADF — skip_branches tests |
| 243 | +# =========================================================================== |
| 244 | + |
| 245 | +@pytest.mark.skipif(not _HAS_ROOT, reason="Requires ROOT + uproot") |
| 246 | +class TestSkipBranches: |
| 247 | + |
| 248 | + @pytest.mark.invariance |
| 249 | + def test_D11_skip_branch_not_in_dataframe(self, tmp_root_file): |
| 250 | + """skip_branches pattern excludes branch from DataFrame entirely.""" |
| 251 | + adf = AliasDataFrame.read_tree(tmp_root_file, "tree", skip_branches=[ |
| 252 | + r'dy_err_PIter1', |
| 253 | + ]) |
| 254 | + assert 'dy_err_PIter1' not in adf.df.columns, \ |
| 255 | + "D11: skipped branch should not appear in DataFrame" |
| 256 | + # Other branches still present |
| 257 | + assert 'dy_intercept_PIter1' in adf.df.columns |
| 258 | + assert 'x' in adf.df.columns |
| 259 | + |
| 260 | + @pytest.mark.invariance |
| 261 | + def test_D12_skip_reduces_column_count(self, tmp_root_file): |
| 262 | + """Skipping branches reduces column count; remaining data correct.""" |
| 263 | + adf_full = AliasDataFrame.read_tree(tmp_root_file, "tree") |
| 264 | + adf_skip = AliasDataFrame.read_tree(tmp_root_file, "tree", skip_branches=[ |
| 265 | + r'dy_err_PIter1', |
| 266 | + r'dz_intercept_PIter2', |
| 267 | + ]) |
| 268 | + assert len(adf_skip.df.columns) == len(adf_full.df.columns) - 2, \ |
| 269 | + f"D12: expected {len(adf_full.df.columns) - 2} columns, got {len(adf_skip.df.columns)}" |
| 270 | + # Remaining columns have identical values |
| 271 | + for col in adf_skip.df.columns: |
| 272 | + np.testing.assert_array_equal( |
| 273 | + adf_skip.df[col].values, adf_full.df[col].values, |
| 274 | + err_msg=f"D12: column {col} values differ after skip") |
| 275 | + |
| 276 | + @pytest.mark.invariance |
| 277 | + def test_D13_skip_and_dtype_override_combined(self, tmp_root_file): |
| 278 | + """skip_branches and dtype_overrides work together independently.""" |
| 279 | + adf = AliasDataFrame.read_tree(tmp_root_file, "tree", |
| 280 | + dtype_overrides={r'dy_intercept_PIter1': np.float16}, |
| 281 | + skip_branches=[r'dy_err_PIter1'], |
| 282 | + ) |
| 283 | + assert 'dy_err_PIter1' not in adf.df.columns |
| 284 | + assert adf.df['dy_intercept_PIter1'].dtype == np.float16 |
| 285 | + # Non-skipped, non-overridden column unchanged |
| 286 | + assert 'x' in adf.df.columns |
| 287 | + |
| 288 | + @pytest.mark.invariance |
| 289 | + def test_D14_skip_no_match_is_noop(self, tmp_root_file): |
| 290 | + """skip_branches with no matching pattern leaves all columns intact.""" |
| 291 | + adf_full = AliasDataFrame.read_tree(tmp_root_file, "tree") |
| 292 | + adf_skip = AliasDataFrame.read_tree(tmp_root_file, "tree", skip_branches=[ |
| 293 | + r'nonexistent_column_.*', |
| 294 | + ]) |
| 295 | + assert list(adf_skip.df.columns) == list(adf_full.df.columns) |
0 commit comments