save: save and export tables into files

Code author: Ueli Sauter, Peter Kraus

The function dgpost.utils.save.save() processes the below specification in order to save the given DataFrame:

pydantic model dgbowl_schemas.dgpost.recipe.Save

Save a table into an external (pkl, xlsx) file.

Show JSON schema
{
   "title": "Save",
   "description": "Save a table into an external (``pkl``, ``xlsx``) file.",
   "type": "object",
   "properties": {
      "table": {
         "title": "Table",
         "type": "string"
      },
      "as": {
         "title": "As",
         "type": "string"
      },
      "type": {
         "anyOf": [
            {
               "enum": [
                  "pkl",
                  "json",
                  "xlsx",
                  "csv",
                  "nc"
               ],
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Type"
      },
      "columns": {
         "anyOf": [
            {
               "items": {
                  "type": "string"
               },
               "type": "array"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Columns"
      },
      "sigma": {
         "default": true,
         "title": "Sigma",
         "type": "boolean"
      }
   },
   "additionalProperties": false,
   "required": [
      "table",
      "as"
   ]
}

Config:
  • extra: str = forbid

  • populate_by_name: bool = True

field table: str [Required]

The name of the table loaded in memory to be stored.

field as_: str [Required] (alias 'as')

Path to which the table is stored.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

field type: Optional[Literal['pkl', 'json', 'xlsx', 'csv', 'nc']] = None

Type of the output file.

Note

Round-tripping of dgpost data is only possible using the pkl and nc formats. For long-term storage, the json and nc formats may be better suited. The other formats (xlsx and csv) are provided for convenience only and should not be used for chaining of dgpost runs.

field columns: Optional[Sequence[str]] = None

Columns to be exported. By default (None), all columns from the specified table will be exported.

Note

If any of the columns supplied is not present in the table, a warning will be printed by dgpost.

field sigma: bool = True

Whether uncertainties/error estimates in the data should be stripped. Particularly useful when exporting into xlsx or csv.

Note

Metadata, including the recipe used to create the saved file, as well as provenance information about the version of dgpost used to process the recipe are saved into the df.attrs["meta"] entry and therefore only available in pkl or json exports.

dgpost.utils.save.save(table, path, type=None, columns=None, sigma=True, meta=None)
Return type:

None