1.3.0 版本新特性 (2021年7月2日)#

以下是 pandas 1.3.0 中的更改。有关完整的更改日志,包括其他版本的 pandas,请参阅发行说明

警告

读取新的 Excel 2007+ (.xlsx) 文件时,read_excel() 的默认参数 engine=None 现在将在选项 io.excel.xlsx.reader 设置为 "auto" 的所有情况下使用 openpyxl 引擎。之前,有些情况下会改用 xlrd 引擎。有关此更改的背景信息,请参阅1.2.0 版本新特性

改进#

读取 csv 或 json 文件时自定义 HTTP(s) 头部#

当从 fsspec 未处理的远程 URL(例如 HTTP 和 HTTPS)读取时,传递给 storage_options 的字典将用于创建请求中包含的头部。这可用于控制 User-Agent 头部或发送其他自定义头部(GH 36688)。例如:

In [1]: headers = {"User-Agent": "pandas"}
In [2]: df = pd.read_csv(
   ...:     "https://download.bls.gov/pub/time.series/cu/cu.item",
   ...:     sep="\t",
   ...:     storage_options=headers
   ...: )

读写 XML 文档#

我们添加了 I/O 支持,可以使用 read_xml()DataFrame.to_xml() 读取和渲染 XML 文档的浅层版本。使用 lxml 作为解析器,支持 XPath 1.0 和 XSLT 1.0。(GH 27554

In [1]: xml = """<?xml version='1.0' encoding='utf-8'?>
   ...: <data>
   ...:  <row>
   ...:     <shape>square</shape>
   ...:     <degrees>360</degrees>
   ...:     <sides>4.0</sides>
   ...:  </row>
   ...:  <row>
   ...:     <shape>circle</shape>
   ...:     <degrees>360</degrees>
   ...:     <sides/>
   ...:  </row>
   ...:  <row>
   ...:     <shape>triangle</shape>
   ...:     <degrees>180</degrees>
   ...:     <sides>3.0</sides>
   ...:  </row>
   ...:  </data>"""

In [2]: df = pd.read_xml(xml)
In [3]: df
Out[3]:
      shape  degrees  sides
0    square      360    4.0
1    circle      360    NaN
2  triangle      180    3.0

In [4]: df.to_xml()
Out[4]:
<?xml version='1.0' encoding='utf-8'?>
<data>
  <row>
    <index>0</index>
    <shape>square</shape>
    <degrees>360</degrees>
    <sides>4.0</sides>
  </row>
  <row>
    <index>1</index>
    <shape>circle</shape>
    <degrees>360</degrees>
    <sides/>
  </row>
  <row>
    <index>2</index>
    <shape>triangle</shape>
    <degrees>180</degrees>
    <sides>3.0</sides>
  </row>
</data>

更多信息请参见用户指南中关于 IO 工具的编写 XML章节。

Styler 改进#

我们对 Styler 进行了一些重点开发。另请参见已经修订和改进的Styler 文档GH 39720GH 39317GH 40493)。

DataFrame 构造函数在使用 dict 时遵守 copy=False#

当向 DataFrame 传递字典并设置 copy=False 时,将不再进行复制(GH 32960)。

In [1]: arr = np.array([1, 2, 3])

In [2]: df = pd.DataFrame({"A": arr, "B": arr.copy()}, copy=False)

In [3]: df
Out[3]: 
   A  B
0  1  1
1  2  2
2  3  3

df["A"] 仍是 arr 的一个视图

In [4]: arr[0] = 0

In [5]: assert df.iloc[0, 0] == 0

不传递 copy 时的默认行为保持不变,即会进行复制。

PyArrow 支持的字符串数据类型#

