Data mutability and ownership: Terality vs pandas
Unlike pandas, Terality always copies data and avoids shared mutable data. Differences with pandas on this topic are documented here.
Last updated
Was this helpful?
Unlike pandas, Terality always copies data and avoids shared mutable data. Differences with pandas on this topic are documented here.
Last updated
Was this helpful?
With pandas, indexing operations can return either a copy or a view. Consider the following code:
Here, df['a']
is a copy of the columna
. As a result, will not mutate df
:
will print df
unchanged.
Whether an indexing operation returns a copy (as above) or a view depends on the underlying memory layout, and is hard to predict as a user. Pandas has an entire dedicated to this issue.
Additionally, pandas exposes functions that share Python objects between two dataframes: functions like can result in two dataframes where mutating one will also mutate the other, leading to error-prone code.
In order to both simplify the API surface and enable performance optimizations, Terality implements a simpler model than the pandas API.
With Terality, all operations (such as indexing functions) always return copies of the data. Terality never returns views.
Data in a Terality structure (whether a Series or a DataFrame) is never shared with any other structure. Mutating a structure is guaranteed not to mutate any other structure.
As a result, some operations will always raise an error in Terality. This should help avoiding common mistakes with pandas code.
With Terality, chained indexing (as described in the first section) will never mutate the original DataFrame. Use (and the iloc
variant) instead of chained indexing when you want to assign to the result of an indexing operation.
and always perform a recursive deep copy. Passing deep=False
is an error.
is not supported: data can not be shared between two Series.
Some pandas functions (such as the or ) accept a copy
argument that determines whether data should be copied during the operation. With Terality, only copy=True
is accepted. Setting copy=False
will raise an error.