1.2.1中的新特性(2021年1月20日)#

这些是Pandas1.2.1中的变化。看见 发行说明 获取完整的更改日志,包括其他版本的Pandas。

固定回归#

  • Fixed regression in to_csv() that created corrupted zip files when there were more rows than chunksize (GH38714)

  • 修复了中的回归问题 to_csv() 打开 codecs.StreamReaderWriter 在二进制模式下而不是在文本模式下 (GH39247 )

  • 修复了中的回归问题 read_csv() 和其他读取功能是编码错误策略 (errors )没有默认设置为 "replace" 未指定编码时 (GH38989 )

  • 修复了中的回归问题 read_excel() 使用非原始字节文件句柄 (GH38788 )

  • 修复了中的回归问题 DataFrame.to_stata() 发生错误时未删除创建的文件 (GH39202 )

  • Fixed regression in DataFrame.__setitem__ raising ValueError when expanding DataFrame and new column is from type "0 - name" (GH39010)

  • 修复了设置中的回归问题 DataFrame.loc() 加薪 ValueError 什么时候 DataFrame 已未排序 MultiIndex 列和索引器是标量 (GH38601 )

  • Fixed regression in setting with DataFrame.loc() raising KeyError with MultiIndex and list-like columns indexer enlarging DataFrame (GH39147)

  • Fixed regression in groupby() with Categorical grouping column not showing unused categories for grouped.indices (GH38642)

  • 修复了中的回归问题 GroupBy.sem() 如果存在非数字列,则会导致错误而不是被删除 (GH38774 )

  • 修复了中的回归问题 DataFrameGroupBy.diff() 为以下项目筹集资金 int8int16 列 (GH39050 )

  • 修复了中的回归问题 DataFrame.groupby() 在聚合 ExtensionDType 对于非数值,这可能会失败 (GH38980 )

  • 修复了中的回归问题 Rolling.skew()Rolling.kurt() 在位修改对象 (GH38908 )

  • 修复了中的回归问题 DataFrame.any()DataFrame.all() 不返回TZ感知的结果 datetime64 列 (GH38723 )

  • 修复了中的回归问题 DataFrame.apply() 使用 axis=1 在Apply函数中使用字符串访问器 (GH38979 )

  • Fixed regression in DataFrame.replace() raising ValueError when DataFrame has dtype bytes (GH38900)

  • 修复了中的回归问题 Series.fillna() 这引发了 RecursionError 使用 datetime64[ns, UTC] 数据类型 (GH38851 )

  • Fixed regression in comparisons between NaT and datetime.date objects incorrectly returning True (GH39151)

  • Fixed regression in calling NumPy accumulate() ufuncs on DataFrames, e.g. np.maximum.accumulate(df) (GH39259)

  • 修复了类浮点型字符串的REPR中的回归问题 object 尾随0在小数点后截断的数据类型 (GH38708 )

  • 修复了引发的回归 AttributeError 使用PyArrow版本[0.16.0、1.0.0] (GH38801 )

  • 修复了中的回归问题 pandas.testing.assert_frame_equal() 加薪 TypeError 使用 check_like=True 什么时候 Index 或列具有混合数据类型 (GH39168 )

我们恢复了一个承诺,该承诺导致了Pandas 1.2.0中的几个与绘图相关的回归 (GH38969GH38736GH38865GH38947GH39126 )。因此,在Pandas 1.2.0中报告的与条形图中不一致的刻度标签相关的错误再次出现 (GH26186GH11465 )

在非对齐的DataFrames上调用NumPy uuncs#

在Pandas 1.2.0之前,对非对齐的DataFrame(或DataFrame/Series组合)调用NumPy ufunc将忽略索引,仅按形状匹配输入,并使用第一个DataFrame的索引/列作为结果:

In [1]: df1 = pd.DataFrame({"a": [1, 2], "b": [3, 4]}, index=[0, 1])
In [2]: df2 = pd.DataFrame({"a": [1, 2], "b": [3, 4]}, index=[1, 2])
In [3]: df1
Out[3]:
   a  b
0  1  3
1  2  4
In [4]: df2
Out[4]:
   a  b
1  1  3
2  2  4

In [5]: np.add(df1, df2)
Out[5]:
   a  b
0  2  6
1  4  8

这与其他大Pandas的操作方式形成了鲜明对比,后者首先对齐输入:

In [6]: df1 + df2
Out[6]:
     a    b
0  NaN  NaN
1  3.0  7.0
2  NaN  NaN

在Pandas 1.2.0中,我们重构了如何在DataFrame上调用NumPy uunction,这首先开始对齐输入 (GH39184 ),就像在其他Pandas操作中发生的那样,以及在Series对象上调用uuncs时发生的情况。

对于Pandas1.2.1,我们恢复了以前的行为,以避免破坏性的变化,但上面的例子 np.add(df1, df2) 如果输入不对齐,现在将发出警告,未来的Pandas2.0版本将首先开始对齐输入 (GH39184 )。在系列对象上调用NumPy ufunc(例如 np.add(s1, s2) )已经保持一致,并将继续这样做。

要避免该警告并保持忽略索引的当前行为,请将其中一个参数转换为NumPy数组:

In [7]: np.add(df1, np.asarray(df2))
Out[7]:
   a  b
0  2  6
1  4  8

要获取未来的行为并使警告静默,您可以在将参数传递给ufunc之前手动对齐:

In [8]: df1, df2 = df1.align(df2)
In [9]: np.add(df1, df2)
Out[9]:
     a    b
0  NaN  NaN
1  3.0  7.0
2  NaN  NaN

错误修复#

  • 窃听 read_csv() 使用 float_precision="high" 导致对长指数字符串的分段错误或错误解析。在某些情况下,这会导致回归成为 float_precision 在Pandas1.2.0中进行了更改 (GH38753 )

  • 窃听 read_csv() 时,不关闭打开的文件句柄 csv.ErrorUnicodeDecodeError 在初始化时发生 (GH39024 )

  • 窃听 pandas.testing.assert_index_equal() 加薪 TypeError 使用 check_order=False 什么时候 Index 具有混合数据类型 (GH39168 )

其他#

贡献者#

共有20人为此次发布贡献了补丁。名字中带有“+”的人第一次贡献了一个补丁。

  • Ada Draginda +

  • Andrew Wieteska

  • Bryan Cutler

  • Fangchen Li

  • Joris Van den Bossche

  • Matthew Roeschke

  • Matthew Zeitlin +

  • MeeseeksMachine

  • Micael Jarniac

  • Omar Afifi +

  • Pandas Development Team

  • Richard Shadrach

  • Simon Hawkins

  • Terji Petersen

  • Torsten Wörtwein

  • WANG Aiyong

  • jbrockmendel

  • kylekeppler

  • mzeitlin11

  • patrick