Skip to content

Commit f8243a8

Browse files
committed
fix a bug in csv_analyzer that was assuming target values were always in ascending order.
1 parent 60743f4 commit f8243a8

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

src/ssvc/csv_analyzer.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,17 @@ def permute_feature_importance(df: pd.DataFrame, target: str) -> pd.DataFrame:
326326
return imp
327327

328328

329-
def check_topological_order(df: pd.DataFrame, target: str) -> list[dict]:
329+
def check_topological_order(df: pd.DataFrame, target: str, target_value_order: list[str]=None) -> list[dict]:
330330
# split df into features and target
331331
X, y = _prepare_data(df, target)
332332

333-
# convert outcome to numeric codes
334-
codes = list(enumerate(y.unique()))
333+
if target_value_order is None:
334+
# convert outcome to numeric codes
335+
codes = list(enumerate(y.unique()))
336+
else:
337+
# use the provided order for the target values
338+
codes = list(enumerate(target_value_order))
339+
335340
mapper = {v: k for (k, v) in codes}
336341
y = y.replace(mapper)
337342

src/ssvc/decision_tables/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,9 @@ def check_topological_order(dt: DecisionTable) -> list[dict]:
565565
logger.debug("Checking topological order of the decision table.")
566566
df = decision_table_to_shortform_df(dt)
567567
target = _get_target_column_name(df.columns[-1])
568-
return check_topological_order(df, target=target)
568+
target_values = dt.decision_points[dt.outcome].values
569+
target_value_order = [v.key for v in target_values]
570+
return check_topological_order(df, target=target, target_value_order=target_value_order)
569571

570572

571573
def main() -> None:
Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
#!/usr/bin/env python
22
"""
3-
file: __init__.py
4-
author: adh
5-
created_at: 7/18/25 12:10 PM
3+
Provides Decision Tables within the SSVC namespace.
64
"""
7-
8-
def main():
9-
pass
10-
11-
if __name__ == '__main__':
12-
main()
5+
# Copyright (c) 2025 Carnegie Mellon University.
6+
# NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE
7+
# ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN "AS-IS" BASIS.
8+
# CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND,
9+
# EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT
10+
# NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR
11+
# MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE
12+
# OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE
13+
# ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM
14+
# PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT.
15+
# Licensed under a MIT (SEI)-style license, please see LICENSE or contact
16+
# permission@sei.cmu.edu for full terms.
17+
# [DISTRIBUTION STATEMENT A] This material has been approved for
18+
# public release and unlimited distribution. Please see Copyright notice
19+
# for non-US Government use and distribution.
20+
# This Software includes and/or makes use of Third-Party Software each
21+
# subject to its own license.
22+
# DM24-0278

0 commit comments

Comments
 (0)