Why is a FrozenList different from a tuple?

from pandas.core.base import FrozenList Type: type String form: <class 'pandas.core.base.FrozenList'> File: /site-packages/pandas/core/base.py Docstring: Container that doesn't allow setting item *but* because it technically non-hashable, will be used for lookups, appropriately, etc. 

Why not just use a tuple ? What additional functionality does FrozenList offer?

+8
python pandas
source share
1 answer

This is the inner construction of pandas. Do not use a tuple because:

  • It inherits from the general pandas class
  • Its customizable (e.g. editor)
  • It does not have absolutely all tuple functions (some of them are disabled)
  • This is nots hashable (it looks more like a list here, not a tuple)

The construct is used to represent levels, labels, and names of MultiIndex. The point is to prevent the modification of these attributes and force the use of methods (for example, set_levels() ). Since their state cannot be changed independently (for level / labels), but must be changed together.

These are โ€œpublicly availableโ€ properties, so an access mechanism that could do all this (and still have to be changed if necessary for performance reasons) is required for this.

+13
source share

All Articles