为什么FrozenList与tuple不同? [英] Why is FrozenList different from tuple?

查看:163
本文介绍了为什么FrozenList与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's technically non-hashable, will be used
for lookups, appropriately, etc.

为什么不只使用元组? FrozenList将提供哪些额外功能?

Why not just use tuple? What extra functionality would a FrozenList offer?

推荐答案

这是内部的熊猫结构.不使用元组的原因是:

This is an internal pandas construct. Not using tuple because:

  • 它继承自一个普通的熊猫类
  • 可自定义(例如repr)
  • 它没有元组的全部功能(有些已禁用)
  • 它不是可哈希的(因此更像是这里的列表,而不是元组)

该构造用于表示MultiIndex级别,标签和名称.这样做的目的是防止修改这些直通属性,并强制使用方法(例如set_levels()).由于这些状态不能单独更改(对于级别/标签),而必须一起更改.

The construct is used to represent a MultiIndex levels,labels, and names. The point of it is to prevent modification of these thru attributes and force the use of methods (e.g. set_levels()). As the state of these cannot be changed independent (for level/labels), but must be changed together.

尽管这些是公共"属性,所以它需要一种可以完成所有这些操作的访问机制(但出于性能方面的考虑,仍需要在内部进行更改).

These are 'public' properties though, so it needed an access mechanism that could do all of this (and yet still be changed internally if necessary, for performance reasons).

这篇关于为什么FrozenList与tuple不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