IOSpec types#
BaseIOSpec#
- class BaseIOSpec[source]#
Abstract base class for storing objects in files.
This base class is inherited from by IOSpec classes, such as
PandasDataandModuleData, and defines properties shared among the child classes. TheModel.get_specmethod returns the IOSpec object associated with a given object referenced in the model.Model.iospecsreturns a list of all the IOSpec associated with the objects referenced in the model.Example
The code below returns the
PandasDataobject associated with a DataFramedfreferenced in the model:>>> model.get_spec(df) <PandasData path='df.xlsx' file_type='excel' sheet='df1'>
The code below returns a list of all the IOSpec objects associated with the objects referenced in the model:
>>> model.iospecs [<PandasData path='df.xlsx' file_type='excel' sheet='df1'>, <PandasData path='df.xlsx' file_type='excel' sheet='s1'>, <ModuleData path='mod1.py'>]
Changed in version 0.20.0: Renamed from
BaseDataSpectoBaseIOSpecChanged in version 0.18.0: The
is_hiddenparameter is removed.Changed in version 0.18.0: Renamed from
BaseDataClienttoBaseDataSpec.See also
- property BaseIOSpec.path#
File path that the object is written to.
This property is defined in
BaseIOSpec, and returns the path to a file to which the object is written to when the model is saved by thewrite()method. The returned path is an instance of the Path class defined in pathlib module in the Python standard library. The Path class is either WindowsPath or PosixPath, depending on the platform the Python session is running on.This property also works as a setter to set the path.
stror any path-like object can be given.Example
In the code below,
dfis a DataFrame referenced inmodel, and the IPython sessin is running on Windows. The DataFrame is saved in an Excel file named df.xlsx in the model folder:>>> model.get_spec(df).path WindowsPath('df.xlsx')
The next assignment changes the file path to files/df2.xlsx under the model folder:
>>> model.get_spec(df).path = 'files/df2.xlsx' >>> model.get_spec(df).path WindowsPath('files/df.xlsx')
See also
PandasData#
- class PandasData(data, sheet=None)[source]#
A subclass of
BaseIOSpecthat associates a pandas DataFrame or Series with a fileA
PandasDataholds a pandas DataFrame or Series object, and associates it with a file for writing and reading the object.A
PandasDatacan be created only byUserSpace.new_pandasorModel.new_pandas.The DataFrame or Series held in
PandasDataobjects are accessible throughvalueproperty or a call()method.- Parameters:
path – Path to a file for saving data. If a relative path is given, it is relative to the model folder.
data – a pandas DataFrame or Series.
filetype (
str) – String to specify the file format. “excel” or “csv”
- path#
A path to the associated file as a pathlib.Path object. See
BaseIOSpec.path.
Changed in version 0.18.0: The
expose_dataparameter is removed.
- property PandasData.value#
pandas DataFrame or Series held in the object
- property PandasData.sheet#
The name of the sheet to which the data is written to
ModuleData#
- class ModuleData(module=None)[source]#
A subclass of
BaseIOSpecthat associates a user module with its source file in the modelA
ModuleDatais created either byUserSpace.new_moduleorModel.new_modulewhen a user module is assigned to a Reference. TheModuleDatais assigned to the_mx_dataclientattribute of the module.Added in version 0.13.0.
- property ModuleData.value#
Module held in the object
ExcelRange#
- class ExcelRange(range_, sheet=None, keyids=None)[source]#
Mapping class for accessing Excel ranges
An ExcelRange is a dict-like object that represents a range in an Excel file. The user can read values from the range or write values to it by the subscription operator
[]. ExcelRange is a mapping class, thus it implements all the mapping methods and operations.ExcelRange objects can only be created by the
Model.new_excel_rangeorUserSpace.new_excel_rangemethod.ExcelRangeis a subclass of theBaseIOSpecabstract class. Theiospecsproperty list all theBaseIOSpecinstances held in the Model includingExcelRangeobjects.Added in version 0.9.0.