Bases: object

Mixin for classes publishing a result as data frame

write_output_table(df, context, output_property_name=None, output_name=None)[source]

Publishes the output df.

The context is used to control the output name:

  • If context.solver.auto_publish is true, the df is written using output_name.
  • If context.solver.auto_publish is false, This method does nothing.
  • If context.solver.auto_publish.output_property_name is true, then df is written using output_name.
  • If context.solver.auto_publish.output_propert_name is None or False, this method does nothing.
  • If context.solver.auto_publish.output_propert_name is a string, it is used as a name to publish the df


A solver can be defined as publishing a result as data frame:

class SomeSolver(PublishResultAsDf)
   def __init__(self, output_customizer):
      # output something if context.solver.autopublish.somesolver_output is set
      self.output_table_property_name = 'somesolver_output'
      # output filename unless specified by somesolver_output:
      self.default_output_table_name = 'somesolver.csv'
      # customizer if users wants one
      self.output_table_customizer = output_customizer
      # uses pandas.DataFrame if possible, otherwise will use namedtuples
      self.output_table_using_df = True

    def solve(self):
        # do something here and return a result as a df
        result = pandas.DataFrame(columns=['A','B','C'])
        return result

Example usage:

solver = SomeSolver()
results = solver.solve()