ENH: Revise Python API for loading/saving games
Game objects currently just have generic .read_game and .write_game operations, where .write_game takes a format parameter to determine the output format, while .read_game tries various formats until one is successful.
Looking at e.g. pandas, it seems it would be better to have functions that explicitly read and write the different supported formats.
As an initial concrete proposal, we suggest we'll follow the conventions that pandas uses in its I/O functions. Specifically, one can look at read_csv (https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html) and to_csv (https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_csv.html).
Specifically, we will have the following:
- The functions for reading files will be module-level in
pygambit. (The current functions are all part of theGameclass.) - When reading, the first argument should be a string, path object, or file-like object, just like
read_*inpandas. - When writing, the first argument is optional, and can be a string, path object, or file-like object, or null. If null, the function returns the serialised string representation.
We will have the following functions (please add a note if there are others that are missing)
- Reading
-
read_efg- reads an .efg file format -
read_nfg- reads an .nfg file format -
read_gbt- reads a .gbt file (XML files produced by the GUI) -
read_agg- reads an action-graph games file format
-
- Writing
-
Game.to_efg- writes an .efg file -
Game.to_nfg- writes an .nfg file -
Game.to_gbt- writes a .gbt file -
Game.to_html- writes out HTML tables -
Game.to_latex- currently thesgameformat supported byGame.write. - (there is not at present support for writing out AGG files so no need to have this as yet)
-
The function Game.parse_game will be deprecated, as its functionality can be replicated by wrapping such a string in an io.StringIO object and then passing it to the appropriate read_* function as above, which functions will now accept file-like objects.