我们增强了 StringDtype,这是一种专门用于字符串数据的扩展类型。(GH 39908

现在可以为 StringDtype 指定关键字选项 storage。可以使用 pandas 选项或通过 dtype='string[pyarrow]' 指定 dtype,使 StringArray 由 PyArrow 数组而不是 Python 对象的 NumPy 数组支持。

PyArrow 支持的 StringArray 需要安装 pyarrow 1.0.0 或更高版本。

警告

string[pyarrow] 目前被认为是实验性的。实现和部分 API 可能会在没有警告的情况下更改。

In [6]: pd.Series(['abc', None, 'def'], dtype=pd.StringDtype(storage="pyarrow"))
Out[6]: 
0     abc
1    <NA>
2     def
dtype: string

您也可以使用别名 "string[pyarrow]"

In [7]: s = pd.Series(['abc', None, 'def'], dtype="string[pyarrow]")

In [8]: s
Out[8]: 
0     abc
1    <NA>
2     def
dtype: string

您还可以使用 pandas 选项创建由 PyArrow 支持的字符串数组。

In [9]: with pd.option_context("string_storage", "pyarrow"):
   ...:     s = pd.Series(['abc', None, 'def'], dtype="string")
   ...: 

In [10]: s
Out[10]: 
0     abc
1    <NA>
2     def
dtype: string

通常的字符串 accessor 方法都可用。在适当的情况下,Series 或 DataFrame 列的返回类型也将是字符串 dtype。

In [11]: s.str.upper()
Out[11]: 
0     ABC
1    <NA>
2     DEF
dtype: string

In [12]: s.str.split('b', expand=True).dtypes
Out[12]: 
0    string[pyarrow]
1    string[pyarrow]
dtype: object

返回整数的字符串 accessor 方法将返回具有 Int64Dtype 的值

In [13]: s.str.count("a")
Out[13]: 
0       1
1    <NA>
2       0
dtype: Int64

居中的 datetime-like 滚动窗口#

在对具有 datetime-like 索引的 DataFrame 和 Series 对象执行滚动计算时,现在可以使用居中的 datetime-like 窗口(GH 38780)。例如:

In [14]: df = pd.DataFrame(
   ....:     {"A": [0, 1, 2, 3, 4]}, index=pd.date_range("2020", periods=5, freq="1D")
   ....: )
   ....: 

In [15]: df
Out[15]: 
            A
2020-01-01  0
2020-01-02  1
2020-01-03  2
2020-01-04  3
2020-01-05  4

In [16]: df.rolling("2D", center=True).mean()
Out[16]: 
              A
2020-01-01  0.5
2020-01-02  1.5
2020-01-03  2.5
2020-01-04  3.5
2020-01-05  4.0

其他改进#

显著的 Bug 修复#

这些 Bug 修复可能会导致行为上的显著改变。

Categorical.unique 现在总是保持与原始数据相同的 dtype#

之前,在使用分类数据调用 Categorical.unique() 时,新数组中未使用的类别会被移除,导致新数组的 dtype 与原始数据不同 (GH 18291)

举个例子,假设有

In [17]: dtype = pd.CategoricalDtype(['bad', 'neutral', 'good'], ordered=True)

In [18]: cat = pd.Categorical(['good', 'good', 'bad', 'bad'], dtype=dtype)

In [19]: original = pd.Series(cat)

In [20]: unique = original.unique()

旧的行为:

In [1]: unique
['good', 'bad']
Categories (2, object): ['bad' < 'good']
In [2]: original.dtype == unique.dtype
False

新的行为:

In [21]: unique
Out[21]: 
['good', 'bad']
Categories (3, object): ['bad' < 'neutral' < 'good']

In [22]: original.dtype == unique.dtype
Out[22]: True

DataFrame.combine_first() 中保留 dtypes#

DataFrame.combine_first() 现在将保留 dtypes (GH 7509)

In [23]: df1 = pd.DataFrame({"A": [1, 2, 3], "B": [1, 2, 3]}, index=[0, 1, 2])

In [24]: df1
Out[24]: 
   A  B
0  1  1
1  2  2
2  3  3

In [25]: df2 = pd.DataFrame({"B": [4, 5, 6], "C": [1, 2, 3]}, index=[2, 3, 4])

In [26]: df2
Out[26]: 
   B  C
2  4  1
3  5  2
4  6  3

In [27]: combined = df1.combine_first(df2)

旧的行为:

In [1]: combined.dtypes
Out[2]:
A    float64
B    float64
C    float64
dtype: object

新的行为:

In [28]: combined.dtypes
Out[28]: 
A    float64
B      int64
C    float64
dtype: object

Groupby 方法 agg 和 transform 不再改变可调用对象的返回 dtype#

之前,当参数 func 是可调用对象时,方法 DataFrameGroupBy.aggregate()SeriesGroupBy.aggregate()DataFrameGroupBy.transform()SeriesGroupBy.transform() 可能会转换结果的 dtype,可能导致不期望的结果 (GH 21240)。如果结果是数值类型并且通过 np.allclose 衡量转换回输入 dtype 不改变任何值时,就会发生转换。现在不再发生这种转换。

In [29]: df = pd.DataFrame({'key': [1, 1], 'a': [True, False], 'b': [True, True]})

In [30]: df
Out[30]: 
   key      a     b
0    1   True  True
1    1  False  True

旧的行为:

In [5]: df.groupby('key').agg(lambda x: x.sum())
Out[5]:
        a  b
key
1    True  2

新的行为:

In [31]: df.groupby('key').agg(lambda x: x.sum())
Out[31]: 
     a  b
key      
1    1  2

float 结果 for DataFrameGroupBy.mean()DataFrameGroupBy.median()GDataFrameGroupBy.var()SeriesGroupBy.mean()SeriesGroupBy.median()SeriesGroupBy.var()#

之前,这些方法的结果 dtype 可能取决于输入值。现在,这些方法将总是返回 float dtype。 (GH 41137)

In [32]: df = pd.DataFrame({'a': [True], 'b': [1], 'c': [1.0]})

旧的行为:

In [5]: df.groupby(df.index).mean()
Out[5]:
        a  b    c
0    True  1  1.0

新的行为:

In [33]: df.groupby(df.index).mean()
Out[33]: 
     a    b    c
0  1.0  1.0  1.0

使用 lociloc 设置值时尝试原地操作#

当使用 lociloc 设置整列时,pandas 将尝试将值插入现有数据中,而不是创建一个全新的数组。

In [34]: df = pd.DataFrame(range(3), columns=["A"], dtype="float64")

In [35]: values = df.values

In [36]: new = np.array([5, 6, 7], dtype="int64")

In [37]: df.loc[[0, 1, 2], "A"] = new

在新旧行为中,values 中的数据都被覆盖,但在旧行为中 df["A"] 的 dtype 改变为 int64

旧的行为:

In [1]: df.dtypes
Out[1]:
A    int64
dtype: object
In [2]: np.shares_memory(df["A"].values, new)
Out[2]: False
In [3]: np.shares_memory(df["A"].values, values)
Out[3]: False

在 pandas 1.3.0 中,df 继续与 values 共享数据

新的行为:

In [38]: df.dtypes
Out[38]: 
A    float64
dtype: object

In [39]: np.shares_memory(df["A"], new)
Out[39]: False

In [40]: np.shares_memory(df["A"], values)
Out[40]: True

设置 frame[keys] = values 时永远不进行原地操作#

当使用 frame[keys] = values 设置多列时,新数组将替换这些键对应的现有数组,现有数组*不会*被覆盖 (GH 39510)。因此,这些列将保留 values 的 dtype(s),不会转换为现有数组的 dtype。

In [41]: df = pd.DataFrame(range(3), columns=["A"], dtype="float64")

In [42]: df[["A"]] = 5

在旧行为中,5 被转换为 float64 并插入到 df 后面的现有数组中

旧的行为:

In [1]: df.dtypes
Out[1]:
A    float64

在新行为中,我们得到一个新数组,并保留一个整数 dtype 的 5

新的行为:

In [43]: df.dtypes
Out[43]: 
A    int64
dtype: object

向布尔 Series 设置值时保持一致的类型转换#

dtype=boolSeries 设置非布尔值时,现在会一致地转换为 dtype=object (GH 38709)

In [1]: orig = pd.Series([True, False])

In [2]: ser = orig.copy()

In [3]: ser.iloc[1] = np.nan

In [4]: ser2 = orig.copy()

In [5]: ser2.iloc[1] = 2.0

旧的行为:

In [1]: ser
Out [1]:
0    1.0
1    NaN
dtype: float64

In [2]:ser2
Out [2]:
0    True
1     2.0
dtype: object

新的行为:

In [1]: ser
Out [1]:
0    True
1     NaN
dtype: object

In [2]:ser2
Out [2]:
0    True
1     2.0
dtype: object

DataFrameGroupBy.rolling 和 SeriesGroupBy.rolling 不再在返回值中包含分组列#

分组列现在将从 groupby.rolling 操作的结果中被移除 (GH 32262)

In [44]: df = pd.DataFrame({"A": [1, 1, 2, 3], "B": [0, 1, 2, 3]})

In [45]: df
Out[45]: 
   A  B
0  1  0
1  1  1
2  2  2
3  3  3

旧的行为:

In [1]: df.groupby("A").rolling(2).sum()
Out[1]:
       A    B
A
1 0  NaN  NaN
1    2.0  1.0
2 2  NaN  NaN
3 3  NaN  NaN

新的行为:

In [46]: df.groupby("A").rolling(2).sum()
Out[46]: 
       B
A       
1 0  NaN
  1  1.0
2 2  NaN
3 3  NaN

移除了滚动方差和标准差中的人为截断#

Rolling.std()Rolling.var() 不再将小于 ~1e-8~1e-15 的结果人为地截断为零 (GH 37051, GH 40448, GH 39872)。

然而,在对较大的值进行滚动计算时,结果中现在可能存在浮点数误差。

In [47]: s = pd.Series([7, 5, 5, 5])

In [48]: s.rolling(3).var()
Out[48]: 
0         NaN
1         NaN
2    1.333333
3    0.000000
dtype: float64

带有 MultiIndex 的 DataFrameGroupBy.rolling 和 SeriesGroupBy.rolling 不再在结果中丢弃级别#

DataFrameGroupBy.rolling()SeriesGroupBy.rolling() 不再在结果中丢弃带有 MultiIndexDataFrame 的级别。这可能导致结果 MultiIndex 中出现感知的级别重复,但此更改恢复了 1.1.3 版本中的行为 (GH 38787, GH 38523)。

In [49]: index = pd.MultiIndex.from_tuples([('idx1', 'idx2')], names=['label1', 'label2'])

In [50]: df = pd.DataFrame({'a': [1], 'b': [2]}, index=index)

In [51]: df
Out[51]: 
               a  b
label1 label2      
idx1   idx2    1  2

旧的行为:

In [1]: df.groupby('label1').rolling(1).sum()
Out[1]:
          a    b
label1
idx1    1.0  2.0

新的行为:

In [52]: df.groupby('label1').rolling(1).sum()
Out[52]: 
                        a    b
label1 label1 label2          
idx1   idx1   idx2    1.0  2.0

向后不兼容的 API 变更#

提高依赖项的最低版本要求#

某些依赖项的最低支持版本已更新。如果已安装,现在要求

最低版本

必需

已变更

numpy

1.17.3

X

X

pytz

2017.3

X

python-dateutil

2.7.3

X

bottleneck

1.2.1

numexpr

2.7.0

X

pytest (dev)

6.0

X

mypy (dev)

0.812

X

setuptools

38.6.0

X

对于可选库,通常建议使用最新版本。下表列出了 pandas 开发过程中当前正在测试的每个库的最低版本。低于最低测试版本的可选库可能仍然可用,但不被视为支持。

最低版本

已变更

beautifulsoup4

4.6.0

fastparquet

0.4.0

X

fsspec

0.7.4

gcsfs

0.6.0

lxml

4.3.0

matplotlib

2.2.3

numba

0.46.0

openpyxl

3.0.0

X

pyarrow

0.17.0

X

pymysql

0.8.1

X

pytables

3.5.1

s3fs

0.4.0

scipy

1.2.0

sqlalchemy

1.3.0

X

tabulate

0.8.7

X

xarray

0.12.0

xlrd

1.2.0

xlsxwriter

1.0.2

xlwt

1.3.0

pandas-gbq

0.12.0

有关更多信息,请参阅 DependenciesOptional dependencies

其他 API 变更#

  • 部分初始化(即 categories=None)的 CategoricalDtype 对象将不再与完全初始化的 dtype 对象比较相等 (GH 38516)

  • DataFrame 上访问 _constructor_expanddim 和在 Series 上访问 _constructor_sliced 现在会引发 AttributeError。之前引发的是 NotImplementedError (GH 38782)

  • DataFrame.to_sql() 添加了新的 engine**engine_kwargs 参数,以支持未来其他的“SQL 引擎”。目前我们仍然只在底层使用 SQLAlchemy,但计划支持更多引擎,例如 turbodbc (GH 36893)

  • 移除了 PeriodIndex 字符串表示中的冗余 freq (GH 41653)

  • 对于 ExtensionDtype 子类,ExtensionDtype.construct_array_type() 现在是必需的方法,而不是可选的方法 (GH 24860)

  • 对不可哈希的 pandas 对象调用 hash 现在将引发带有内置错误消息(例如 unhashable type: 'Series')的 TypeError。之前会引发自定义消息,例如 'Series' objects are mutable, thus they cannot be hashed。此外,isinstance(<Series>, abc.collections.Hashable) 现在将返回 False (GH 40013)

  • Styler.from_custom_template() 现在新增了两个模板名称参数,并移除了旧的 name 参数,这是因为引入了模板继承以更好地进行解析 (GH 42053)。还需要对 Styler 属性的子类进行修改。

构建#

  • .pptx.pdf 格式的文档不再包含在 wheel 包或源码分发中。(GH 30741)

废弃#

DataFrame reductions 和 DataFrameGroupBy 操作中丢弃无关列的行为已废弃#

numeric_only=None(默认值)的 DataFrame 上调用 reduction 方法(例如 .min.max.sum)时,reduction 操作会引发 TypeError 的列会被静默忽略并从结果中丢弃。

此行为已废弃。在未来的版本中,将引发 TypeError,用户需要在调用函数之前仅选择有效的列。

例如

In [53]: df = pd.DataFrame({"A": [1, 2, 3, 4], "B": pd.date_range("2016-01-01", periods=4)})

In [54]: df
Out[54]: 
   A          B
0  1 2016-01-01
1  2 2016-01-02
2  3 2016-01-03
3  4 2016-01-04

旧的行为:

In [3]: df.prod()
Out[3]:
Out[3]:
A    24
dtype: int64

未来的行为:

In [4]: df.prod()
...
TypeError: 'DatetimeArray' does not implement reduction 'prod'

In [5]: df[["A"]].prod()
Out[5]:
A    24
dtype: int64

类似地,将函数应用于 DataFrameGroupBy 时,函数会引发 TypeError 的列目前会被静默忽略并从结果中丢弃。

此行为已废弃。在未来的版本中,将引发 TypeError,用户需要在调用函数之前仅选择有效的列。

例如

In [55]: df = pd.DataFrame({"A": [1, 2, 3, 4], "B": pd.date_range("2016-01-01", periods=4)})

In [56]: gb = df.groupby([1, 1, 2, 2])

旧的行为:

In [4]: gb.prod(numeric_only=False)
Out[4]:
A
1   2
2  12

未来的行为:

In [5]: gb.prod(numeric_only=False)
...
TypeError: datetime64 type does not support prod operations

In [6]: gb[["A"]].prod(numeric_only=False)
Out[6]:
    A
1   2
2  12

其他废弃#

性能提升#

错误修复#

Categorical#

  • CategoricalIndex 中的 Bug,当传递标量数据时错误地未能引发 TypeError (GH 38614)

  • CategoricalIndex.reindex 中的 Bug,当传递的 Index 不是分类类型但其值都是分类标签时失败 (GH 28690)

  • date 对象的 object-dtype 数组构造 Categorical 时,使用 astype 进行往返转换不正确的 Bug (GH 38552)

  • ndarrayCategoricalDtype 构造 DataFrame 时出现的 Bug (GH 38857)

  • DataFrame 的 object-dtype 列中设置分类值时出现的 Bug (GH 39136)

  • DataFrame.reindex() 中的一个错误,当新索引包含重复项而旧索引是 CategoricalIndex 时,会引发 IndexError (GH 38906)

  • Categorical.fillna() 中的一个错误,当使用非类别的元组进行填充时,带有元组类别的类别会引发 NotImplementedError 而不是 ValueError (GH 41914)

日期时间类#

时间差#

  • np.timedelta64 对象构造 Timedelta 时的一个错误,其中非纳秒单位超出了 timedelta64[ns] 的范围 (GH 38965)

  • 构造 TimedeltaIndex 时的一个错误,错误地接受 np.datetime64("NaT") 对象 (GH 39462)

  • 从仅包含符号而无数字的输入字符串构造 Timedelta 时未能引发错误的一个错误 (GH 39710)

  • TimedeltaIndexto_timedelta() 中的一个错误,当传递非纳秒 timedelta64 数组时未能引发错误,该数组在转换为 timedelta64[ns] 时会溢出 (GH 40008)

时区#

  • 代表 UTC 的不同 tzinfo 对象未被视为等价的一个错误 (GH 39216)

  • dateutil.tz.gettz("UTC") 未被识别为与其他表示 UTC 的 tzinfo 等价的一个错误 (GH 39276)

数值#

转换#

  • Series.to_dict() 中的一个错误,当 orient='records' 时现在返回 Python 原生类型 (GH 25969)

  • Series.view()Index.view() 中的一个错误,在日期时间类 (datetime64[ns], datetime64[ns, tz], timedelta64, period) dtypes 之间转换时 (GH 39788)

  • 从空的 np.recarray 创建 DataFrame 时未能保留原始 dtypes 的一个错误 (GH 40121)

  • DataFramefrozenset 构造时未能引发 TypeError 的一个错误 (GH 40163)

  • Index 构造中的一个错误,当数据无法转换为传递的 dtype 时,静默忽略该 dtype (GH 21311)

  • StringArray.astype() 中的一个错误,回退到 NumPy 并在转换为 dtype='categorical' 时引发错误 (GH 40450)

  • factorize() 中的一个错误,当给定一个数值型 NumPy dtype 低于 int64、uint64 和 float64 的数组时,唯一值未保留其原始 dtype (GH 41132)

  • DataFrame 构造中的一个错误,当字典包含具有 ExtensionDtype 的类数组且 copy=True 时未能创建副本 (GH 38939)

  • qcut() 中的一个错误,接受 Float64DType 作为输入时引发错误 (GH 40730)

  • DataFrameSeries 构造中的一个错误,当使用 datetime64[ns] 数据和 dtype=object 时,结果是 datetime 对象而不是 Timestamp 对象 (GH 41599)

  • DataFrameSeries 构造中的一个错误,当使用 timedelta64[ns] 数据和 dtype=object 时,结果是 np.timedelta64 对象而不是 Timedelta 对象 (GH 41599)

  • 从包含 PeriodInterval 对象的二维 object-dtype np.ndarray 构造 DataFrame 时未能分别转换为 PeriodDtypeIntervalDtype 的一个错误 (GH 41812)

  • 从列表和 PandasDtype 构造 Series 时的一个错误 (GH 39357)

  • 从超出 int64 dtype 范围的 range 对象创建 Series 时的一个错误 (GH 30173)

  • 从具有全元组键且需要重新索引的 Indexdict 创建 Series 时的一个错误 (GH 41707)

  • infer_dtype() 中的一个错误,未识别带有 Period dtype 的 Series、Index 或数组 (GH 23553)

  • infer_dtype() 中的一个错误,对一般的 ExtensionArray 对象引发错误。现在将返回 "unknown-array" 而不是引发错误 (GH 37367)

  • DataFrame.convert_dtypes() 中的一个错误,在空 DataFrame 上调用时错误地引发 ValueError (GH 40393)

字符串#

区间#

  • IntervalIndex.intersection()IntervalIndex.symmetric_difference() 方法中,与 CategoricalIndex 操作时总是返回 object-dtype 的错误 (GH 38653, GH 38741)

  • IntervalIndex.intersection() 方法中,当至少一个 Index 对象包含在另一对象中也存在的重复项时,返回重复项的错误 (GH 38743)

  • IntervalIndex.union(), IntervalIndex.intersection(), IntervalIndex.difference()IntervalIndex.symmetric_difference() 现在转换为适当的 dtype,而不是在与另一个不兼容 dtype 的 IntervalIndex 操作时引发 TypeError (GH 39267)

  • PeriodIndex.union(), PeriodIndex.intersection(), PeriodIndex.symmetric_difference(), PeriodIndex.difference() 现在转换为 object dtype,而不是在与另一个不兼容 dtype 的 PeriodIndex 操作时引发 IncompatibleFrequency (GH 39306)

  • IntervalIndex.is_monotonic(), IntervalIndex.get_loc(), IntervalIndex.get_indexer_for(), 和 IntervalIndex.__contains__() 方法中,当存在 NA 值时出现的错误 (GH 41831)

索引#

  • Index.union()MultiIndex.union() 方法中,当 Index 不是单调的或 sort 设置为 False 时,删除重复 Index 值的错误 (GH 36289, GH 31326, GH 40862)

  • CategoricalIndex.get_indexer() 方法中,当非唯一时未能引发 InvalidIndexError 的错误 (GH 38372)

  • IntervalIndex.get_indexer() 方法中,当 target 具有 CategoricalDtype 且索引和目标都包含 NA 值时出现的错误 (GH 41934)

  • Series.loc() 中,当输入使用布尔列表过滤且要设置的值是维度较低的列表时引发 ValueError 的错误 (GH 20438)

  • DataFrame 插入许多新列时导致后续索引行为不正确的错误 (GH 38380)

  • DataFrame.__setitem__() 方法中,当向重复列设置多个值时引发 ValueError 的错误 (GH 15695)

  • DataFrame.loc(), Series.loc(), DataFrame.__getitem__()Series.__getitem__() 方法中,对于非单调的 DatetimeIndex,使用字符串切片时返回错误元素的错误 (GH 33146)

  • DataFrame.reindex()Series.reindex() 方法中,对于时区感知的索引,在使用 method="ffill"method="bfill" 并指定 tolerance 时引发 TypeError 的错误 (GH 38566)

  • DataFrame.reindex() 方法中,当 datetime64[ns]timedelta64[ns]fill_value 需要转换为 object dtype 时,错误地将其转换为整数的错误 (GH 39755)

  • DataFrame.__setitem__() 方法中,当使用指定列和一个非空 DataFrame 值设置到空的 DataFrame 时引发 ValueError 的错误 (GH 38831)

  • DataFrame.loc.__setitem__() 方法中,当 DataFrame 包含重复列时,对唯一列进行操作时引发 ValueError 的错误 (GH 38521)

  • DataFrame.iloc.__setitem__()DataFrame.loc.__setitem__() 方法中,当使用字典值进行设置时,存在混合 dtypes 的错误 (GH 38335)

  • Series.loc.__setitem__()DataFrame.loc.__setitem__() 方法中,当提供布尔生成器时引发 KeyError 的错误 (GH 39614)

  • Series.iloc()DataFrame.iloc() 方法中,当提供生成器时引发 KeyError 的错误 (GH 39614)

  • DataFrame.__setitem__() 方法中,当右侧是一个列数错误的 DataFrame 时,没有引发 ValueError 的错误 (GH 38604)

  • Series.__setitem__() 方法中,当使用标量索引器设置 Series 时引发 ValueError 的错误 (GH 38303)

  • DataFrame.loc() 方法中,当作为输入的 DataFrame 只有一行时,丢弃 MultiIndex 级别的错误 (GH 10521)

  • DataFrame.__getitem__()Series.__getitem__() 方法中,当使用现有字符串进行切片且 Index 具有毫秒时总是引发 KeyError 的错误 (GH 33589)

  • 在将 timedelta64datetime64 值设置到数值型 Series 中时,未能转换为 object dtype 的错误 (GH 39086, GH 39619)

  • 在将 Interval 值设置到具有不匹配 IntervalDtypeSeriesDataFrame 中时,错误地将新值转换为现有 dtype 的错误 (GH 39120)

  • 在将 datetime64 值设置到 integer-dtype 的 Series 中时,错误地将 datetime64 值转换为整数的错误 (GH 39266)

  • 在将 np.datetime64("NaT") 设置到具有 Datetime64TZDtypeSeries 中时,错误地将时区天真值视为时区感知值的错误 (GH 39769)

  • Index.get_loc() 方法中,当 key=NaN 且指定了 methodNaN 不在 Index 中时,没有引发 KeyError 的错误 (GH 39382)

  • DatetimeIndex.insert() 方法中,当将 np.datetime64("NaT") 插入到时区感知索引中时,错误地将时区天真值视为时区感知值的错误 (GH 39769)

  • Index.insert() 中,设置无法在现有 frame.columns 中容纳的新列时,或在 Series.reset_index()DataFrame.reset_index() 中,错误地引发异常而不是转换为兼容 dtype 的错误 (GH 39068)

  • RangeIndex.append() 方法中,长度为 1 的单个对象被错误拼接的错误 (GH 39401)

  • RangeIndex.astype() 方法中,当转换为 CategoricalIndex 时,categories 变成了 Int64Index 而不是 RangeIndex 的错误 (GH 41263)

  • 在使用布尔索引器将 numpy.timedelta64 值设置到 object-dtype 的 Series 中时出现的错误 (GH 39488)

  • 在使用 atiat 将数值设置到 boolean-dtypes Series 中时,未能转换为 object-dtype 的错误 (GH 39582)

  • DataFrame.__setitem__()DataFrame.iloc.__setitem__() 方法中,当尝试使用行切片进行索引并设置列表作为值时引发 ValueError 的错误 (GH 40440)

  • DataFrame.loc() 方法中,当在 MultiIndex 中找不到键且未完全指定级别时,没有引发 KeyError 的错误 (GH 41170)

  • DataFrame.loc.__setitem__() 方法中,当使用扩展进行设置时,在扩展轴中的索引包含重复项时错误地引发异常的错误 (GH 40096)

  • 在具有 MultiIndexDataFrame.loc.__getitem__() 方法中,当至少一个索引列具有 float dtype 且我们检索标量时转换为 float 的错误 (GH 41369)

  • DataFrame.loc() 方法中,错误地匹配非布尔索引元素的错误 (GH 20432)

  • 在使用 np.nan 对具有 CategoricalIndexSeriesDataFrame 进行索引时,当存在 np.nan 键时错误地引发 KeyError 的错误 (GH 41933)

  • 在具有 ExtensionDtypeSeries.__delitem__() 方法中,错误地转换为 ndarray 的错误 (GH 40386)

  • 在具有 CategoricalIndexDataFrame.at() 方法中,当传递整数键时返回错误结果的错误 (GH 41846)

  • DataFrame.loc() 方法中,如果索引器包含重复项,返回顺序错误的 MultiIndex 的错误 (GH 40978)

  • DataFrame.__setitem__() 方法中,当使用 str 的子类作为列名并配合 DatetimeIndex 时引发 TypeError 的错误 (GH 37366)

  • PeriodIndex.get_loc() 方法中,当给定具有不匹配 freqPeriod 时未能引发 KeyError 的错误 (GH 41670)

  • 使用 .loc.__getitem__ 配合 UInt64Index 和负整数键时,在某些情况下引发 OverflowError 而不是 KeyError,在其他情况下则绕回到正整数的错误 (GH 41777)

  • Index.get_indexer() 方法中,在某些情况下,当提供无效的 method, limittolerance 参数时未能引发 ValueError 的错误 (GH 41918)

  • 当使用无效字符串对具有 TimedeltaIndexSeriesDataFrame 进行切片时,引发 ValueError 而不是 TypeError 的错误 (GH 41821)

  • Index 构造函数中,有时会静默忽略指定的 dtype 的错误 (GH 38879)

  • Index.where() 行为现在与 Index.putmask() 行为一致,即 index.where(mask, other) 匹配 index.putmask(~mask, other) (GH 39412)

缺失值#

多级索引#

  • DataFrame.drop() 中存在的 bug,当 MultiIndex 非唯一且未提供 level 时引发 TypeError (GH 36293)

  • MultiIndex.intersection() 中存在的 bug,结果中重复出现 NaN (GH 38623)

  • MultiIndex.equals() 中存在的 bug,当 MultiIndex 包含 NaN 且顺序不同时错误地返回 True (GH 38439)

  • MultiIndex.intersection() 中存在的 bug,与 CategoricalIndex 求交集时始终返回空结果 (GH 38653)

  • MultiIndex.difference() 中存在的 bug,当索引包含不可排序条目时错误地引发 TypeError (GH 41915)

  • MultiIndex.reindex() 中存在的 bug,当用于空的 MultiIndex 且仅索引特定 level 时引发 ValueError (GH 41170)

  • MultiIndex.reindex() 中存在的 bug,根据扁平 Index 进行 reindexing 时引发 TypeError (GH 41707)

I/O#

  • Index.__repr__() 中存在的 bug,当 display.max_seq_items=1 时 (GH 38415)

  • read_csv() 中存在的 bug,如果设置了参数 decimalengine="python" 时无法识别科学计数法 (GH 31920)

  • read_csv() 中存在的 bug,将 NA 值错误地解释为注释,当 NA 确实包含注释字符串时(已修复 engine="python" 的此问题)(GH 34002)

  • read_csv() 中存在的 bug,当文件没有数据行时,如果存在多个 header 列且指定了 index_col 则引发 IndexError (GH 38292)

  • read_csv() 中存在的 bug,当 engine="python" 时,不接受 usecols 的长度与 names 不同 (GH 16469)

  • read_csv() 中存在的 bug,当 engine="python" 时,如果指定了 delimiter=","usecolsparse_dates,返回 object dtype (GH 35873)

  • read_csv() 中存在的 bug,当 engine="c" 时,如果指定了 namesparse_dates 则引发 TypeError (GH 33699)

  • read_clipboard()DataFrame.to_clipboard() 中存在的 bug,在 WSL 中不起作用 (GH 38527)

  • 允许为 read_sql()read_sql_query()read_sql_table()parse_dates 参数指定自定义错误值 (GH 35185)

  • DataFrame.to_hdf()Series.to_hdf() 中存在的 bug,当尝试应用于 DataFrameSeries 的子类时引发 KeyError (GH 33748)

  • HDFStore.put() 中存在的 bug,当保存非字符串 dtype 的 DataFrame 时引发错误的 TypeError (GH 34274)

  • json_normalize() 中存在的 bug,导致生成器对象的第一个元素未包含在返回的 DataFrame 中 (GH 35923)

  • read_csv() 中存在的 bug,当列应被解析为日期且 engine="python" 指定了 usecols 时,将千位分隔符应用于日期列 (GH 39365)

  • read_excel() 中存在的 bug,当指定多个 header 和 index 列时,向前填充 MultiIndex 名称 (GH 34673)

  • read_excel() 中存在的 bug,不遵守 set_option() (GH 34252)

  • read_csv() 中存在的 bug,未为可为空的 Boolean dtype 切换 true_valuesfalse_values (GH 34655)

  • read_json() 中存在的 bug,当 orient="split" 时未保留数字字符串索引 (GH 28556)

  • read_sql()chunksize 非零且查询没有返回结果时,返回一个空的生成器。现在返回一个包含一个空 DataFrame 的生成器 (GH 34411)

  • read_hdf() 中存在的 bug,使用 where 参数过滤分类字符串列时返回意外的记录 (GH 39189)

  • read_sas() 中存在的 bug,当 datetimes 为 null 时引发 ValueError (GH 39725)

  • read_excel() 中存在的 bug,丢弃单列电子表格中的空值 (GH 39808)

  • read_excel() 中存在的 bug,对于某些文件类型加载末尾的空行/列 (GH 41167)

  • read_excel() 中存在的 bug,当 excel 文件具有 MultiIndex header 后跟两个空行且没有 index 时引发 AttributeError (GH 40442)

  • read_excel()read_csv()read_table()read_fwf()read_clipboard() 中存在的 bug,当 MultiIndex header 后跟一个空行且没有 index 时,该空行会被丢弃 (GH 40442)

  • DataFrame.to_string() 中存在的 bug,当 index=False 时截断列位置错误 (GH 40904)

  • DataFrame.to_string() 中存在的 bug,当 index=False 时添加一个额外的点并使截断行不对齐 (GH 40904)

  • read_orc() 中存在的 bug,始终引发 AttributeError (GH 40918)

  • read_csv()read_table() 中存在的 bug,如果定义了 namesprefix 则静默忽略 prefix,现在引发 ValueError (GH 39123)

  • read_csv()read_excel() 中存在的 bug,当 mangle_dupe_cols 设置为 True 时,不遵守重复列名的 dtype (GH 35211)

  • read_csv() 中存在的 bug,如果定义了 delimitersep 则静默忽略 sep,现在引发 ValueError (GH 39823)

  • read_csv()read_table() 中存在的 bug,当之前调用过 sys.setprofile 时错误地解释参数 (GH 41069)

  • 将 PyArrow 转换为 pandas(例如用于读取 Parquet)时存在的 bug,涉及可为空的 dtypes 以及数据缓冲区大小不是 dtype 大小倍数的 PyArrow 数组 (GH 40896)

  • read_excel() 中存在的 bug,即使用户指定了 engine 参数,当 pandas 无法确定文件类型时也会引发错误 (GH 41225)

  • read_clipboard() 中存在的 bug,从 excel 文件复制时,如果第一列有 null 值,则值会移动到错误的列 (GH 41108)

  • DataFrame.to_hdf()Series.to_hdf() 中存在的 bug,当尝试将字符串列附加到不兼容的列时引发 TypeError (GH 41897)

周期#

  • Period 对象或 IndexSeriesDataFrame 与不匹配的 PeriodDtype 进行比较时,现在行为与其他不匹配类型比较类似,对于 equals 返回 False,对于 not-equal 返回 True,对于 inequality checks 引发 TypeError (GH 39274)

绘图#

  • plotting.scatter_matrix() 中存在的 bug,当传递 2d ax 参数时引发错误 (GH 16253)

  • 阻止在 Matplotlib 的 constrained_layout 启用时产生警告 (GH 25261)

  • DataFrame.plot() 中存在的 bug,如果函数被重复调用且某些调用使用了 yerr 而其他调用没有,则图例中显示错误的颜色 (GH 39522)

  • DataFrame.plot() 中存在的 bug,如果函数被重复调用且某些调用使用了 secondary_y 而其他调用使用了 legend=False,则图例中显示错误的颜色 (GH 40044)

  • DataFrame.plot.box() 中存在的 bug,当选择了 dark_background 主题时,绘图的 caps 或 min/max 标记不可见 (GH 40769)

分组/重采样/滑动窗口#

重塑#

稀疏#

  • DataFrame.sparse.to_coo() 中的错误,当列是数字 Index 但不包含 0 时,引发了 KeyError (GH 18414)

  • SparseArray.astype() 中的错误,当使用 copy=False 从整数数据类型转换为浮点数据类型时,产生不正确的结果 (GH 34456)

  • SparseArray.max()SparseArray.min() 中的错误,总是返回空结果 (GH 40921)

扩展数组#

Styler#

  • Styler 中的一个错误,其中方法的 subset 参数对某些有效的 MultiIndex 切片会引发错误 (GH 33562)

  • Styler 渲染的 HTML 输出经过细微改动以支持 w3 良好代码标准 (GH 39626)

  • Styler 中的一个错误,其中渲染的 HTML 缺少某些头部单元格的列类标识符 (GH 39716)

  • Styler.background_gradient() 中的一个错误,其中未正确确定文本颜色 (GH 39888)

  • Styler.set_table_styles() 中的一个错误,其中 table_styles 参数的 CSS 选择器中的多个元素未正确添加 (GH 34061)

  • Styler 中的一个错误,其中从 Jupyter 复制时会丢失左上角的单元格并使头部错位 (GH 12147)

  • Styler.where 中的一个错误,其中 kwargs 未传递给适用的可调用对象 (GH 40845)

  • Styler 中的一个错误,导致 CSS 在多次渲染时重复 (GH 39395, GH 40334)

其他#

贡献者#

共有 251 人为本次发布贡献了补丁。名字旁边带有“+”的人是首次贡献补丁。

  • Abhishek R +

  • Ada Draginda

  • Adam J. Stewart

  • Adam Turner +

  • Aidan Feldman +

  • Ajitesh Singh +

  • Akshat Jain +

  • Albert Villanova del Moral

  • Alexandre Prince-Levasseur +

  • Andrew Hawyrluk +

  • Andrew Wieteska

  • AnglinaBhambra +

  • Ankush Dua +

  • Anna Daglis

  • Ashlan Parker +

  • Ashwani +

  • Avinash Pancham

  • Ayushman Kumar +

  • BeanNan

  • Benoît Vinot

  • Bharat Raghunathan

  • Bijay Regmi +

  • Bobin Mathew +

  • Bogdan Pilyavets +

  • Brian Hulette +

  • Brian Sun +

  • Brock +

  • Bryan Cutler

  • Caleb +

  • Calvin Ho +

  • Chathura Widanage +

  • Chinmay Rane +

  • Chris Lynch

  • Chris Withers

  • Christos Petropoulos

  • Corentin Girard +

  • DaPy15 +

  • Damodara Puddu +

  • Daniel Hrisca

  • Daniel Saxton

  • DanielFEvans

  • Dare Adewumi +

  • Dave Willmer

  • David Schlachter +

  • David-dmh +

  • Deepang Raval +

  • Doris Lee +

  • Dr. Jan-Philip Gehrcke +

  • DriesS +

  • Dylan Percy

  • Erfan Nariman

  • Eric Leung

  • EricLeer +

  • Eve

  • Fangchen Li

  • Felix Divo

  • Florian Jetter

  • Fred Reiss

  • GFJ138 +

  • Gaurav Sheni +

  • Geoffrey B. Eisenbarth +

  • Gesa Stupperich +

  • Griffin Ansel +

  • Gustavo C. Maciel +

  • Heidi +

  • Henry +

  • Hung-Yi Wu +

  • Ian Ozsvald +

  • Irv Lustig

  • Isaac Chung +

  • Isaac Virshup

  • JHM Darbyshire (MBP) +

  • JHM Darbyshire (iMac) +

  • Jack Liu +

  • James Lamb +

  • Jeet Parekh

  • Jeff Reback

  • Jiezheng2018 +

  • Jody Klymak

  • Johan Kåhrström +

  • John McGuigan

  • Joris Van den Bossche

  • Jose

  • JoseNavy

  • Josh Dimarsky

  • Josh Friedlander

  • Joshua Klein +

  • Julia Signell

  • Julian Schnitzler +

  • Kaiqi Dong

  • Kasim Panjri +

  • Katie Smith +

  • Kelly +

  • Kenil +

  • Keppler, Kyle +

  • Kevin Sheppard

  • Khor Chean Wei +

  • Kiley Hewitt +

  • Larry Wong +

  • Lightyears +

  • Lucas Holtz +

  • Lucas Rodés-Guirao

  • Lucky Sivagurunathan +

  • Luis Pinto

  • Maciej Kos +

  • Marc Garcia

  • Marco Edward Gorelli +

  • Marco Gorelli

  • MarcoGorelli +

  • Mark Graham

  • Martin Dengler +

  • Martin Grigorov +

  • Marty Rudolf +

  • Matt Roeschke

  • Matthew Roeschke

  • Matthew Zeitlin

  • Max Bolingbroke

  • Maxim Ivanov

  • Maxim Kupfer +

  • Mayur +

  • MeeseeksMachine

  • Micael Jarniac

  • Michael Hsieh +

  • Michel de Ruiter +

  • Mike Roberts +

  • Miroslav Šedivý

  • Mohammad Jafar Mashhadi

  • Morisa Manzella +

  • Mortada Mehyar

  • Muktan +

  • Naveen Agrawal +

  • Noah

  • Nofar Mishraki +

  • Oleh Kozynets

  • Olga Matoula +

  • Oli +

  • Omar Afifi

  • Omer Ozarslan +

  • Owen Lamont +

  • Ozan Öğreden +

  • Pandas Development Team

  • Paolo Lammens

  • Parfait Gasana +

  • Patrick Hoefler

  • Paul McCarthy +

  • Paulo S. Costa +

  • Pav A

  • Peter

  • Pradyumna Rahul +

  • Punitvara +

  • QP Hou +

  • Rahul Chauhan

  • Rahul Sathanapalli

  • Richard Shadrach

  • Robert Bradshaw

  • Robin to Roxel

  • Rohit Gupta

  • Sam Purkis +

  • Samuel GIFFARD +

  • Sean M. Law +

  • Shahar Naveh +

  • ShaharNaveh +

  • Shiv Gupta +

  • Shrey Dixit +

  • Shudong Yang +

  • Simon Boehm +

  • Simon Hawkins

  • Sioned Baker +

  • Stefan Mejlgaard +

  • Steven Pitman +

  • Steven Schaerer +

  • Stéphane Guillou +

  • TLouf +

  • Tegar D Pratama +

  • Terji Petersen

  • Theodoros Nikolaou +

  • Thomas Dickson

  • Thomas Li

  • Thomas Smith

  • Thomas Yu +

  • ThomasBlauthQC +

  • Tim Hoffmann

  • Tom Augspurger

  • Torsten Wörtwein

  • Tyler Reddy

  • UrielMaD

  • Uwe L. Korn

  • Venaturum +

  • VirosaLi

  • Vladimir Podolskiy

  • Vyom Pathak +

  • WANG Aiyong

  • Waltteri Koskinen +

  • Wenjun Si +

  • William Ayd

  • Yeshwanth N +

  • Yuanhao Geng

  • Zito Relova +

  • aflah02 +

  • arredond +

  • attack68

  • cdknox +

  • chinggg +

  • fathomer +

  • ftrihardjo +

  • github-actions[bot] +

  • gunjan-solanki +

  • guru kiran

  • hasan-yaman

  • i-aki-y +

  • jbrockmendel

  • jmholzer +

  • jordi-crespo +

  • jotasi +

  • jreback

  • juliansmidek +

  • kylekeppler

  • lrepiton +

  • lucasrodes

  • maroth96 +

  • mikeronayne +

  • mlondschien

  • moink +

  • morrme

  • mschmookler +

  • mzeitlin11

  • na2 +

  • nofarmishraki +

  • partev

  • patrick

  • ptype

  • realead

  • rhshadrach

  • rlukevie +

  • rosagold +

  • saucoide +

  • sdementen +

  • shawnbrown

  • sstiijn +

  • stphnlyd +

  • sukriti1 +

  • taytzehao

  • theOehrly +

  • theodorju +

  • thordisstella +

  • tonyyyyip +

  • tsinggggg +

  • tushushu +

  • vangorade +

  • vladu +

  • wertha +