Skip to main content
Work with local tabular data, including how to add and delete local rows. In general, tabular attributes contain a combination of local and linked tabular columns. This example focuses on local tabular columns only. Example 12 shows how to work with linked tabular data.

Create a new record

Connect to MI and specify a database and table.
Create a new record.
Previous cell output:

Access a local tabular attribute

Access the (empty) tabular attribute Characterization of this material.
Previous cell output:
The tabular attribute __repr__ shows that the tabular attribute is not loaded yet, and so additional information about the number of rows and columns is not available. Tabular data is loaded on-demand to improve performance, and reading or modifying the data will load the data automatically. However, accessing the __repr__ does not trigger the load operation. To load the data manually, use the .load() method. Once the attribute is loaded, the __repr__ shows the number of rows and columns.
Previous cell output:
The .column_name, .column_types, and .linked_columns properties list the tabular column names, types, and whether the column is linked. Each of these properties contain 11 entries, which corresponds to the number of columns in the tabular attribute, and the size printed in the tabular attribute __repr__.
Previous cell output:
The .value property contains an immutable representation of the current state of the tabular attribute value. Since the tabular attribute is empty, this returns an empty tuple.
Previous cell output:
The .linking_table and .linking_attribute properties contain the target table and target attribute. This is a local tabular attribute, so these properties both return None.
Previous cell output:

Add rows and data

Add a new row to the tabular attribute.
Previous cell output:
An empty TabularRow object is created, which contains a blank cell for each local tabular column, stored in a tuple. The type of the cell object depends on the type of the column. Access the tuple of cell objects via the .cells property.
Previous cell output:
Often it is more convenient to access cells by their column name. The .cells_by_column property returns a mapping of column name to cell object.
Previous cell output:
Tabular cell classes have similar interfaces to their attribute value counterparts. For example, all tabular cell classes have a .value property, and picture and file tabular cell classes have a .load() method. The name of each cell type has a ‘Local’ prefix, which indicates that these are local columns and can be modified. Each tabular cell class also has a linked counterpart without the ‘Local’ prefix. These are shown in the linked tabular data example referenced in the introduction. These linked tabular cell classes are read-only and cannot be modified.

Text cells

Long text cells can accept any string value. Short text cells can accept any string value less than 255 characters. Assign the string to the .value property.

Integer cells

Integer cells can accept any integer value. Assign the integer to the .value property.

Date cells

Date cells accept a datetime.date object. Assign the date to the .value property.

Logical cells

Logical cells accept either True or False. Assign the boolean to the .value property.

Discrete cells

Discrete cells accept a limited set of allowed strings. To see which values are allowed, use the .possible_discrete_values property.
Previous cell output:
Use one of these for new value:

Point cells

Point cells accept a float value and a unit. In contrast to point attributes, point cells are always single-valued and may not contain parameter information.

Range cells

Range cells are similar to point cells, except they accept high and low float values and a unit. Each high and low bound may be marked as inclusive or exclusive, using the .low_value_is_inclusive and .high_value_is_inclusive property. Range cell classes differ from range attribute classes in that they do not contain a .value property. Cell values are set using the .low and .high properties directly.

Picture cells

Picture cells can be populated either by setting .value to a bytes object, or using the .load() method.

File cells

File cells are similar to picture cells, and can also be populated either by setting .value to a bytes object, or using the .load() method. However, file cells also have a settable .file_name and .description field.
Hyperlink cells accept a .value property which contains the link url, along with .hyperlink_display and .hyperlink_description properties which control how the hyperlink is displayed in MI Viewer.
Print the cells again to show the added values.
Previous cell output:
The data is also visible in the AttributeTabular.value property. This property is useful as a high-level summary of the data, but should not be used for processing. The .rows property provides a richer representation of the data.
Previous cell output:

Write changes to Granta MI

Finally, write the changes to the server.
Check the content of the tabular attribute after the update.
Previous cell output:

Edit tabular data

Most modifications to tabular data can be made as updates to the data already in the database. For example, adding a new row only requires the new row to be uploaded to the database, any existing data is not re-transmitted. The next cell adds two new rows, and adds data to a subset of cells in each.
Check the content of the tabular attribute after the update.
Previous cell output:
Rows can be deleted and modified in the same operation
Previous cell output:

Destructive operations

Destructive operations cannot be completed by modifying data in-place, and can only be completed by overwriting all values.
Warning:Destructive editing should be avoided because:
  • This can be slow for attributes with File or Picture attributes, especially if many rows are present.
  • Users of Data Updater will face conflicts when applying subsequent updates.
Modifying the order of rows in a tabular attribute is a destructive operation, and by default raises a ValueError.
Previous cell output:
To check whether destructive editing is allowed, use the property .is_destructive_editing_allowed:
Previous cell output:
To allow destructive editing, call the method .enable_destructive_editing(). Re-export the tabular attribute with binary data enabled to avoid an exception when calling mi.update().
Previous cell output:
Swapping rows will now not raise an exception.
Update the record in Granta MI. Note that this will re-import all data in the tabular attribute.
Previous cell output: