Skip to content

Fixed IndexError when category names are missing in .json

Ghost User requested to merge missing-cat-names into master

If a _config.json does not contain some category name, then an error would appear as shown below.

Traceback (most recent call last):
  File "./dtcontrol/venv/bin/dtcontrol", line 11, in <module>
    load_entry_point('dtcontrol', 'console_scripts', 'dtcontrol')()
  File "./dtcontrol/dtcontrol/cli.py", line 597, in main
    args.func(args)
  File "./dtcontrol/dtcontrol/cli.py", line 521, in core_parser
    suite.benchmark(classifiers)
  File "./dtcontrol/dtcontrol/benchmark_suite.py", line 95, in benchmark
    cell, computed = self.compute_cell(ds, classifier)
  File "./dtcontrol/dtcontrol/benchmark_suite.py", line 133, in compute_cell
    cell = self.train_and_get_cell(dataset, classifier)
  File "./dtcontrol/dtcontrol/benchmark_suite.py", line 158, in train_and_get_cell
    self.save_dot_and_c(classifier, dataset)
  File "./dtcontrol/dtcontrol/benchmark_suite.py", line 180, in save_dot_and_c
    outfile.write(classifier.print_dot(dataset.x_metadata, dataset.y_metadata))
  File "./dtcontrol/dtcontrol/decision_tree/decision_tree.py", line 80, in print_dot
    return self.root.print_dot(x_metadata, y_metadata)
  File "./dtcontrol/dtcontrol/decision_tree/decision_tree.py", line 225, in print_dot
    text = 'digraph {{\n{}\n}}'.format(self._print_dot(0, x_metadata, y_metadata)[1])
  File "./dtcontrol/dtcontrol/decision_tree/decision_tree.py", line 260, in _print_dot
    last_number, child_text = child._print_dot(child_starting_number, x_metadata, y_metadata)
  File "./dtcontrol/dtcontrol/decision_tree/decision_tree.py", line 246, in _print_dot
    label = group[0] if not names else names[group[0]]

This MR checks if the name for the action index exists, if yes, it uses it, if no, it uses the action index itself as the name.

Merge request reports

Loading