Pandas-2-2-中文文档-四十六-

Pandas 2.2 中文文档(四十六)

原文:pandas.pydata.org/docs/

1.2.5 版本的新功能(2021 年 6 月 22 日)

原文:pandas.pydata.org/docs/whatsnew/v1.2.5.html

这些是 pandas 1.2.5 版本的更改。查看发行说明了解包括其他 pandas 版本在内的完整更改日志。

修复的回归问题

  • 修复了concat()在一个具有全空的Index和另一个是DatetimeIndex之间的回归问题,错误地引发了异常 (GH 40841)

  • 修复了当 min_countnumeric_only 都给定时DataFrame.sum()DataFrame.prod()的回归问题 (GH 41074)

  • 修复了在使用非 UTF8 编码时使用 memory_map=True 时的read_csv()的回归问题 (GH 40986)

  • 修复了当要替换的值是 NumPy 浮点数组时DataFrame.replace()Series.replace()的回归问题 (GH 40371)

  • 修复了当打开但未关闭损坏文件时ExcelFile()的回归问题 (GH 41778)

  • 修复了DataFrame.astype()中使用 dtype=str 时在分类列中无法转换 NaN 的回归问题 (GH 41797) ## 贡献者

共有 12 人为此版本提交了补丁。带有“+”标记的人员首次为此版本提交了补丁。

  • Joris Van den Bossche

  • Marc Garcia

  • Matthew Zeitlin

  • MeeseeksMachine

  • Pandas 开发团队

  • Patrick Hoefler +

  • Simon Hawkins

  • Thomas Li

  • Torsten Wörtwein

  • hasan-yaman +

  • jbrockmendel

  • phofl + ## 修复的回归问题

  • 修复了两个 DataFrame 之间的 concat() 中的回归问题,其中一个具有全部为 None 的 Index,另一个是 DatetimeIndex 错误地引发异常 (GH 40841)

  • 在给定 min_countnumeric_only 时修复了 DataFrame.sum()DataFrame.prod() 中的回归问题 (GH 41074)

  • 在使用非 UTF8 编码时使用 memory_map=True 修复了 read_csv() 中的回归问题 (GH 40986)

  • 修复了当要替换的值是 NumPy 浮点数组时,在 DataFrame.replace()Series.replace() 中的回归问题 (GH 40371)

  • 在打开但未关闭损坏文件时修复了 ExcelFile() 中的回归问题 (GH 41778)

  • 修复了在将 dtype=str 用于分类列时失败于转换 NaNDataFrame.astype() 中的回归问题 (GH 41797)

贡献者

本次发布共有 12 人贡献了补丁。带有“+”标记的人员首次贡献了补丁。

  • Joris Van den Bossche

  • Marc Garcia

  • Matthew Zeitlin

  • MeeseeksMachine

  • Pandas 开发团队

  • Patrick Hoefler +

  • Simon Hawkins

  • Thomas Li

  • Torsten Wörtwein

  • hasan-yaman +

  • jbrockmendel

  • phofl +

1.2.4 版本的新功能(2021 年 4 月 12 日)

原文:pandas.pydata.org/docs/whatsnew/v1.2.4.html

这些是 pandas 1.2.4 版本中的更改。查看发布说明获取包括其他版本的完整更改日志。

修复的回归问题

  • 修复了DataFrame.sum()中的回归问题,当min_count大于DataFrame形状时传递导致ValueErrorGH 39738)

  • 修复了DataFrame.to_json()在 PyPy 上运行时引发AttributeError的回归问题(GH 39837)

  • 修复了pd.NaT与非日期时间 numpy 数组的(不)相等比较返回标量而不是数组的回归问题(GH 40722)

  • 修复了DataFrame.where()中的回归问题,在所有条件都为 True 的情况下未返回副本(GH 39595)

  • 修复了DataFrame.replace()中的回归问题,当regex是多键字典时引发IndexErrorGH 39338)

  • 修复了object列中浮点数的 repr 在控制台打印或通过DataFrame.to_string()DataFrame.to_html()DataFrame.to_latex()输出时不遵守float_format的回归问题(GH 40024)

  • 修复了 NumPy ufuncs 中的回归问题,例如np.add未传递所有参数给DataFrameGH 40662) ## 贡献者

总共有 9 人为此版本贡献了补丁。名字后面带有“+”的人是第一次为此版本贡献补丁。

  • Fangchen Li

  • Joris Van den Bossche

  • Matthew Zeitlin

  • MeeseeksMachine

  • Pandas 开发团队

  • Simon Hawkins

  • jbrockmendel

  • mzeitlin11

  • patrick ## 修复的回归问题

  • 修复了当min_count大于DataFrame形状时,DataFrame.sum()传递的值引发ValueError的回归问题 (GH 39738)

  • 修复了在 PyPy 上运行时DataFrame.to_json()抛出AttributeError的回归问题 (GH 39837)

  • 修复了使用非日期时间类型的 numpy 数组与pd.NaT进行(不)相等比较时返回标量而不是数组的回归问题 (GH 40722)

  • 修复了DataFrame.where()在所有条件都为 True 的情况下未返回副本的回归问题 (GH 39595)

  • 修复了当regex是多键字典时,DataFrame.replace()抛出IndexError的回归问题 (GH 39338)

  • 修复了在object列中浮点数的 repr 在控制台打印或通过DataFrame.to_string()DataFrame.to_html()DataFrame.to_latex()输出时不遵守float_format的回归问题 (GH 40024)

  • 修复了 NumPy ufuncs 中的回归,例如np.add未将所有参数传递给DataFrame (GH 40662)

贡献者

总共有 9 人为此版本贡献了补丁。带有“+”标记的人是首次为此贡献了补丁。

  • Fangchen Li

  • Joris Van den Bossche

  • Matthew Zeitlin

  • MeeseeksMachine

  • Pandas 开发团队

  • Simon Hawkins

  • jbrockmendel

  • mzeitlin11

  • patrick

1.2.3 新特性(2021 年 3 月 2 日)

原文:pandas.pydata.org/docs/whatsnew/v1.2.3.html

这些是 pandas 1.2.3 的变化。 有关包括其他 pandas 版本的完整更改日志,请参阅发布说明。

修复的回归问题

  • 修复了 to_excel() 在使用 columns 属性给出重复列时引发 KeyError 的回归问题(GH 39695

  • 修复了可空整数一元操作在赋值时传播掩码的回归问题(GH 39943

  • 修复了 DataFrame.__setitem__() 中的回归问题,未对布尔索引器的右侧的 DataFrame 进行对齐(GH 39931

  • 修复了 to_json() 在使用 URL 风格路径且内部以二进制模式打开或在用户提供的以二进制模式打开的文件对象时未使用 compression 的回归问题(GH 39985

  • 修复了 Series.sort_index()DataFrame.sort_index() 中的回归问题,当传递 kwarg ascending=None 时退出时出现不优雅的错误。 仍然视 ascending=None 为无效,并且改进的错误消息建议了正确的用法(ascending 必须是布尔值或布尔值的类似列表)(GH 39434

  • 修复了 DataFrame.transform()Series.transform() 中的回归问题,在传递包含列表和非列表值混合的字典时给出了错误的列标签(GH 40018) ## 贡献者

总共有 14 人为此版本贡献了补丁。 姓名后面带有“+”的人第一次贡献了补丁。

  • Daniel Saxton

  • Dylan Percy +

  • Jody Klymak +

  • Maxim Ivanov

  • MeeseeksMachine

  • Pandas 开发团队

  • Richard Shadrach

  • Rohit Gupta +

  • Simon Hawkins

  • Torsten Wörtwein

  • jbrockmendel

  • morrme +

  • partev

  • patrick ## 修复的回归问题

  • 修复了 to_excel() 在使用 columns 属性给出重复列时引发 KeyError 的回归问题(GH 39695

  • 修复了在可空整数一元操作中传播掩码的回归在赋值时 (GH 39943)

  • 修复了在DataFrame.__setitem__()中的回归,当布尔索引器右侧为DataFrame时未对齐 (GH 39931)

  • 修复了在 to_json() 中的回归,当使用内部以二进制模式打开的 URL 样式路径或以二进制模式打开的用户提供的文件对象时,未使用 compression 失败 (GH 39985)

  • 修复了在 Series.sort_index()DataFrame.sort_index() 中的回归,当传递 kwarg ascending=None 时,以不优雅的错误退出。仍然认为传递ascending=None是无效的,并且改进的错误消息建议正确的用法(ascending必须是布尔值或类布尔值的列表) (GH 39434)

  • 修复了在 DataFrame.transform()Series.transform() 中的回归,当传递混合了列表和非列表值的字典时,给出了错误的列标签 (GH 40018)

贡献者

总共有 14 人为此版本提交了补丁。名字后面带有“+”的人第一次为补丁做出了贡献。

  • Daniel Saxton

  • Dylan Percy +

  • Jody Klymak +

  • Maxim Ivanov

  • MeeseeksMachine

  • Pandas 开发团队

  • 理查德·沙德拉赫

  • Rohit Gupta +

  • Simon Hawkins

  • Torsten Wörtwein

  • jbrockmendel

  • morrme +

  • partev

  • patrick

1.2.2 中的新内容(2021 年 2 月 9 日)

原文:pandas.pydata.org/docs/whatsnew/v1.2.2.html

这些是 pandas 1.2.2 中的更改。请查看发布说明以获取包括其他版本的 pandas 的完整更改日志。

修复的回归

  • 修复了在检查旧版 xlrd 版本的版本时,read_excel()引发AttributeError的回归(GH 38955)

  • 当从非"datetime64[ns]"的 dtype 构建日期时间 ndarray 时,修复了在构造函数中重新排序元素的回归DataFrame(GH 39422)

  • 修复了在不将 dtype 转换为字节 dtype 时,DataFrame.astype()Series.astype()中的回归(GH 39474)

  • 修复了使用protocol=5创建 bz2/xz 压缩的 pickle 文件时to_pickle()中的回归失败(GH 39002)

  • 修复了当比较扩展 dtype 时,pandas.testing.assert_series_equal()pandas.testing.assert_frame_equal()始终引发AssertionError的回归(GH 39410)

  • 修复了在以二进制模式而不是文本模式打开codecs.StreamWriter并忽略用户提供的mode时的回归to_csv()(GH 39247)

  • 当将np.int32传递给 dtype 参数时,修复了将Categorical.astype()转换为不正确 dtype 的回归(GH 39402)

  • 修复了在追加 (mode="a") 到现有文件时创建损坏文件的to_excel()中的回归(GH 39576)

  • 修复了在空 DataFrame 或 Series 的情况下DataFrame.transform()中的回归失败(GH 39636)

  • 修复了在对所有-NaN 或数字对象 dtype 列进行聚合时,groupby()resample()中的回归问题(GH 39329)

  • 修复了Rolling.count()中的回归问题,操作后min_periods参数将被设置为0GH 39554)

  • 修复了read_excel()中的回归问题,当参数io是非路径和非缓冲区且指定了engine参数时,错误地引发异常(GH 39528) ## Bug 修复

  • 当指定的sheetname不存在时,pandas.read_excel()的错误消息现在在所有引擎上是统一的(GH 39250)

  • 修复了pandas.read_excel()中的错误,当使用引擎openpyxl并且 Excel 文件丢失或具有不正确的维度信息时,会产生不正确的结果;修复需要openpyxl >= 3.0.0,之前的版本可能仍然会失败(GH 38956GH 39001)

  • 修复了pandas.read_excel()中的错误,有时在使用引擎openpyxl时会产生带有尾随np.nan行的DataFrameGH 39181) ## 贡献者

总共有 14 人为此版本贡献了补丁。名字后面带有“+”的人第一次贡献了补丁。

  • Andrew Wieteska

  • Erfan Nariman

  • Joris Van den Bossche

  • Matthew Roeschke

  • MeeseeksMachine

  • Pandas 开发团队

  • Pav A

  • Richard Shadrach

  • Simon Hawkins

  • Thomas Li

  • Torsten Wörtwein

  • Vladimir Podolskiy +

  • jbrockmendel

  • patrick ## 修复的回归问题

  • 修复了read_excel()中的回归问题,导致在检查旧版 xlrd 版本时引发AttributeError错误(GH 38955)

  • 修复��从非"datetime64[ns]"类型的日期时间 ndarray 构造时,DataFrame构造函数重新排序元素的问题(GH 39422)

  • 修复了DataFrame.astype()Series.astype()不转换为字节数据类型的回归(GH 39474)

  • 修复了to_pickle()在使用protocol=5创建 bz2/xz 压缩的 pickle 文件时失败的回归(GH 39002)

  • 修复了pandas.testing.assert_series_equal()pandas.testing.assert_frame_equal()在比较扩展数据类型时始终引发AssertionError的回归(GH 39410)

  • 修复了to_csv()在以二进制模式而不是文本模式打开codecs.StreamWriter并忽略用户提供的mode时的回归(GH 39247)

  • 修复了当将np.int32传递给 dtype 参数时,Categorical.astype()转换为不正确的数据类型的回归(GH 39402)

  • 修复了在追加(mode="a")到现有文件时,to_excel()创建损坏文件的回归(GH 39576)

  • 修复了在空 DataFrame 或 Series 的情况下,DataFrame.transform()失败的回归(GH 39636)

  • 修复了在聚合全为 NaN 或数值对象数据类型列时,groupby()resample()引发回归的问题(GH 39329)

  • 修复了在Rolling.count()中,操作后min_periods参数会被设置为0的回归(GH 39554)

  • 修复了 read_excel() 中的回归,当参数 io 是非路径且非缓冲区时,且指定了 engine 参数时错误地引发异常(GH 39528

Bug 修复

  • 当指定的 sheetname 不存在时,pandas.read_excel() 的错误消息现在在所有引擎上都是统一的(GH 39250

  • 修复了 pandas.read_excel() 中的错误,在使用引擎 openpyxl 且 excel 文件丢失或具有不正确的维度信息时产生错误结果;修复需要 openpyxl >= 3.0.0,旧版本可能仍然失败(GH 38956GH 39001

  • 修复了 pandas.read_excel() 中的错误,有时会在使用引擎 openpyxl 时产生带有 np.nan 尾行的 DataFrameGH 39181

贡献者

总共有 14 人为此版本贡献了补丁。名字后面带有“+”的人是首次贡献补丁的人。

  • Andrew Wieteska

  • Erfan Nariman

  • Joris Van den Bossche

  • Matthew Roeschke

  • MeeseeksMachine

  • Pandas 开发团队

  • Pav A

  • Richard Shadrach

  • Simon Hawkins

  • Thomas Li

  • Torsten Wörtwein

  • Vladimir Podolskiy +

  • jbrockmendel

  • patrick

1.2.1 版本的新增内容(2021 年 1 月 20 日)

原文:pandas.pydata.org/docs/whatsnew/v1.2.1.html

这些是 pandas 1.2.1 版本的更改。查看发布说明以获取包括 pandas 其他版本在内的完整更改日志。

修复的回归问题

  • 修复了当行数超过chunksize时,to_csv()创建损坏的 zip 文件的回归问题 (GH 38714)

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

  • 修复了在未指定编码时,read_csv() 和其他读取函数中编码错误策略 (errors) 未默认为 "replace" 的回归问题 (GH 38989)

  • 修复了对非原始字节文件句柄的read_excel()中的回归问题 (GH 38788)

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

  • 修复了在扩展 DataFrame 并且新列类型为 "0 - name" 时,DataFrame.__setitem__ 引发 ValueError 的回归问题 (GH 39010)

  • 修复了当 DataFrame 有未排序的 MultiIndex 列且索引器为标量时,使用 DataFrame.loc() 设置时引发 ValueError 的回归问题 (GH 38601)

  • 修复了在使用 DataFrame.loc() 设置时,对具有 MultiIndex 和类似列表的列索引器进行扩展 DataFrame 时引发 KeyError 的回归问题 (GH 39147)

  • 修复了 groupby() 中的回归问题,使用 Categorical 分组列时,grouped.indices 不显示未使用的类别 (GH 38642)

  • 修复了 DataFrameGroupBy.sem()SeriesGroupBy.sem() 中的回归问题,其中存在非数值列会导致错误而不是被删除 (GH 38774)

  • 修复了 DataFrameGroupBy.diff() 中的回归问题,对于 int8int16 列引发错误 (GH 39050)

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

  • 修复了 Rolling.skew()Rolling.kurt() 中的回归问题,这些问题会直接修改对象本身 (GH 38908)

  • 修复了 DataFrame.any()DataFrame.all() 中的回归问题,不会为 tz-aware datetime64 列返回结果 (GH 38723)

  • 修复了 DataFrame.apply() 中的回归问题,当 axis=1 时,在应用函数中使用 str 访问器 (GH 38979)

  • 修复了 DataFrame.replace() 中的回归问题,当 DataFrame 的 dtype 为 bytes 时引发 ValueError (GH 38900)

  • 修复了一个问题,在使用 datetime64[ns, UTC] 数据类型时引发 RecursionErrorSeries.fillna()GH 38851

  • 修复了一个问题,在 NaTdatetime.date 对象之间的比较中错误地返回 TrueGH 39151

  • 修复了一个问题,在数据帧上调用 NumPy accumulate() ufuncs 时引发错误,例如 np.maximum.accumulate(df)GH 39259

  • 修复了一个问题,在 object 数据类型的类似浮点数的字符串的表示中,小数点后的尾部 0 被截断了(GH 38708

  • 修复了一个问题,即在 PyArrow 版本 [0.16.0, 1.0.0) 中引发 AttributeError 的回归问题(GH 38801

  • 修复了一个问题,在 pandas.testing.assert_frame_equal() 使用 check_like=True 时引发 TypeError,当 Index 或列具有混合数据类型时(GH 39168)

我们已经撤销了一个提交,在 pandas 1.2.0 中导致了几个与绘图相关的回归问题(GH 38969GH 38736GH 38865GH 38947GH 39126)。因此,在 pandas 1.2.0 中报告为修复的与条形图中不一致的刻度标签相关的错误再次存在(GH 26186GH 11465) ## 在非对齐的数据帧上调用 NumPy ufuncs

在 pandas 1.2.0 之前,在非对齐的数据帧(或 DataFrame / Series 组合)上调用 NumPy ufunc 将忽略索引,只匹配形状相同的输入,并使用结果的第一个数据帧的索引/列:

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 操作的工作方式相反,其他 pandas 操作首先对齐输入:

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

在 pandas 1.2.0 中,我们重构了如何在数据帧上调用 NumPy ufuncs,并且这开始首先对齐输入(GH 39184),就像其他 pandas 操作和对 Series 对象调用的 ufuncs 一样。

对于 pandas 1.2.1,我们恢复了以避免破坏性更改,但上述使用非对齐输入的 np.add(df1, df2) 的示例现在将会引发警告,而未来的 pandas 2.0 版本将首先对齐输入。在 Series 对象上调用 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 
```  ## 错误修复

+   在 pandas 1.2.0 中更改了 `float_precision` 的默认值后,`read_csv()` 中的一个 bug 使用 `float_precision="high"` 导致长指数字符串的段错误或错误解析。这在某些情况下导致了回归 ([GH 38753](https://github.com/pandas-dev/pandas/issues/38753))

+   在初始化时发生`csv.Error`或`UnicodeDecodeError`时,`read_csv()`中的一个 bug 未关闭已打开的文件句柄 ([GH 39024](https://github.com/pandas-dev/pandas/issues/39024))

+   当 `Index` 具有混合数据类型时,`pandas.testing.assert_index_equal()` 中的 bug 在 `check_order=False` 时引发 `TypeError` ([GH 39168](https://github.com/pandas-dev/pandas/issues/39168))  ## 其他

+   `DataFrame` 和 `Series` 的已弃用属性 `_AXIS_NAMES` 和 `_AXIS_NUMBERS` 将不再出现在 `dir` 或 `inspect.getmembers` 调用中 ([GH 38740](https://github.com/pandas-dev/pandas/issues/38740))

+   将最小 fastparquet 版本提升到 0.4.0 以避免 numba 引发的 `AttributeError` ([GH 38344](https://github.com/pandas-dev/pandas/issues/38344))

+   将最小 pymysql 版本提升到 0.8.1 以避免测试失败 ([GH 38344](https://github.com/pandas-dev/pandas/issues/38344))

+   在 Python 3.9.1 中修复了在 MacOS 11 上的构建失败 ([GH 38766](https://github.com/pandas-dev/pandas/issues/38766))

+   在 pandas 1.1.0 新功能 中为 `testing.assert_frame_equal()` 和 `testing.assert_series_equal()` 添加了与后向不兼容的 `check_freq` 参数的引用 ([GH 34050](https://github.com/pandas-dev/pandas/issues/34050))  ## 贡献者

总共有 20 人为此版本贡献了补丁。带有“+”标记的人首次贡献了补丁。

+   Ada Draginda +

+   Andrew Wieteska

+   Bryan Cutler

+   Fangchen Li

+   Joris Van den Bossche

+   Matthew Roeschke

+   Matthew Zeitlin +

+   MeeseeksMachine

+   Micael Jarniac

+   Omar Afifi +

+   Pandas 开发团队

+   Richard Shadrach

+   Simon Hawkins

+   Terji Petersen

+   Torsten Wörtwein

+   WANG Aiyong

+   jbrockmendel

+   kylekeppler

+   mzeitlin11

+   patrick  ## 修复的回归问题

+   修复了`to_csv()`中的回归问题,当行数超过`chunksize`时会创建损坏的 zip 文件([GH 38714](https://github.com/pandas-dev/pandas/issues/38714))

+   修复了`to_csv()`中的回归问题,以二进制模式而不是文本模式打开了`codecs.StreamReaderWriter`([GH 39247](https://github.com/pandas-dev/pandas/issues/39247))

+   修复了`read_csv()`和其他读取函数中的回归问题,当未指定编码时,编码错误策略 (`errors`) 没有默认为`"replace"`([GH 38989](https://github.com/pandas-dev/pandas/issues/38989))

+   修复了使用非原始字节文件句柄时的`read_excel()`中的回归问题([GH 38788](https://github.com/pandas-dev/pandas/issues/38788))

+   修复了`DataFrame.to_stata()`中的回归问题,当出现错误时未删除创建的文件([GH 39202](https://github.com/pandas-dev/pandas/issues/39202))

+   修复了`DataFrame.__setitem__`中的回归问题,当扩展`DataFrame`并且新列的类型为`"0 - name"`时会引发`ValueError`([GH 39010](https://github.com/pandas-dev/pandas/issues/39010))

+   修复了使用 `DataFrame.loc()` 设置时引发`ValueError`的回归问题,当`DataFrame`具有未排序的`MultiIndex`列且索引器为标量时([GH 38601](https://github.com/pandas-dev/pandas/issues/38601))

+   修复了使用 `DataFrame.loc()` 设置时引发`KeyError`的回归问题,当使用`MultiIndex`和类似列表的列索引器扩大 `DataFrame` 时([GH 39147](https://github.com/pandas-dev/pandas/issues/39147))

+   修复了`groupby()`在使用`Categorical`分组列时,对于`grouped.indices`未显示未使用类别的回归问题([GH 38642](https://github.com/pandas-dev/pandas/issues/38642))

+   修复了`DataFrameGroupBy.sem()`和`SeriesGroupBy.sem()`中存在非数值列会导致错误而不是被删除的回归问题([GH 38774](https://github.com/pandas-dev/pandas/issues/38774))

+   修复了`DataFrameGroupBy.diff()`在处理`int8`和`int16`列时引发错误的回归问题([GH 39050](https://github.com/pandas-dev/pandas/issues/39050))

+   修复了`DataFrame.groupby()`在聚合`ExtensionDType`时对非数值值可能失败的回归问题([GH 38980](https://github.com/pandas-dev/pandas/issues/38980))

+   修复了`Rolling.skew()`和`Rolling.kurt()`在原地修改对象的回归问题([GH 38908](https://github.com/pandas-dev/pandas/issues/38908))

+   修复了`DataFrame.any()`和`DataFrame.all()`在处理带有时区信息的`datetime64`列时未返回结果的回归问题([GH 38723](https://github.com/pandas-dev/pandas/issues/38723))

+   修复了`DataFrame.apply()`在使用`axis=1`时,在应用函数中使用 str 访问器时引发错误的回归问题([GH 38979](https://github.com/pandas-dev/pandas/issues/38979))

+   修复了`DataFrame.replace()`在`DataFrame`的 dtype 为`bytes`时引发`ValueError`的回归问题([GH 38900](https://github.com/pandas-dev/pandas/issues/38900))

+   修复了在 `Series.fillna()` 中使用 `datetime64[ns, UTC]` dtype 时引发 `RecursionError` 的回归问题([GH 38851](https://github.com/pandas-dev/pandas/issues/38851))

+   修复了 `NaT` 和 `datetime.date` 对象之间比较错误地返回 `True` 的回归问题([GH 39151](https://github.com/pandas-dev/pandas/issues/39151))

+   修复了在 DataFrames 上调用 NumPy `accumulate()` ufuncs 时的回归问题,例如 `np.maximum.accumulate(df)`([GH 39259](https://github.com/pandas-dev/pandas/issues/39259))

+   修复了在 `object` dtype 中浮点类似字符串的 repr 中,小数点后的尾随 0 被截断的回归问题([GH 38708](https://github.com/pandas-dev/pandas/issues/38708))

+   修复了在 PyArrow 版本 [0.16.0, 1.0.0) 中引发 `AttributeError` 的回归问题([GH 38801](https://github.com/pandas-dev/pandas/issues/38801))

+   修复了在 `pandas.testing.assert_frame_equal()` 中使用 `check_like=True` 时,当 `Index` 或列具有混合 dtype 时引发 `TypeError` 的回归问题([GH 39168](https://github.com/pandas-dev/pandas/issues/39168))

我们已经回滚了一个提交,导致了 pandas 1.2.0 中几个与绘图相关的回归问题([GH 38969](https://github.com/pandas-dev/pandas/issues/38969),[GH 38736](https://github.com/pandas-dev/pandas/issues/38736),[GH 38865](https://github.com/pandas-dev/pandas/issues/38865),[GH 38947](https://github.com/pandas-dev/pandas/issues/38947) 和 [GH 39126](https://github.com/pandas-dev/pandas/issues/39126))。因此,在 pandas 1.2.0 中报告为已修复的与条形图中标签不一致的错误再次出现([GH 26186](https://github.com/pandas-dev/pandas/issues/26186) 和 [GH 11465](https://github.com/pandas-dev/pandas/issues/11465))

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

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

```py
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 中,我们重构了如何在 DataFrames 上调用 NumPy ufuncs,并且这开始首先对齐输入(GH 39184),就像其他 pandas 操作和在 Series 对象上调用 ufuncs 时一样。

对于 pandas 1.2.1,我们恢复了先前的行为以避免破坏性更改,但上述示例中的 np.add(df1, df2) 使用非对齐输入将会引发警告,未来的 pandas 2.0 版本将首先对齐输入(GH 39184)。在 Series 对象上调用 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 

Bug 修复

  • float_precision="high" 的情况下 read_csv() 中的错误导致 segfault 或长指数字符串的错误解析。这在某些情况下导致了回归,因为 float_precision 的默认值在 pandas 1.2.0 中已更改(GH 38753

  • 在初始化时 read_csv() 出现 csv.ErrorUnicodeDecodeError 时未关闭已打开的文件句柄的错误(GH 39024

  • pandas.testing.assert_index_equal() 中的错误,当 Index 具有混合 dtype 时,使用 check_order=False 会引发 TypeErrorGH 39168

其他

  • 已弃用的 DataFrameSeries 的属性 _AXIS_NAMES_AXIS_NUMBERS 将不再出现在 dirinspect.getmembers 调用中(GH 38740

  • 将最小的 fastparquet 版本提升到 0.4.0 以避免 numba 的 AttributeErrorGH 38344

  • 将最小的 pymysql 版本提升到 0.8.1 以避免测试失败(GH 38344

  • 修复了在 Python 3.9.1 中在 MacOS 11 上构建失败的问题(GH 38766

  • 在 pandas 1.1.0 新功能 中的 testing.assert_frame_equal()testing.assert_series_equal() 中添加了对不兼容的 check_freq 参数的引用(GH 34050

贡献者

本次发布中共有 20 人贡献了补丁。名字旁边带有“+”符号的人第一次贡献了补丁。

  • Ada Draginda +

  • Andrew Wieteska

  • Bryan Cutler

  • Fangchen Li

  • Joris Van den Bossche

  • Matthew Roeschke

  • Matthew Zeitlin +

  • MeeseeksMachine

  • Micael Jarniac

  • Omar Afifi +

  • Pandas 开发团队

  • Richard Shadrach

  • Simon Hawkins

  • Terji Petersen

  • Torsten Wörtwein

  • 王爱勇

  • jbrockmendel

  • kylekeppler

  • mzeitlin11

  • patrick

1.2.0 中的新功能(2020 年 12 月 26 日)

原文:pandas.pydata.org/docs/whatsnew/v1.2.0.html

这些是 pandas 1.2.0 的更改。查看发行说明以获取包括其他版本的完整更改日志。

警告

用于写旧式 .xls Excel 文件的 xlwt 包不再维护。现在 xlrd 包仅用于读取旧式 .xls 文件。

以前,对 read_excel() 的默认参数 engine=None 在许多情况下会导致使用 xlrd 引擎,包括新的 Excel 2007+(.xlsx)文件。如果安装了 openpyxl,则现在许多这些情况将默认使用 openpyxl 引擎。有关更多详细信息,请参阅 read_excel() 文档。

因此,强烈建议安装 openpyxl 以读取 Excel 2007+(.xlsx)文件。请不要在使用 xlrd 读取 .xlsx 文件时报告问题。 这已不再受支持,请改用 openpyxl

尝试使用 xlwt 引擎将引发 FutureWarning,除非选项 io.excel.xls.writer 设置为 "xlwt"。虽然此选项现已不推荐使用并且也会引发 FutureWarning,但可以全局设置并抑制警告。建议用户改用 openpyxl 引擎来写入 .xlsx 文件。

增强功能

可选地禁止重复标签

SeriesDataFrame 现在可以使用 allows_duplicate_labels=False 标志创建,以控制索引或列是否可以包含重复标签(GH 28394)。这可用于防止意外引入重复标签,这可能会影响下游操作。

默认情况下,允许继续存在重复标签。

In [1]: pd.Series([1, 2], index=['a', 'a'])
Out[1]:
a    1
a    2
Length: 2, dtype: int64

In [2]: pd.Series([1, 2], index=['a', 'a']).set_flags(allows_duplicate_labels=False)
...
DuplicateLabelError: Index has duplicates.
 positions
label
a        [0, 1] 

pandas 将通过许多操作传播 allows_duplicate_labels 属性。

In [3]: a = (
 ...:    pd.Series([1, 2], index=['a', 'b'])
 ...:      .set_flags(allows_duplicate_labels=False)
 ...: )

In [4]: a
Out[4]:
a    1
b    2
Length: 2, dtype: int64

# An operation introducing duplicates
In [5]: a.reindex(['a', 'b', 'a'])
...
DuplicateLabelError: Index has duplicates.
 positions
label
a        [0, 2]

[1 rows x 1 columns] 

警告

这是一个实验性功能。目前,许多方法无法传播 allows_duplicate_labels 值。预计在未来版本中,每个接受或返回一个或多个 DataFrame 或 Series 对象的方法都将传播 allows_duplicate_labels

查看重复标签了解更多信息。

allows_duplicate_labels 标志存储在新的 DataFrame.flags 属性中。这会存储适用于 pandas 对象 的全局属性。这与DataFrame.attrs不同,后者存储适用于数据集的信息。

传递参数给 fsspec 后端

许多读写函数已经添加了可选参数storage_options,用于传递参数字典给存储后端。例如,这允许传递凭据给 S3 和 GCS 存储。可以在各个存储后端的文档中找到可以传递给哪些后端的参数的详细信息(从fsspec 文档中的内置实现详细说明,并链接到外部实现)。请参阅读取/写入远程文件部分。

GH 35655为读取 excel 文件添加了 fsspec 支持(包括storage_options)。

支持to_csv中的二进制文件句柄

to_csv()支持以二进制模式打开的文件句柄(GH 19827GH 35058),并且支持encodingGH 13068GH 23854)以及compressionGH 22555)。如果 pandas 无法自动检测文件句柄是以二进制还是文本模式打开的,需要提供mode="wb"

例如:

In [1]: import io

In [2]: data = pd.DataFrame([0, 1, 2])

In [3]: buffer = io.BytesIO()

In [4]: data.to_csv(buffer, encoding="utf-8", compression="gzip") 

to_latex中支持短标题和表格位置

DataFrame.to_latex()现在允许指定浮动表格位置(GH 35281)和短标题(GH 36267)。

已添加关键字position以设置位置。

In [5]: data = pd.DataFrame({'a': [1, 2], 'b': [3, 4]})

In [6]: table = data.to_latex(position='ht')

In [7]: print(table)
\begin{table}[ht]
\begin{tabular}{lrr}
\toprule
 & a & b \\
\midrule
0 & 1 & 3 \\
1 & 2 & 4 \\
\bottomrule
\end{tabular}
\end{table} 

关键字caption的用法已经扩展。除了接受单个字符串作为参数外,还可以选择性地提供一个元组(full_caption, short_caption)来添加一个短标题宏。

In [8]: data = pd.DataFrame({'a': [1, 2], 'b': [3, 4]})

In [9]: table = data.to_latex(caption=('the full long caption', 'short caption'))

In [10]: print(table)
\begin{table}
\caption[short caption]{the full long caption}
\begin{tabular}{lrr}
\toprule
 & a & b \\
\midrule
0 & 1 & 3 \\
1 & 2 & 4 \\
\bottomrule
\end{tabular}
\end{table} 

更改read_csvread_table的默认浮点精度

对于 C 解析引擎,之前的方法read_csv()read_table() 默认使用的解析器在读取浮点数时可能会存在与精度的最后一位略有不正确的情况。选项 floating_precision="high" 一直可用以避免此问题。从此版本开始,默认使用更准确的解析器,使 floating_precision=None 对应高精度解析器,而新选项 floating_precision="legacy" 则使用旧解析器。默认改用更高精度解析器不应对性能产生影响。 (GH 17154) ### 实验性浮点数据的可空数据类型

我们已添加Float32Dtype / Float64DtypeFloatingArray。这些是专门用于浮点数据的扩展数据类型,可以容纳pd.NA 缺失值指示器 (GH 32265, GH 34307)。

虽然默认的浮点数据类型已支持使用 np.nan 的缺失值,但这些新数据类型使用 pd.NA(及其相应的行为)作为缺失值指示器,与已存在的可空整数和布尔数据类型一致。

np.nanpd.NA 行为不同的一个示例是比较操作:

# the default NumPy float64 dtype
In [11]: s1 = pd.Series([1.5, None])

In [12]: s1
Out[12]: 
0    1.5
1    NaN
dtype: float64

In [13]: s1 > 1
Out[13]: 
0     True
1    False
dtype: bool 
# the new nullable float64 dtype
In [14]: s2 = pd.Series([1.5, None], dtype="Float64")

In [15]: s2
Out[15]: 
0     1.5
1    <NA>
dtype: Float64

In [16]: s2 > 1
Out[16]: 
0    True
1    <NA>
dtype: boolean 

更多有关使用 pd.NA 缺失值指示器时的行为的详细信息,请参阅 NA 语义文档部分。

如上所示,可以使用字符串“Float64”或“Float32”指定 dtype(大写以区别于默认的“float64”数据类型)。或者,您也可以使用 dtype 对象:

In [17]: pd.Series([1.5, None], dtype=pd.Float32Dtype())
Out[17]: 
0     1.5
1    <NA>
dtype: Float32 

使用现有的整数或布尔可空数据类型进行浮点结果的操作现在也将使用可空浮点数据类型 (GH 38178)。

警告

实验性:新的浮点数据类型目前是实验性的,其行为或 API 可能仍会发生更改,而不另行通知。特别是关于 NaN(与 NA 缺失值不同)的行为可能会发生变化。 ### 聚合时保留索引/列名

在使用concat()DataFrame构造函数进行聚合时,pandas 现在会尽可能保留索引和列名(GH 35847)。在所有输入共享通用名称的情况下,该名称将分配给结果。当输入名称不完全一致时,结果将不具有名称。下面是一个保留索引名称的示例:

In [18]: idx = pd.Index(range(5), name='abc')

In [19]: ser = pd.Series(range(5, 10), index=idx)

In [20]: pd.concat({'x': ser[1:], 'y': ser[:-1]}, axis=1)
Out[20]: 
 x    y
abc 
1    6.0  6.0
2    7.0  7.0
3    8.0  8.0
4    9.0  NaN
0    NaN  5.0 

对于MultiIndex来说,情况也是一样的,但逻辑是逐级别地分开应用的。 ### GroupBy 直接支持 EWM 操作

DataFrameGroupBy现在直接支持指数加权窗口操作(GH 16037)。

In [21]: df = pd.DataFrame({'A': ['a', 'b', 'a', 'b'], 'B': range(4)})

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

In [23]: df.groupby('A').ewm(com=1.0).mean()
Out[23]: 
 B
A 
a 0  0.000000
 2  1.333333
b 1  1.000000
 3  2.333333 

此外,mean现在支持通过Numba以及engineengine_kwargs参数直接执行。要使用此功能,必须将 Numba 安装为可选依赖项。 ### 其他增强功能

  • TimestampDatetimeIndexPeriodPeriodIndex添加了day_of_week(兼容别名为dayofweek)属性(GH 9605)

  • TimestampDatetimeIndexPeriodPeriodIndex添加了day_of_year(兼容别名为dayofyear)属性(GH 9605

  • DataFrame或 DataFrame 设置表格级别的标志添加了set_flags()GH 28394)

  • DataFrame.applymap()现在支持na_actionGH 23803

  • 带有对象 dtype 的Index支持除法和乘法(GH 34160

  • io.sql.get_schema() 现在支持 schema 关键字参数,可以将模式添加到创建表的语句中(GH 28486

  • DataFrame.explode()Series.explode() 现在支持对集合进行展开(GH 35614

  • DataFrame.hist() 现在支持时间序列(日期时间)数据(GH 32590

  • Styler.set_table_styles() 现在允许直接对行和列进行样式设置,并且可以链式调用(GH 35607

  • Styler 现在允许直接向各个数据单元格添加 CSS 类名(GH 36159

  • Rolling.mean()Rolling.sum() 使用 Kahan 总和法来计算均值,以避免数值问题(GH 10319GH 11645GH 13254GH 32761GH 36031

  • DatetimeIndex.searchsorted(), TimedeltaIndex.searchsorted(), PeriodIndex.searchsorted(),以及 Series.searchsorted() 在具有类似日期时间的数据类型时,现在会尝试将字符串参数(列表形式和标量)转换为相应的日期时间类型(GH 36346

  • 添加了方法 IntegerArray.prod()IntegerArray.min()IntegerArray.max()GH 33790

  • DataFrame 上调用 NumPy ufunc 时,现在会尽可能地保留扩展类型(GH 23743

  • 调用二进制输入的 NumPy ufunc 在多个 DataFrame 对象上现在会对齐,与 Series 上的二进制操作和 ufuncs 的行为相匹配(GH 23743)。这一变更已在 pandas 1.2.1 中被撤销,不对齐 DataFrames 的行为已被弃用,请参阅 1.2.1 发行说明。

  • 在可能的情况下,RangeIndex.difference()RangeIndex.symmetric_difference() 将返回 RangeIndex 而不是 Int64IndexGH 36564)

  • DataFrame.to_parquet() 现在支持 parquet 格式中的列的 MultiIndexGH 34777

  • read_parquet() 增加了 use_nullable_dtypes=True 选项,以在可能的情况下使用 pd.NA 作为缺失值指示符号的可空数据类型,用于生成的 DataFrame(默认为 False,仅适用于 engine="pyarrow")(GH 31242

  • 添加了 Rolling.sem()Expanding.sem() 来计算均值的标准误差(GH 26476

  • Rolling.var()Rolling.std() 使用 Kahan 求和和 Welford 方法避免数值问题(GH 37051

  • DataFrame.corr()DataFrame.cov() 使用 Welford 方法避免数值问题(GH 37448

  • DataFrame.plot() 现在识别 scatterhexbin 类型图的 xlabelylabel 参数(GH 37001

  • DataFrame 现在支持 divmod 操作(GH 37165

  • DataFrame.to_parquet() 现在在没有传递 path 参数时返回一个 bytes 对象(GH 37105)

  • Rolling 现在支持固定窗口的 closed 参数(GH 34315

  • DatetimeIndexSeries 现在支持 datetime64datetime64tz dtypes 的 stdGH 37436

  • Window 现在在 win_type 中支持所有 Scipy 窗口类型,并具有灵活的关键字参数支持(GH 34556

  • testing.assert_index_equal() 现在有一个 check_order 参数,允许以无序方式检查索引(GH 37478

  • read_csv() 支持对压缩文件进行内存映射(GH 37621

  • DataFrame.groupby()DataFrame.resample() 添加对 min_count 关键字的支持,用于 minmaxfirstlast 函数(GH 37821GH 37768

  • 改进了对 DataFrame.merge() 的错误报告,当给出无效的合并列定义时(GH 16228

  • 改进了 Rolling.skew()Rolling.kurt()Expanding.skew()Expanding.kurt() 的数值稳定性,通过实现 Kahan 求和(GH 6929

  • 改进了对带有 axis=1DataFrameGroupBy 的列子集的错误报告(GH 37725

  • DataFrame.merge()DataFrame.join()实现了cross方法(GH 5401

  • 当使用chunksize/iterator调用read_csv()read_sas()read_json()时,它们可以在with语句中使用,因为它们返回上下文管理器(GH 38225

  • 扩展了可用于样式化 Excel 导出的命名颜色列表,启用了所有 CSS4 颜色(GH 38247) ## 值得注意的错误修复

这些是可能具有显着行为更改的错误修复。

DataFrame 缩减的一致性

DataFrame.any()DataFrame.all()现在使用bool_only=True确定是否基于逐列的基础来排除对象 dtype 列,而不是检查所有对象 dtype 列是否可以被视为布尔值。

这可以防止将缩减应用于列子集时可能导致更大的 Series 结果的病态行为。参见(GH 37799)。

In [24]: df = pd.DataFrame({"A": ["foo", "bar"], "B": [True, False]}, dtype=object)

In [25]: df["C"] = pd.Series([True, True]) 

先前的行为

In [5]: df.all(bool_only=True)
Out[5]:
C    True
dtype: bool

In [6]: df[["B", "C"]].all(bool_only=True)
Out[6]:
B    False
C    True
dtype: bool 

新行为

In [26]: In [5]: df.all(bool_only=True)
Out[26]: 
C    True
dtype: bool

In [27]: In [6]: df[["B", "C"]].all(bool_only=True)
Out[27]: 
C    True
dtype: bool 

使用numeric_only=None的其他 DataFrame 缩减操作也将避免这种病态行为(GH 37827):

In [28]: df = pd.DataFrame({"A": [0, 1, 2], "B": ["a", "b", "c"]}, dtype=object) 

先前的行为

In [3]: df.mean()
Out[3]: Series([], dtype: float64)

In [4]: df[["A"]].mean()
Out[4]:
A    1.0
dtype: float64 

新行为

In [3]: df.mean()
Out[3]:
A    1.0
dtype: float64

In [4]: df[["A"]].mean()
Out[4]:
A    1.0
dtype: float64 

此外,使用numeric_only=None的 DataFrame 缩减现在将与其 Series 对应部分保持一致。特别是,对于 Series 方法引发TypeError的缩减,DataFrame 缩减现在将考虑该列为非数值,而不是将其转换为可能具有不同语义的 NumPy 数组(GH 36076GH 28949GH 21020)。

In [29]: ser = pd.Series([0, 1], dtype="category", name="A")

In [30]: df = ser.to_frame() 

先前的行为

In [5]: df.any()
Out[5]:
A    True
dtype: bool 

新行为

In [5]: df.any()
Out[5]: Series([], dtype: bool) 

增加了 Python 的最低版本

pandas 1.2.0 支持 Python 3.7.1 及更高版本(GH 35214)。 ### 增加了依赖项的最低版本

更新了一些依赖项的最低支持版本(GH 35214)。如果已安装,我们现在需要:

最低版本 需要 已更改
numpy 1.16.5 X X
pytz 2017.3 X X
python-dateutil 2.7.3 X
bottleneck 1.2.1
numexpr 2.6.8 X
pytest (dev) 5.0.1 X
mypy (dev) 0.782 X

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

最低版本 已更改
beautifulsoup4 4.6.0
fastparquet 0.3.2
fsspec 0.7.4
gcsfs 0.6.0
lxml 4.3.0 X
matplotlib 2.2.3 X
numba 0.46.0
openpyxl 2.6.0 X
pyarrow 0.15.0 X
pymysql 0.7.11 X
pytables 3.5.1 X
s3fs 0.4.0
scipy 1.2.0
sqlalchemy 1.2.8 X
xarray 0.12.3 X
xlrd 1.2.0 X
xlsxwriter 1.0.2 X
xlwt 1.3.0 X
pandas-gbq 0.12.0

有关更多信息,请参见依赖项和可选依赖项 ### 其他 API 更改

  • 对于 Datetime-like Index 子类,现在 Series.sort_values()Index.sort_values() 的降序排序是稳定的。这会影响到当对 DataFrame 在多列上进行排序、使用产生重复值的键函数进行排序或者在使用 Index.sort_values() 时请求排序索引时的排序顺序。在使用 Series.value_counts() 时,缺失值的计数不再一定在重复计数列表的最后。相反,它的位置对应于原始 Series 中的位置。当对 Datetime-like Index 子类使用 Index.sort_values() 时,NaTs 忽略了 na_position 参数并被排序到开头。现在它们遵守 na_position,默认为 last,与其他 Index 子类相同 (GH 35992)

  • 将无效的 fill_value 传递给 Categorical.take()DatetimeArray.take()TimedeltaArray.take()PeriodArray.take() 现在引发 TypeError 而不是 ValueError (GH 37733)

  • Passing an invalid fill_value to Series.shift() with a CategoricalDtype now raises a TypeError instead of a ValueError (GH 37733)

  • Passing an invalid value to IntervalIndex.insert() or CategoricalIndex.insert() now raises a TypeError instead of a ValueError (GH 37733)

  • Attempting to reindex a Series with a CategoricalIndex with an invalid fill_value now raises a TypeError instead of a ValueError (GH 37733)

  • CategoricalIndex.append() with an index that contains non-category values will now cast instead of raising TypeError (GH 38098) ## Deprecations

  • Deprecated parameter inplace in MultiIndex.set_codes() and MultiIndex.set_levels() (GH 35626)

  • Deprecated parameter dtype of method copy() for all Index subclasses. Use the astype() method instead for changing dtype (GH 35853)

  • Deprecated parameters levels and codes in MultiIndex.copy(). Use the set_levels() and set_codes() methods instead (GH 36685)

  • Date parser functions parse_date_time(), parse_date_fields(), parse_all_fields() and generic_parser() from pandas.io.date_converters are deprecated and will be removed in a future version; use to_datetime() instead (GH 35741)

  • DataFrame.lookup()已被弃用,并将在未来版本中删除,请改用DataFrame.melt()DataFrame.loc()(参见GH 35224

  • 方法Index.to_native_types()已弃用。请改用.astype(str)(参见GH 28867

  • 使用单个类似日期时间的字符串作为df[string]的索引行(由于模棱两可是索引行还是选择列),已被废弃,请改用df.loc[string](参见GH 36179

  • 弃用Index.is_all_dates()(参见GH 27744

  • Series.str.replace()regex默认值将在将来的版本中从True更改为False。此外,当设置regex=True时,单个字符正则表达式将被视为文字字符串(参见GH 24804

  • 自动对比操作在DataFrameSeries之间已被弃用,请在例如frame == ser之前执行frame, ser = frame.align(ser, axis=1, copy=False)(参见GH 28759

  • 在未来版本中,带有min_periods=NoneRolling.count()将默认为窗口大小(参见GH 31302

  • 在 DataFrame 上使用“outer”ufuncs 返回 4d ndarray 现已被弃用。请先转换为 ndarray(参见GH 23743

  • 在带有时区信息的DatetimeIndex上使用不带时区信息的datetime对象进行切片索引已被弃用,以匹配标量索引行为(参见GH 36148

  • 返回np.ndarrayIndex.ravel()已弃用,将来将返回相同索引的视图(参见GH 19956

  • 弃用使用带有‘M’、‘Y’或‘y’单位的字符串表示单位的to_timedelta()(参见GH 36666

  • Index的方法&|^的行为类似于集合操作Index.intersection()Index.union()Index.symmetric_difference(),已弃用,并且将来将作为与Series行为匹配的逐点布尔操作。请改用命名的集合方法代替(GH 36758)

  • Categorical.is_dtype_equal()CategoricalIndex.is_dtype_equal()已弃用,将在将来的版本中删除(GH 37545)

  • Series.slice_shift()DataFrame.slice_shift()已弃用,请改用Series.shift()DataFrame.shift()代替(GH 37601)

  • 对于无序的DatetimeIndex对象进行部分切片,其中键不在索引中,已弃用,并将在将来的版本中删除(GH 18531)

  • PeriodIndex.astype()中的how关键字已弃用,并将在将来的版本中删除,请改用index.to_timestamp(how=how)代替(GH 37982)

  • 对于Index的子类,除了DatetimeIndexTimedeltaIndexPeriodIndex,已弃用Index.asi8()GH 37877)

  • Categorical.remove_unused_categories()inplace参数已弃用,并将在将来的版本中删除(GH 37643)

  • DataFrame.info()null_counts参数已弃用,并由show_counts替代。将在将来的版本中删除(GH 37999)

在非对齐的 DataFrame 上调用 NumPy ufuncs

在 pandas 1.2.0 中对非对齐 DataFrame 调用 NumPy ufuncs 的行为已更改(在调用 ufunc 之前对输入进行对齐),但此更改已在 pandas 1.2.1 中撤销。 不对齐的行为现已弃用,请参阅 1.2.1 版本说明了解更多详细信息。 ## 性能改进

  • 创建包含许多字符串元素的数组并使用 strStringDtype 类型的 DataFrame 或 Series 时的性能改进 (GH 36304, GH 36317, GH 36325, GH 36432, GH 37371)

  • 使用 numba 引擎时 DataFrameGroupBy.agg()SeriesGroupBy.agg() 中的性能改进 (GH 35759)

  • 从大型字典创建 Series.map() 时的性能改进 (GH 34717)

  • 使用 numba 引擎时 DataFrameGroupBy.transform()SeriesGroupBy.transform() 中的性能改进 (GH 36240)

  • Styler 的 uuid 方法已更改,以在保持合理低的表冲突概率的同时压缩 Web 上的数据传输 (GH 36345)

  • 使用非 ns 时间单位的 float dtype 列时的 to_datetime() 性能改进 (GH 20445)

  • IntervalArray 上设置值时的性能改进 (GH 36310)

  • 内部索引方法_shallow_copy()现在使新索引和原索引共享缓存属性,避免再次创建这些属性,如果在任一处创建了。这可以加快依赖于创建现有索引副本的操作的速度(GH 36840

  • RollingGroupby.count()的性能改进(GH 35625

  • 固定窗口的Rolling.min()Rolling.max()略微减慢性能(GH 36567

  • 在使用 python 3.8+中的protocol=5时,DataFrame.to_pickle()的峰值内存使用量减少(GH 34244

  • 当对象具有许多索引标签时,例如dir(ser)dir调用更快速(GH 37450

  • ExpandingGroupby的性能改进(GH 37064

  • Series.astype()DataFrame.astype()针对Categorical的性能改进(GH 8628

  • DataFrame.groupby()float dtype的性能改进(GH 28303),底层哈希函数的更改可能会导致基于浮点数的索引排序的变化(例如Index.value_counts()

  • pd.isin()针对元素超过 1e6 的输入的性能改进(GH 36611

  • 使用类似列表的索引器时DataFrame.__setitem__()的性能改进(GH 37954

  • 当指定 chunksize 时,read_json()现在避免将整个文件读入内存(GH 34548

分类

  • Categorical.fillna() 将始终返回一个副本,无论是否有任何 NA 需要填充,都会验证传递的填充值,并且禁止将 NaT 用作数值类别的填充值(GH 36530)

  • Categorical.__setitem__() 中的错误,尝试设置元组值时错误地引发异常(GH 20439)

  • CategoricalIndex.equals() 中的错误,错误地将非类别条目强制转换为 np.nanGH 37667)

  • CategoricalIndex.where() 中的错误,错误地将非类别条目设置为 np.nan 而不是引发 TypeErrorGH 37977)

  • Categorical.to_numpy()np.array(categorical) 中的错误,具有时区感知的 datetime64 类别错误地丢弃时区信息,而不是转换为对象 dtype(GH 38136)

日期时间类似

  • DataFrame.combine_first() 中的错误,当在原始 DataFrame 中不存在列时,会将其他 DataFrame 上的日期时间类似列转换为整数(GH 28481)

  • DatetimeArray.date 中的错误,当只读备份数组引发 ValueError 时(GH 33530)

  • 在无效的不等式比较上,NaT 比较失败,未引发 TypeError 的错误(GH 35046)

  • DateOffset 中的错误,从 pickle 文件重新构建的属性与原始对象不同,当输入值超出正常范围时(例如,月份=12)(GH 34511)

  • DatetimeIndex.get_slice_bound() 中的错误,其中不接受 datetime.date 对象或具有时区感知的 Timestamp 与具有时区感知的 DatetimeIndexGH 35690)

  • DatetimeIndex.slice_locs() 中的错误,其中不接受 datetime.date 对象(GH 34077)

  • DatetimeIndex.searchsorted()TimedeltaIndex.searchsorted()PeriodIndex.searchsorted()Series.searchsorted() 中的 Bug,与 NumPy 不一致地放置 NaT 值的 datetime64timedelta64Period dtype(GH 36176GH 36254

  • DatetimeArrayTimedeltaArrayPeriodArray 中方法 __setitem__ 中的不一致性,将字符串数组转换为日期时间样式标量,但不转换标量字符串(GH 36261

  • DatetimeArray.take() 中的 Bug 错误地允许了带有不匹配时区的 fill_valueGH 37356

  • DatetimeIndex.shift 中的 Bug 在移动空索引时错误地引发异常(GH 14811

  • TimestampDatetimeIndex 在时区感知和时区不感知对象之间的比较现在遵循标准库 datetime 行为,对于 !=/== 返回 True/False,对于不等式比较引发异常(GH 28507

  • DatetimeIndex.equals()TimedeltaIndex.equals() 中的 Bug 错误地将 int64 索引视为相等(GH 36744

  • 当 orient 结构为 table 时,Series.to_json()DataFrame.to_json()read_json() 现在实现了时区解析(GH 35973

  • astype() 现在尝试直接从推断出的字符串中的时区转换为 datetime64[ns, tz]GH 35973

  • TimedeltaIndex.sum()Series.sum() 中的 Bug,在空索引或系列上返回 NaT 而不是 Timedelta(0)timedelta64 dtype(GH 31751

  • DatetimeArray.shift() 中的错误,错误地允许 fill_value 与不匹配的时区 (GH 37299)

  • 将非零 offsetBusinessDay 添加到非标量其他值中的错误 (GH 37457)

  • 对于只读数组,在 to_datetime() 中错误地引发异常 (GH 34857)

  • Series.isin() 中的错误,对于 datetime64[ns] dtype 和 DatetimeIndex.isin(),错误地将整数转换为日期时间 (GH 36621)

  • Series.isin() 中的错误,对于 datetime64[ns] dtype 和 DatetimeIndex.isin(),未考虑到时区感知和时区非感知的日期时间始终不同 (GH 35728)

  • Series.isin() 中的错误,对于 PeriodDtype dtype 和 PeriodIndex.isin(),未考虑到参数与不同 PeriodDtype 始终不同 (GH 37528)

  • 现在正确处理 value 参数中的纳秒的 Period 构造函数中的错误 (GH 34621GH 17053)

时间间隔

  • 对于 timedelta64 dtypes 和分母中的 NaTTimedeltaIndexSeriesDataFrame 中的地板除法错误 (GH 35529)

  • 对 ISO 8601 时间间隔在 Timedeltato_datetime() 中的解析错误 (GH 29773, GH 36204)

  • 对于只读数组,在 to_timedelta() 中错误地引发异常 (GH 34857)

  • Timedelta 存在错误,在输入字符串的精度高于纳秒时,错误地截断为亚秒部分(GH 36738

时区

  • date_range() 存在错误,在 ambiguous=False 的情况下,对有效输入引发 AmbiguousTimeErrorGH 35297

  • Timestamp.replace() 存在错误,丢失了折叠信息(GH 37610

数值

  • to_numeric() 存在错误,浮点精度不正确(GH 31364

  • DataFrame.any()axis=1bool_only=True 的情况下忽略了 bool_only 关键字(GH 32432

  • Series.equals() 存在错误,当将 NumPy 数组与标量进行比较时,会引发 ValueErrorGH 35267

  • Series 存在错误,当两个具有不同时区的 DatetimeIndex 的 Series 进行算术运算时,这些索引会错误地更改(GH 33671

  • 在使用 pandas.testing 模块函数时,当在复杂数值类型上使用 check_exact=False 时存在问题(GH 28235

  • DataFrame.__rmatmul__() 存在错误处理,报告了转置形状的问题(GH 21581

  • Series 的灵活算术方法存在错误,当与 listtuplenp.ndarray 进行操作时,结果的名称会不正确(GH 36760

  • IntegerArray 的乘法存在错误,与 timedeltanp.timedelta64 对象相乘时出现问题(GH 36870

  • MultiIndex 与元组比较时存在错误,错误地将元组视为类似数组(GH 21517

  • DataFrame.diff() 在包含 NaT 值的 datetime64 数据类型时未能正确填充 NaT 结果的错误(GH 32441

  • DataFrame 算术运算中的错误接受关键字参数(GH 36843

  • IntervalArraySeries 的比较不返回 Series 的错误(GH 36908

  • DataFrame 允许与未定义结果的数组列表进行算术操作的错误。行为更改为引发 ValueErrorGH 36702

  • DataFrame.std()timedelta64 数据类型和 skipna=False 时的错误(GH 37392

  • DataFrame.min()DataFrame.max()datetime64 数据类型和 skipna=False 时的错误(GH 36907

  • DataFrame.idxmax()DataFrame.idxmin() 混合数据类型时错误地引发 TypeErrorGH 38195

转换

  • DataFrame.to_dict()orient='records' 时返回具有 python 原生日期时间对象的日期时间列的错误(GH 21256

  • Series.astype()string 转换为 float 时在存在 pd.NA 值时引发错误(GH 37626

字符串

  • Series.to_string()DataFrame.to_string()DataFrame.to_latex() 中的错误,在 index=False 时添加一个前导空格(GH 24980

  • to_numeric() 中的错误,在尝试转换仅包含数字字符串和 NA 的字符串 dtype Series 时引发 TypeErrorGH 37262

区间

  • DataFrame.replace()Series.replace() 中的错误,会将 Interval 的 dtype 转换为 object dtype(GH 34871

  • IntervalIndex.take() 中的错误,带有负索引和 fill_value=NoneGH 37330

  • IntervalIndex.putmask() 中的错误,带有 datetime-like dtype,错误地转换为 object dtype(GH 37968

  • IntervalArray.astype() 中的错误会错误地丢弃带有 CategoricalDtype 对象的 dtype 信息(GH 37984

索引

  • PeriodIndex.get_loc() 中的错误会错误地引发 ValueError,而不是 KeyError,导致 Series.__getitem__()Series.__contains__()Series.loc.__getitem__() 中出现类似的错误(GH 34240

  • Index.sort_values() 中的错误,在传递空值时,该方法会尝试比较缺失值,而不是将它们推到排序顺序的末尾,导致方法中断(GH 35584

  • Index.get_indexer()Index.get_indexer_non_unique() 中的错误,会返回 int64 数组,而不是 intpGH 36359

  • 在单个级别索引上将参数ascending作为列表传递给DataFrame.sort_index()会导致错误的结果(GH 32334)

  • DataFrame.reset_index()中的错误错误地对具有Categorical dtype 的级别中的缺失值的具有MultiIndex的输入引发了ValueErrorGH 24206)

  • 在日期时间类值上使用布尔掩码进行索引时,有时会返回视图而不是副本的错误(GH 36210)

  • 当具有数值索引器的IntervalIndex列时,DataFrame.__getitem__()DataFrame.loc.__getitem__()中的错误(GH 26490)

  • 具有非唯一的MultiIndex和空列表索引器的Series.loc.__getitem__()中的错误(GH 13691)

  • 索引中的错误在具有名为"0"的级别的SeriesDataFrame上,且一个MultiIndexGH 37194)

  • 当使用无符号整数数组作为索引器时,Series.__getitem__()中的错误导致错误的结果或导致KeyError而不是分段(GH 37218)

  • Index.where()中的错误将数值错误地转换为字符串(GH 37591)

  • 当索引器是具有负步长的切片时,DataFrame.loc()中的错误返回空结果(GH 38071)

  • 当索引是object dtype 并且给定的数值标签在索引中时,Series.loc()DataFrame.loc()中的错误会引发(GH 26491)

  • DataFrame.loc()中的错误,在将loc应用于来自MultiIndex的单个级别时,返回请求的键加上缺失值(GH 27104)

  • 在使用包含 NA 值的列表样式索引器对具有CategoricalIndexSeriesDataFrame进行索引时出现错误(GH 37722)

  • DataFrame.loc.__setitem__()中的错误,扩展具有混合数据类型的空DataFrameGH 37932)

  • DataFrame.xs()中的错误,对列忽略了droplevel=FalseGH 19056)

  • DataFrame.reindex()中的错误,对于带有tolerance而不是Nonemethod="nearest"的空 DataFrame 错误地引发IndexingErrorGH 27315)

  • 在使用包含在索引的categories中但不在索引本身中的元素的列表样式索引器对具有CategoricalIndexSeriesDataFrame进行索引时出现错误,未能引发KeyErrorGH 37901)

  • 在将布尔标签插入到具有数值Index列的DataFrame中的错误,错误地转换为整数(GH 36319)

  • DataFrame.iloc()Series.iloc()中的错误,在__setitem__中对齐对象(GH 22046)

  • MultiIndex.drop()中的错误,如果部分找到标签,则不会引发错误(GH 37820)

  • 当给定 slice(None) 用于剩余级别的缺失组合时,DataFrame.loc() 未引发 KeyError 的错误(GH 19556)

  • 当给定非整数切片以从 MultiIndex 中选择值时,DataFrame.loc() 引发 TypeError 的错误(GH 25165, GH 24263)

  • 当索引是具有一个级别的 MultiIndex 时,Series.at() 返回具有一个元素而不是标量的 Series 的错误(GH 38053)

  • 当索引器与要过滤的 MultiIndex 顺序不同时,DataFrame.loc() 返回和分配元素的顺序错误(GH 31330, GH 34603)

  • DataFrame.loc()DataFrame.__getitem__() 在仅具有一个级别的 MultiIndex 列时引发 KeyError 的错误(GH 29749)

  • 在没有缺失键的情况下,Series.__getitem__()DataFrame.__getitem__() 在 [IntervalIndex 上引发空白 KeyError 的错误(GH 27365)

  • 当在具有 CategoricalIndexDataFrameSeries 上设置新标签时,如果新标签不在索引的类别中,则错误地引发 TypeErrorGH 38098)

  • Series.loc()Series.iloc() 中,当在长度相等的 object Series 中插入类似于列表的 np.arraylisttuple 时引发 ValueError (GH 37748, GH 37486)

  • Series.loc()Series.iloc() 中的错误,将 object Series 的所有值设置为列表形式的 ExtensionArray 的值,而不是将其插入 (GH 38271)

缺失

  • SeriesGroupBy.transform() 中的错误现在正确处理了 dropna=False 时的缺失值 (GH 35014)

  • Series.nunique() 中的错误,当存在 NANone 缺失值时,使用 dropna=True 返回了不正确的结果 (GH 37566)

  • Series.interpolate() 中的错误,当使用 padbackfill 方法时,kwarg limit_arealimit_direction 没有效果 (GH 31048)

MultiIndex

  • DataFrame.xs() 中的错误,当与 IndexSlice 一起使用时,引发 TypeError,消息为 "Expected label or tuple of labels" (GH 35301)

  • DataFrame.reset_index() 中的错误,当索引中存在 NaT 值时,引发 ValueError,消息为 "cannot convert float NaN to integer" (GH 36541)

  • DataFrame.combine_first() 中的错误,当与包含字符串和 NaN 值的 MultiIndex 一起使用时,引发 TypeError (GH 36562)

  • MultiIndex.drop() 存在问题,当输入不存在的键时丢弃了 NaN 值(GH 18853)

  • MultiIndex.drop() 在索引存在重复且未排序的情况下,丢弃了比预期更多的值(GH 33494)

I/O

  • read_sas() 在失败时不再存在资源泄漏问题(GH 35566)

  • DataFrame.to_csv()Series.to_csv() 存在问题,当以带有 bmode 和文件名的形式调用时,会引发 ValueError 错误(GH 35058)

  • float_precision='round_trip' 的情况下,read_csv() 存在问题,无法处理 decimalthousands 参数(GH 35365)

  • to_pickle()read_pickle() 在关闭用户提供的文件对象时出现了问题(GH 35679)

  • to_csv() 总是将 'gzip' 的压缩参数传递给 gzip.GzipFileGH 28103)

  • to_csv() 不支持对没有文件名的二进制文件对象进行 zip 压缩(GH 35058)

  • to_csv()read_csv() 对于内部转换为文件对象的路径对象不遵守 compressionencoding 参数(GH 35677, GH 26124, GH 32392)

  • DataFrame.to_pickle(), Series.to_pickle()read_pickle() 不支持对文件对象进行压缩(GH 26237, GH 29054, GH 29570)

  • LongTableBuilder.middle_separator() 中存在 bug,复制了 LaTeX 文档中表格的条目 (GH 34360)

  • engine='python'且第一行存在多个项,并且第一个元素以 BOM 开头时,在 read_csv() 中存在 bug,数据被截断(GH 36343)

  • read_gbq()中移除了 private_keyverbose,因为它们在 pandas-gbq 中不再支持(GH 34654, GH 30200)

  • 将最小的 pytables 版本升级至 3.5.1,以避免在 read_hdf() 中出现 ValueErrorGH 24839)

  • delim_whitespace=Truesep=default时,在read_table()read_csv()中存在 bug (GH 36583)

  • 当使用lines=Trueorient='records'时,DataFrame.to_json()Series.to_json()存在 bug,最后一行记录没有添加‘换行字符’(GH 36888

  • 在固定偏移时区的情况下,read_parquet()存在 bug。时区的字符串表示未被识别(GH 35997, GH 36004)

  • float_format也被指定时,DataFrame.to_html()DataFrame.to_string()DataFrame.to_latex()忽略了na_rep参数的 bug (GH 9046, GH 13828)

  • 在复数的输出渲染中存在 bug,显示了过多的尾随零(GH 36799)

  • 在使用固定的 HDF5 存储时,当导出空 DataFrame 且包含 datetime64[ns, tz] 数据类型时,HDFStore 中存在 bug,会抛出 TypeError (GH 20594)

  • 在使用固定的 HDF5 存储导出具有datetime64[ns, tz] dtypes 的 Series 时,HDFStore中的错误会丢失时区信息(GH 20594

  • engine="c"并且请求了encoding时,read_csv()在关闭用户提供的二进制文件句柄时出现错误(GH 36980

  • dropna=True时,DataFrame.to_hdf()中的错误未删除缺失的行(GH 35719

  • read_html()在将pathlib.Path参数提供给io参数时引发TypeError错误(GH 37705

  • DataFrame.to_excel()Series.to_excel()DataFrame.to_markdown(),以及Series.to_markdown()现在支持写入 fsspec URL,例如 S3 和 Google Cloud Storage(GH 33987

  • 在使用skip_blank_lines=True时,read_fwf()中的错误未跳过空行(GH 37758

  • 使用read_json()解析缺失值,将dtype=False设置为NaN而不是NoneGH 28501

  • read_fwf()在推断压缩时使用compression=None,这与其他read_*函数不一致(GH 37909

  • ExtensionDtype列的formatters参数中,DataFrame.to_html()忽略了该参数(GH 36525

  • 将最小的 xarray 版本提升至 0.12.3,以避免引用已移除的Panel类(GH 27101GH 37983

  • DataFrame.to_csv() 会重新打开文件句柄,这些句柄还实现了 os.PathLike (GH 38125)

  • 在将具有缺失值的切片 pyarrow.Table 转换为 DataFrame 时存在 Bug (GH 38525)

  • 在包含百分号的列名时,read_sql_table() 中存在 Bug,会引发 sqlalchemy.exc.OperationalError (GH 37517)

Period

  • DataFrame.replace()Series.replace() 存在 Bug,会将 Period 类型转换为对象类型 (GH 34871)

绘图

  • subplots=True 时,DataFrame.plot() 会旋转 xticklabels,即使 x 轴不是不规则时间序列 (GH 29460)

  • style 关键字中的标记字母有时会引发 ValueError 的 Bug (GH 21003)

  • DataFrame.plot.bar()Series.plot.bar() 存在 Bug,刻度位置是按值顺序分配的,而不是根据数字值或字符串的智能排序 (GH 26186, GH 11465)。此修复已在 pandas 1.2.1 中撤销,请参阅 1.2.1 版本新特性(2021 年 1 月 20 日)

  • 共享轴的双轴丢失了它们的刻度标签,这应该只发生在‘外部’共享轴的最后一行或列 (GH 33819)

  • Series.plot()DataFrame.plot() 中的 Bug 当 Series 或 DataFrame 被以 TimedeltaIndex 索引且 x 轴下限大于上限时会引发 ValueError (GH 37454)

  • subplots=False 时,DataFrameGroupBy.boxplot() 中的 Bug 会引发 KeyError (GH 16748)

  • DataFrame.plot()Series.plot() 中的 Bug 在没有传递 sharey 参数时覆盖了 matplotlib 的共享 y 轴行为(GH 37942

  • DataFrame.plot() 中的 Bug 当使用 ExtensionDtype 列时会引发 TypeError (GH 32073)

Styler

  • Styler.render() 中的 HTML 生成不正确,因为 rowspan 属性的格式错误,现在与 w3 语法匹配(GH 38234

Groupby/resample/rolling

  • DataFrameGroupBy.count()SeriesGroupBy.sum() 中的 Bug 当在多个 Categoricals 上进行分组时,对于缺失的类别返回 NaN。现在返回 0 (GH 35028)

  • DataFrameGroupBy.apply() 中的 Bug 有时会在分组轴具有重复条目时抛出错误的 ValueError (GH 16646)

  • DataFrame.resample() 中的 Bug 会在从 "D""24H" 的 DST 转换期间进行重新采样时抛出 ValueError (GH 35219)

  • 当将 DataFrame.groupby() 方法与 DataFrame.resample()DataFrame.interpolate() 方法结合使用时,会引发TypeErrorGH 35325

  • DataFrameGroupBy.apply() 中存在错误,如果在.apply之前调用了另一个 groupby 方法,则会从输出列中删除非无关的分组列(GH 34656

  • 当在DataFrameGroupBy上对列进行子集化时出现的错误(例如df.groupby('a')[['b']]))会将属性axisdropnagroup_keyslevelmutatedsortsqueeze重置为它们的默认值(GH 9959

  • DataFrameGroupBy.tshift() 中的错误未能在组的索引无法推断出频率时引发ValueErrorGH 35937

  • DataFrame.groupby() 中存在的错误,对于 anyallbfillffillshift,不总是保持列索引名称(GH 29764

  • DataFrameGroupBy.apply() 中存在错误,当 dropna=False 时,会在存在 np.nan 的组时引发错误(GH 35889

  • Rolling.sum() 方法中,当 dtype 在浮点数和整数之间混合,并且axis=1时,返回的值错误(GH 20649, GH 35596

  • Rolling.count() 方法中,当窗口使用 FixedForwardWindowIndexermin_periods=0以及窗口中仅包含缺失值时,返回了np.nanGH 35579

  • 在使用 PeriodIndex 时,Rolling 会产生错误的窗口大小(GH 34225

  • DataFrameGroupBy.ffill()DataFrameGroupBy.bfill()中存在 Bug,当 dropna=True 时,NaN 组会返回填充值而不是 NaN (GH 34725)

  • RollingGroupby.count()中存在 Bug,当指定closed参数时引发ValueError (GH 35869)

  • 在部分中心化窗口中,DataFrameGroupBy.rolling()存在 Bug,返回的值不正确 (GH 36040)

  • 在具有包含 NaN 的时间感知窗口的DataFrameGroupBy.rolling()中存在 Bug,返回的值不正确。现在引发 ValueError,因为窗口现在不是单调的 (GH 34617)

  • Rolling.__iter__()中存在 Bug,当min_periods大于window时没有引发ValueError (GH 37156)

  • 使用Rolling.var()而不是Rolling.std()可以避免在Rolling.var()仍在浮点精度范围内时,Rolling.corr()出现数值问题,而Rolling.std()则不会 (GH 31286)

  • DataFrameGroupBy.quantile()Resampler.quantile() 中的 Bug 在值为 Timedelta 类型时引发了 TypeError 错误(GH 29485

  • Rolling.median()Rolling.quantile() 中的 Bug 返回了基于非单调起始或结束点的 BaseIndexer 子类的错误值(GH 37153

  • 在对单个列进行分组时,DataFrame.groupby() 中的 Bug 在 dropna=False 时会从结果中删除 nan 组(GH 35646, GH 35542

  • 在使用 axis=1 时,DataFrameGroupBy.head()DataFrameGroupBy.tail()SeriesGroupBy.head()SeriesGroupBy.tail() 中的 Bug 会引发错误(GH 9772

  • 在使用 axis=1 和转换内核(例如“shift”)时,DataFrameGroupBy.transform() 中的 Bug 会引发错误(GH 36308

  • 使用 .agg.sum 相比,DataFrameGroupBy.resample() 中的 Bug 产生了不同的结果(GH 33548

  • 在返回与原始框架相同的轴时,DataFrameGroupBy.apply() 中的 Bug 会丢弃 nan 组的值(GH 38227

  • 在按列分组时,DataFrameGroupBy.quantile()无法处理数组样式的qGH 33795

  • 在使用datetime64tz或周期 dtype 的DataFrameGroupBy.rank()中,错误地将结果转换为这些 dtype,而不是返回float64 dtype(GH 38187

重塑

  • 在具有重复行名称、重复列名称或行列标签之间重复名称的输入上,DataFrame.crosstab()存在 bug,返回不正确的结果(GH 22529

  • 在使用aggfunc='count'aggfunc='sum'Categorical进行数据透视时,DataFrame.pivot_table()存在 bug,对于缺失的类别返回NaN。现在返回0GH 31422

  • 在某些情况下,concat()DataFrame构造函数中,输入索引名称未被保留(GH 13475

  • 在使用多列进行margins=Truenormalize=True的情况下,crosstab()存在 bug(GH 35144

  • 在空的 DataFrame.stack 上存在 bug,DataFrame.stack()会引发错误。现在返回带有空 MultiIndex 的空 Series(GH 36113

  • 在尝试取消堆叠具有单个索引级别的 Series 时,Series.unstack()会引发ValueErrorGH 36113

  • DataFrame.columns==['Name']时,使用func={'name':<FUNC>}DataFrame.agg()不正确地引发TypeErrorGH 36212

  • 当参数func为字典时,Series.transform()会给出不正确的结果或引发错误(GH 35811

  • 修复了DataFrame.pivot()在行和列都是多级索引时,未保留列的MultiIndex级别名称的错误(GH 36360)

  • 修复了DataFrame.pivot()在传递columns但未传递values时修改了index参数的错误(GH 37635)

  • 修复了DataFrame.join()返回结果MultiIndex的非确定性级别顺序的错误(GH 36910)

  • 修复了DataFrame.combine_first()中的错误,导致string类型和只包含NA的一级MultiIndex对齐错误(GH 37591)

  • 修复了在merge()中合并DatetimeIndex与空 DataFrame 时的回归错误(GH 36895)

  • 修复了DataFrame.apply()中的错误,当func返回类型为dict时,未设置返回值的索引(GH 37544)

  • 修复了DataFrame.merge()pandas.merge()how=righthow=left时返回结果中排序不一致的错误(GH 35382)

  • 修复了merge_ordered()无法处理类似列表的left_byright_by的错误(GH 35269)

  • 修复了merge_ordered()left_byright_by的长度等于leftright的行数时返回错误的连接结果的问题(GH 38166)

  • 修复了merge_ordered()left_byright_by中的元素不存在于left列或right列时未引发错误的问题(GH 38167)

  • DataFrame.drop_duplicates() 中的 bug,不会验证 ignore_index 关键字的布尔类型 dtype (GH 38274)

ExtensionArray

  • 修复了通过字典实例化将 DataFrame 列设置为标量扩展类型时,将其视为对象类型而不是扩展类型的 bug (GH 35965)

  • 修复了 astype() 在相等 dtype 和 copy=False 的情况下返回新对象的 bug (GH 28488)

  • 修复了将 NumPy ufunc 应用于返回 NoneIntegerArray 时的 bug (GH 36913)

  • 修复了 PeriodArray__init__ 签名与 DatetimeArrayTimedeltaArray 的不一致性 (GH 37289)

  • BooleanArrayCategoricalDatetimeArrayFloatingArrayIntegerArrayPeriodArrayTimedeltaArrayPandasArray 的归约现在是关键字方法 (GH 37541)

  • 修复了在包含类似 NaN 值的 ExtensionArray 上进行成员检查时错误引发 TypeError 的 bug (GH 37867)

其他

  • DataFrame.replace()Series.replace() 错误地在传递无效参数组合时引发 AssertionError 而不是 ValueError 的错误(GH 36045

  • DataFrame.replace()Series.replace() 在数值和字符串 to_replace 中存在的错误(GH 34789

  • 修复了在 Series 和 DataFrame 上调用的 Series.abs() 和 ufuncs 中的元数据传播问题(GH 28283

  • DataFrame.replace()Series.replace() 错误地将 PeriodDtype 强制转换为对象 dtype(GH 34871

  • 修复了元数据传播中的错误,在列名与元数据名重叠时错误地复制 DataFrame 列作为元数据的问题(GH 37037

  • 修复了Series.dtSeries.str 访问器,DataFrame.duplicatedDataFrame.stackDataFrame.unstackDataFrame.pivotDataFrame.appendDataFrame.diffDataFrame.applymapDataFrame.update 方法中的元数据传播问题(GH 28283GH 37381

  • 修复了使用 DataFrame.__getitem__ 选择列时的元数据传播问题(GH 28283

  • Index.intersection() 中的 Bug,当非 Index 对象失败时,未能正确设置返回的 Index 的名称(GH 38111

  • RangeIndex.intersection() 中的 Bug,在某些边缘情况下未能设置返回的 Index 的正确名称(GH 38197

  • Index.difference() 中的 Bug,在某些边缘情况下未能设置返回的 Index 的正确名称(GH 38268

  • Index.union() 中的 Bug,根据操作数是否为 Index 或其他类似列表的对象,表现不同(GH 36384

  • Index.intersection() 中的 Bug,在非匹配数值数据类型时将转换为 object 数据类型而不是最小公共数据类型(GH 38122

  • IntervalIndex.union() 中的 Bug,在空时返回了错误类型的 IndexGH 38282

  • 现在将具有 2 个或更多维度的数组传递给 Series 构造函数时,会引发更具体的 ValueError 而不是裸露的 ExceptionGH 35744

  • dir 中的 Bug,dir(obj) 不会显示定义在 pandas 对象实例上的属性(GH 37173

  • Index.drop() 中的 Bug,在索引存在重复时引发 InvalidIndexErrorGH 38051

  • RangeIndex.difference() 中的 Bug,在某些情况下返回 Int64Index,而应该返回 RangeIndexGH 38028

  • 修复了 assert_series_equal() 中的 Bug,当比较类似日期时间的数组与等效的非扩展数据类型数组时(GH 37609

  • is_bool_dtype() 中的 Bug 会在传递有效字符串如"boolean"时引发问题(GH 38386

  • 修复了逻辑运算符在 DataFrame 的列是 CategoricalIndex 且有未使用类别时引发 ValueError 的问题(GH 38367) ## 贡献者

本次发布共有 257 人贡献了补丁。名字后带“+”的人第一次贡献了补丁。

  • 21CSM +

  • AbdulMAbdi +

  • Abhiraj Hinge +

  • Abhishek Mangla +

  • Abo7atm +

  • Adam Spannbauer +

  • Albert Villanova del Moral

  • Alex Kirko

  • Alex Lim +

  • Alex Thorne +

  • Aleš Erjavec +

  • Ali McMaster

  • Amanda Dsouza +

  • Amim Knabben +

  • Andrew Wieteska

  • Anshoo Rajput +

  • Anthony Milbourne

  • Arun12121 +

  • Asish Mahapatra

  • Avinash Pancham +

  • BeanNan +

  • Ben Forbes +

  • Brendan Wilby +

  • Bruno Almeida +

  • Byron Boulton +

  • Chankey Pathak

  • Chris Barnes +

  • Chris Lynch +

  • Chris Withers

  • Christoph Deil +

  • Christopher Hadley +

  • Chuanzhu Xu

  • Coelhudo +

  • Dan Moore

  • Daniel Saxton

  • David Kwong +

  • David Li +

  • David Mrva +

  • Deepak Pandey +

  • Deepyaman Datta

  • Devin Petersohn

  • Dmitriy Perepelkin +

  • Douglas Hanley +

  • Dāgs Grīnbergs +

  • Eli Treuherz +

  • Elliot Rampono +

  • Erfan Nariman

  • Eric Goddard

  • Eric Leung +

  • Eric Wieser

  • Ethan Chen +

  • Eve +

  • Eyal Trabelsi +

  • Fabian Gebhart +

  • Fangchen Li

  • Felix Claessen +

  • Finlay Maguire +

  • Florian Roscheck +

  • Gabriel Monteiro

  • Gautham +

  • Gerard Jorgensen +

  • Gregory Livschitz

  • Hans

  • Harsh Sharma

  • Honfung Wong +

  • Igor Gotlibovych +

  • Iqrar Agalosi Nureyza

  • Irv Lustig

  • Isaac Virshup

  • Jacob Peacock

  • Jacob Stevens-Haas +

  • Jan Müller +

  • Janus

  • Jeet Parekh

  • Jeff Hernandez +

  • Jeff Reback

  • Jiaxiang

  • Joao Pedro Berno Zanutto +

  • Joel Nothman

  • Joel Whittier +

  • John Karasinski +

  • John McGuigan +

  • Johnny Pribyl +

  • Jonas Laursen +

  • Jonathan Shreckengost +

  • Joris Van den Bossche

  • Jose +

  • JoseNavy +

  • Josh Temple +

  • Jun Kudo +

  • Justin Essert

  • Justin Sexton +

  • Kaiqi Dong

  • Kamil Trocewicz +

  • Karthik Mathur

  • Kashif +

  • Kenny Huynh

  • Kevin Sheppard

  • Kumar Shivam +

  • Leonardus Chen +

  • Levi Matus +

  • Lucas Rodés-Guirao +

  • Luis Pinto +

  • Lynch +

  • Marc Garcia

  • Marco Gorelli

  • Maria-Alexandra Ilie +

  • Marian Denes

  • Mark Graham +

  • Martin Durant

  • Matt Roeschke

  • Matthew Roeschke

  • Matthias Bussonnier

  • Maxim Ivanov +

  • Mayank Chaudhary +

  • MeeseeksMachine

  • Meghana Varanasi +

  • Metehan Kutlu +

  • Micael Jarniac +

  • Micah Smith +

  • Michael Marino

  • Miroslav Šedivý

  • Mohammad Jafar Mashhadi

  • Mohammed Kashif +

  • Nagesh Kumar C +

  • Nidhi Zare +

  • Nikhil Choudhary +

  • Number42

  • Oleh Kozynets +

  • OlivierLuG

  • Pandas 开发团队

  • Paolo Lammens +

  • Paul Ganssle

  • Pax +

  • Peter Liu +

  • Philip Cerles +

  • Pranjal Bhardwaj +

  • Prayag Savsani +

  • Purushothaman Srikanth +

  • Qbiwan +

  • Rahul Chauhan +

  • Rahul Sathanapalli +

  • Rajat Bishnoi +

  • Ray Bell

  • Reshama Shaikh +

  • Richard Shadrach

  • Robert Bradshaw

  • Robert de Vries

  • Rohith295

  • S Mono +

  • S.TAKENO +

  • Sahid Velji +

  • Sam Cohen +

  • Sam Ezebunandu +

  • Sander +

  • Sarthak +

  • Sarthak Vineet Kumar +

  • Satrio H Wicaksono +

  • Scott Lasley

  • Shao Yang Hong +

  • Sharon Woo +

  • Shubham Mehra +

  • Simon Hawkins

  • Sixuan (Cherie) Wu +

  • Souris Ash +

  • Steffen Rehberg

  • Suvayu Ali

  • Sven

  • SylvainLan +

  • T. JEGHAM +

  • Terji Petersen

  • Thomas Dickson +

  • Thomas Heavey +

  • Thomas Smith

  • Tobias Pitters

  • Tom Augspurger

  • Tomasz Sakrejda +

  • Torsten Wörtwein +

  • Ty Mick +

  • UrielMaD +

  • Uwe L. Korn

  • Vikramaditya Gaonkar +

  • VirosaLi +

  • W.R +

  • Warren White +

  • Wesley Boelrijk +

  • William Ayd

  • Yanxian Lin +

  • Yassir Karroum +

  • Yong Kai Yi +

  • Yuanhao Geng +

  • Yury Mikhaylov +

  • Yutaro Ikeda

  • Yuya Takashina +

  • Zach Brookler +

  • Zak Kohler +

  • ZhihuiChen0903 +

  • abmyii

  • alexhtn +

  • asharma13524 +

  • attack68

  • beanan +

  • chinhwee

  • cleconte987

  • danchev +

  • ebardie +

  • edwardkong

  • elliot rampono +

  • estasney +

  • gabicca

  • geetha-rangaswamaiah +

  • gfyoung

  • guru kiran

  • hardikpnsp +

  • icanhazcodeplz +

  • ivanovmg +

  • jbrockmendel

  • jeschwar

  • jnecus

  • joooeey +

  • junk +

  • krajatcl +

  • lacrosse91 +

  • leo +

  • lpkirwin +

  • lrjball

  • lucasrodes +

  • ma3da +

  • mavismonica +

  • mlondschien +

  • mzeitlin11 +

  • nguevara +

  • nrebena

  • parkdj1 +

  • partev

  • patrick

  • realead

  • rxxg +

  • samilAyoub +

  • sanderland

  • shawnbrown

  • sm1899 +

  • smartvinnetou

  • ssortman +

  • steveya +

  • taytzehao +

  • tiagohonorato +

  • timhunderwood

  • tkmz-n +

  • tnwei +

  • tpanza +

  • vineethraj510 +

  • vmdhhh +

  • xinrong-databricks +

  • yonas kassa +

  • yonashub +

  • Ádám Lippai +

Enhancements

可选禁止重复标签

SeriesDataFrame现在可以通过设置allows_duplicate_labels=False标志来创建,以控制索引或列是否可以包含重复标签(GH 28394)。这可以用于防止意外引入重复标签,这可能会影响下游操作。

默认情况下,允许重复。

In [1]: pd.Series([1, 2], index=['a', 'a'])
Out[1]:
a    1
a    2
Length: 2, dtype: int64

In [2]: pd.Series([1, 2], index=['a', 'a']).set_flags(allows_duplicate_labels=False)
...
DuplicateLabelError: Index has duplicates.
 positions
label
a        [0, 1] 

pandas 将通过许多操作传播allows_duplicate_labels属性。

In [3]: a = (
 ...:    pd.Series([1, 2], index=['a', 'b'])
 ...:      .set_flags(allows_duplicate_labels=False)
 ...: )

In [4]: a
Out[4]:
a    1
b    2
Length: 2, dtype: int64

# An operation introducing duplicates
In [5]: a.reindex(['a', 'b', 'a'])
...
DuplicateLabelError: Index has duplicates.
 positions
label
a        [0, 2]

[1 rows x 1 columns] 

警告

这是一个试验性功能。目前,许多方法都无法传播allows_duplicate_labels值。未来版本预计每个接受或返回一个或多个 DataFrame 或 Series 对象的方法都将传播allows_duplicate_labels

查看重复标签以获取更多信息。

新的DataFrame.flags属性中存储了allows_duplicate_labels标志。这个属性存储了适用于pandas 对象的全局属性。这与DataFrame.attrs不同,后者存储适用于数据集的信息。

将参数传递给 fsspec 后端

许多读写函数已经获得了storage_options可选参数,用于将参数字典传递给存储后端。这允许,例如,传递凭据给 S3 和 GCS 存储。关于可以传递哪些参数到哪些后端的详细信息可以在各个存储后端的文档中找到(从fsspec 文档中详细说明和链接到外部实现)。请参阅读取/写入远程文件部分。

GH 35655 添加了对于读取 Excel 文件的 fsspec 支持(包括storage_options)。

to_csv 支持二进制文件句柄

to_csv() 支持二进制模式的文件句柄(GH 19827GH 35058)以及encodingGH 13068GH 23854)和compressionGH 22555)。如果 pandas 不能自动检测文件句柄是以二进制还是文本模式打开的,则需要提供mode="wb"

例如:

In [1]: import io

In [2]: data = pd.DataFrame([0, 1, 2])

In [3]: buffer = io.BytesIO()

In [4]: data.to_csv(buffer, encoding="utf-8", compression="gzip") 

to_latex 中的简短说明和表位置的支持

DataFrame.to_latex() 现在允许指定浮动表位置(GH 35281)和简短说明(GH 36267)。

添加了关键字position以设置位置。

In [5]: data = pd.DataFrame({'a': [1, 2], 'b': [3, 4]})

In [6]: table = data.to_latex(position='ht')

In [7]: print(table)
\begin{table}[ht]
\begin{tabular}{lrr}
\toprule
 & a & b \\
\midrule
0 & 1 & 3 \\
1 & 2 & 4 \\
\bottomrule
\end{tabular}
\end{table} 

关键字caption的使用已经扩展。除了接受单个字符串作为参数外,还可以选择提供元组(full_caption, short_caption)以添加简短说明宏。

In [8]: data = pd.DataFrame({'a': [1, 2], 'b': [3, 4]})

In [9]: table = data.to_latex(caption=('the full long caption', 'short caption'))

In [10]: print(table)
\begin{table}
\caption[short caption]{the full long caption}
\begin{tabular}{lrr}
\toprule
 & a & b \\
\midrule
0 & 1 & 3 \\
1 & 2 & 4 \\
\bottomrule
\end{tabular}
\end{table} 

更改了 read_csvread_table 的默认浮点精度

对于 C 解析引擎,方法 read_csv()read_table() 以前默认使用一个解析器,该解析器可能会在精度的最后一位上略微不正确地读取浮点数。选项 floating_precision="high" 一直可用于避免此问题。从此版本开始,默认值现在是使用更准确的解析器,使 floating_precision=None 对应于高精度解析器,新选项 floating_precision="legacy" 用于使用旧解析器。默认情况下改为使用更高精度的解析器不应对性能产生影响。(GH 17154) ### 浮点数据的实验性可空数据类型

我们新增了Float32Dtype / Float64DtypeFloatingArray。这些是专门用于浮点数据的扩展数据类型,可以容纳pd.NA缺失值指示器 (GH 32265, GH 34307)。

尽管默认的浮点数据类型已经支持使用 np.nan 来表示缺失值,但这些新的数据类型使用 pd.NA(以及其相应的行为)作为缺失值指示器,与已经存在的可空整数和布尔数据类型保持一致。

np.nanpd.NA 行为不同的一个示例是比较操作:

# the default NumPy float64 dtype
In [11]: s1 = pd.Series([1.5, None])

In [12]: s1
Out[12]: 
0    1.5
1    NaN
dtype: float64

In [13]: s1 > 1
Out[13]: 
0     True
1    False
dtype: bool 
# the new nullable float64 dtype
In [14]: s2 = pd.Series([1.5, None], dtype="Float64")

In [15]: s2
Out[15]: 
0     1.5
1    <NA>
dtype: Float64

In [16]: s2 > 1
Out[16]: 
0    True
1    <NA>
dtype: boolean 

更多关于使用 pd.NA 缺失值指示器时的行为的详细信息,请参阅 NA 语义 文档部分。

如上所示,可以使用 “Float64” 或 “Float32” 字符串指定数据类型(大写以区别于默认的 “float64” 数据类型)。另外,您也可以使用数据类型对象:

In [17]: pd.Series([1.5, None], dtype=pd.Float32Dtype())
Out[17]: 
0     1.5
1    <NA>
dtype: Float32 

对于产生浮点结果的现有整数或布尔可空数据类型的操作,现在也将使用可空浮点数据类型 (GH 38178)。

警告

实验性的:新的浮点数据类型目前还处于实验阶段,它们的行为或 API 可能会在不经过警告的情况下发生变化。特别是关于 NaN(与 NA 缺失值不同)的行为可能会发生变化。### 聚合时保留索引/列名

当使用concat()函数或DataFrame构造函数进行聚合时,pandas 现在会尽可能保留索引和列名称(GH 35847)。如果所有输入共享一个公共名称,则将该名称分配给结果。当输入名称不完全一致时,结果将无名称。下面是一个保留索引名称的示例:

In [18]: idx = pd.Index(range(5), name='abc')

In [19]: ser = pd.Series(range(5, 10), index=idx)

In [20]: pd.concat({'x': ser[1:], 'y': ser[:-1]}, axis=1)
Out[20]: 
 x    y
abc 
1    6.0  6.0
2    7.0  7.0
3    8.0  8.0
4    9.0  NaN
0    NaN  5.0 

对于MultiIndex也是如此,但逻辑是分别按级别应用的。### GroupBy 直接支持 EWM 操作

DataFrameGroupBy现在直接支持指数加权窗口操作(GH 16037

In [21]: df = pd.DataFrame({'A': ['a', 'b', 'a', 'b'], 'B': range(4)})

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

In [23]: df.groupby('A').ewm(com=1.0).mean()
Out[23]: 
 B
A 
a 0  0.000000
 2  1.333333
b 1  1.000000
 3  2.333333 

此外,mean函数支持通过Numba执行,可使用engineengine_kwargs参数。必须安装 Numba 作为可选依赖项才能使用此功能。### 其他增强功能

  • TimestampDatetimeIndexPeriodPeriodIndex上添加了day_of_week(兼容别名dayofweek)属性(GH 9605

  • TimestampDatetimeIndexPeriodPeriodIndex上添加了day_of_year(兼容别名dayofyear)属性(GH 9605

  • 添加了set_flags()函数,用于在 Series 或 DataFrame 上设置表范围的标志(GH 28394

  • DataFrame.applymap()函数现在支持na_action参数(GH 23803

  • 具有对象 dtype 的Index支持除法和乘法(GH 34160

  • io.sql.get_schema() 现在支持 schema 关键字参数,该参数将在创建表语句中添加一个模式(GH 28486

  • DataFrame.explode()Series.explode() 现在支持集合的展开(GH 35614

  • DataFrame.hist() 现在支持时间序列(日期时间)数据(GH 32590

  • Styler.set_table_styles() 现在允许直接为行和列设置样式,并且可以链式调用(GH 35607

  • Styler 现在允许将直接的 CSS 类名添加到单个数据单元格中(GH 36159

  • Rolling.mean()Rolling.sum() 使用 Kahan 总和法计算平均值以避免数值问题(GH 10319GH 11645GH 13254GH 32761GH 36031

  • DatetimeIndex.searchsorted()TimedeltaIndex.searchsorted()PeriodIndex.searchsorted()Series.searchsorted() 在具有类似日期时间的数据类型时,现在会尝试将字符串参数(类似列表和标量)转换为相匹配的日期时间类型(GH 36346

  • 新增方法 IntegerArray.prod()IntegerArray.min()IntegerArray.max()GH 33790

  • DataFrame 调用 NumPy 通用函数时,现在会在可能的情况下保留扩展类型(GH 23743

  • 调用二进制输入的 NumPy ufunc 在多个 DataFrame 对象上现在会对齐,与 Series 上的二进制操作和 ufuncs 的行为匹配(GH 23743)。这一变更已在 pandas 1.2.1 中被撤销,不对齐 DataFrames 的行为已被弃用,详见 1.2.1 发行说明。

  • 在可能的情况下,RangeIndex.difference()RangeIndex.symmetric_difference() 将返回 RangeIndex 而不是 Int64Index (GH 36564)

  • DataFrame.to_parquet() 现在支持 parquet 格式中列的 MultiIndex (GH 34777)

  • read_parquet() 增加了 use_nullable_dtypes=True 选项,以在可能的情况下使用 pd.NA 作为缺失值指示符的可空数据类型,用于生成的 DataFrame(默认为 False,仅适用于 engine="pyarrow") (GH 31242)

  • 添加了 Rolling.sem()Expanding.sem() 来计算均值的标准误差 (GH 26476)

  • Rolling.var()Rolling.std() 使用 Kahan 求和和 Welford 方法来避免数值问题 (GH 37051)

  • DataFrame.corr()DataFrame.cov() 使用 Welford 方法来避免数值问题 (GH 37448)

  • DataFrame.plot() 现在可以识别 scatterhexbin 类型图的 xlabelylabel 参数 (GH 37001)

  • DataFrame 现在支持 divmod 操作 (GH 37165)

  • DataFrame.to_parquet()现在在不传递path参数时返回一个bytes对象(GH 37105)

  • Rolling现在支持了固定窗口的closed参数(GH 34315)

  • 具有datetime64datetime64tz dtype 的DatetimeIndexSeries现在支持stdGH 37436)

  • Window现在支持在win_type中使用所有 Scipy 窗口类型,并支持灵活的关键字参数(GH 34556)

  • testing.assert_index_equal()现在有了一个check_order参数,允许以无序方式检查索引(GH 37478)

  • read_csv()支持对压缩文件进行内存映射(GH 37621)

  • DataFrame.groupby()DataFrame.resample()函数的minmaxfirstlast添加对min_count关键字的支持(GH 37821GH 37768)

  • 在给出无效的合并列定义时,改进了对DataFrame.merge()的错误报告 (GH 16228)

  • 通过实现 Kahan 求和改进了对Rolling.skew()Rolling.kurt()Expanding.skew()Expanding.kurt()的数值稳定性(GH 6929)

  • 对于使用axis=1DataFrameGroupBy,改进了对列子集的错误报告(GH 37725)

  • DataFrame.merge()DataFrame.join()实现了cross方法(GH 5401

  • 当使用chunksize/iterator调用read_csv()read_sas()read_json()时,它们可以在with语句中使用,因为它们返回上下文管理器(GH 38225

  • 增加了用于样式化 Excel 导出的已命名颜色列表,启用了所有 CSS4 颜色(GH 38247) ### 可选择不允许重复标签

使用allows_duplicate_labels=False标志,现在可以创建SeriesDataFrame,以控制索引或列是否可以包含重复标签(GH 28394)。这可用于防止意外引入重复标签,这可能会影响到下游操作。

默认情况下,允许重复继续存在。

In [1]: pd.Series([1, 2], index=['a', 'a'])
Out[1]:
a    1
a    2
Length: 2, dtype: int64

In [2]: pd.Series([1, 2], index=['a', 'a']).set_flags(allows_duplicate_labels=False)
...
DuplicateLabelError: Index has duplicates.
 positions
label
a        [0, 1] 

pandas 将通过许多操作传播allows_duplicate_labels属性。

In [3]: a = (
 ...:    pd.Series([1, 2], index=['a', 'b'])
 ...:      .set_flags(allows_duplicate_labels=False)
 ...: )

In [4]: a
Out[4]:
a    1
b    2
Length: 2, dtype: int64

# An operation introducing duplicates
In [5]: a.reindex(['a', 'b', 'a'])
...
DuplicateLabelError: Index has duplicates.
 positions
label
a        [0, 2]

[1 rows x 1 columns] 

警告

这是一个试验性的功能。当前,许多方法未能传播allows_duplicate_labels值。在未来版本中,预计每个接受或返回一个或多个 DataFrame 或 Series 对象的方法都将传播allows_duplicate_labels

更多信息请参阅 Duplicate Labels。

allows_duplicate_labels标志存储在新的DataFrame.flags属性中。这个属性存储适用于pandas 对象的全局属性。这与DataFrame.attrs不同,后者存储适用于数据集的信息。

将参数传递给 fsspec 后端

许多读取/写入函数已经获取了 storage_options 可选参数,用于将参数字典传递给存储后端。这允许,例如,将凭据传递给 S3 和 GCS 存储。可以在各个存储后端的文档中找到可以传递给哪些后端的参数的详细信息(从 fsspec 文档详细说明了 内置实现 并链接到 外部实现)。请参阅章节 读取/写入远程文件。

GH 35655 添加了对读取 Excel 文件的 fsspec 支持(包括 storage_options)。

支持在 to_csv 中使用二进制文件句柄

to_csv() 支持以二进制模式打开的文件句柄(GH 19827GH 35058)与 encodingGH 13068GH 23854)以及 compressionGH 22555)。如果 pandas 无法自动检测文件句柄是以二进制还是文本模式打开的,则需要提供 mode="wb"

例如:

In [1]: import io

In [2]: data = pd.DataFrame([0, 1, 2])

In [3]: buffer = io.BytesIO()

In [4]: data.to_csv(buffer, encoding="utf-8", compression="gzip") 

to_latex 中支持短标题和表位置

DataFrame.to_latex() 现在允许指定浮动表位置(GH 35281)和短标题(GH 36267)。

添加了关键字 position 以设置位置。

In [5]: data = pd.DataFrame({'a': [1, 2], 'b': [3, 4]})

In [6]: table = data.to_latex(position='ht')

In [7]: print(table)
\begin{table}[ht]
\begin{tabular}{lrr}
\toprule
 & a & b \\
\midrule
0 & 1 & 3 \\
1 & 2 & 4 \\
\bottomrule
\end{tabular}
\end{table} 

关键字 caption 的用法已扩展。除了接受单个字符串作为参数外,还可以选择提供一个元组 (full_caption, short_caption) 来添加一个简短标题宏。

In [8]: data = pd.DataFrame({'a': [1, 2], 'b': [3, 4]})

In [9]: table = data.to_latex(caption=('the full long caption', 'short caption'))

In [10]: print(table)
\begin{table}
\caption[short caption]{the full long caption}
\begin{tabular}{lrr}
\toprule
 & a & b \\
\midrule
0 & 1 & 3 \\
1 & 2 & 4 \\
\bottomrule
\end{tabular}
\end{table} 

更改 read_csvread_table 的默认浮点精度

对于 C 解析引擎,方法 read_csv()read_table() 以前默认使用一个解析器,该解析器在浮点数的精度上略微不正确,与最后一位有关。选项 floating_precision="high" 一直可用以避免此问题。从此版本开始,默认值现在是使用更准确的解析器,使 floating_precision=None 对应于高精度解析器,并使用新选项 floating_precision="legacy" 来使用旧解析器。默认情况下更改为使用更高精度解析器不应影响性能。(GH 17154

实验性的浮点数据的可空数据类型

我们已添加了 Float32Dtype / Float64DtypeFloatingArray。这些是专用于浮点数据的扩展数据类型,可以保存 pd.NA 缺失值指示符(GH 32265GH 34307)。

虽然默认的浮点数据类型已经使用 np.nan 支持缺失值,但这些新的数据类型使用 pd.NA(及其相应的行为)作为缺失值指示符,与已经存在的可空整数和布尔数据类型保持一致。

一个示例是 np.nanpd.NA 的行为不同的情况是比较操作:

# the default NumPy float64 dtype
In [11]: s1 = pd.Series([1.5, None])

In [12]: s1
Out[12]: 
0    1.5
1    NaN
dtype: float64

In [13]: s1 > 1
Out[13]: 
0     True
1    False
dtype: bool 
# the new nullable float64 dtype
In [14]: s2 = pd.Series([1.5, None], dtype="Float64")

In [15]: s2
Out[15]: 
0     1.5
1    <NA>
dtype: Float64

In [16]: s2 > 1
Out[16]: 
0    True
1    <NA>
dtype: boolean 

有关使用 pd.NA 缺失值指示符时的行为的更多详细信息,请参见 NA 语义文档部分。

如上所示,dtype 可以使用“Float64”或“Float32”字符串指定(大写以区别于默认的“float64”数据类型)。或者,您也可以使用 dtype 对象:

In [17]: pd.Series([1.5, None], dtype=pd.Float32Dtype())
Out[17]: 
0     1.5
1    <NA>
dtype: Float32 

使用现有的整数或布尔可空数据类型进行给出浮点结果的操作现在也将使用可空浮点数据类型(GH 38178)。

警告

实验性:新的浮点数据类型目前处于实验阶段,其行为或 API 可能会在没有警告的情况下发生变化。特别是关于 NaN(与 NA 缺失值不同)的行为可能会发生变化。

聚合时保留索引/列名称

使用 concat()DataFrame 构造函数进行聚合时,pandas 现在将尽可能保留索引和列名称(GH 35847)。在所有输入共享通用名称的情况下,该名称将分配给结果。当输入名称不全一致时,结果将无名称。以下是保留索引名称的示例:

In [18]: idx = pd.Index(range(5), name='abc')

In [19]: ser = pd.Series(range(5, 10), index=idx)

In [20]: pd.concat({'x': ser[1:], 'y': ser[:-1]}, axis=1)
Out[20]: 
 x    y
abc 
1    6.0  6.0
2    7.0  7.0
3    8.0  8.0
4    9.0  NaN
0    NaN  5.0 

MultiIndex 也是如此,但逻辑是分别应用在逐级的基础上。

GroupBy 直接支持 EWM 操作

DataFrameGroupBy 现在直接支持指数加权窗口操作(GH 16037)。

In [21]: df = pd.DataFrame({'A': ['a', 'b', 'a', 'b'], 'B': range(4)})

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

In [23]: df.groupby('A').ewm(com=1.0).mean()
Out[23]: 
 B
A 
a 0  0.000000
 2  1.333333
b 1  1.000000
 3  2.333333 

此外,mean现在支持通过Numba执行,使用engineengine_kwargs参数。必须安装 Numba 作为可选依赖项才能使用此功能。

其他增强

  • TimestampDatetimeIndexPeriodPeriodIndex添加了day_of_week(兼容别名dayofweek)属性(GH 9605)

  • TimestampDatetimeIndexPeriodPeriodIndex添加了day_of_year(兼容别名dayofyear)属性(GH 9605)

  • 添加了set_flags()用于在 Series 或 DataFrame 上设置表范围标志的功能(GH 28394)

  • DataFrame.applymap()现在支持na_actionGH 23803)

  • 对象 dtype 的Index支持除法和乘法(GH 34160)

  • io.sql.get_schema()现在支持schema关键字参数,该参数将在创建表语句中添加模式(GH 28486)

  • DataFrame.explode()Series.explode()现在支持集合的爆炸操作(GH 35614)

  • DataFrame.hist()现在支持时间序列(日期时间)数据(GH 32590)

  • Styler.set_table_styles()现在允许直接对行和列进行样式设置,并且可以链式调用(GH 35607)

  • Styler 现在允许直接向单个数据单元格添加 CSS 类名 (GH 36159)。

  • Rolling.mean()Rolling.sum() 使用 Kahan 求和来计算均值以避免数值问题 (GH 10319, GH 11645, GH 13254, GH 32761, GH 36031)。

  • DatetimeIndex.searchsorted()TimedeltaIndex.searchsorted()PeriodIndex.searchsorted()Series.searchsorted() 对于 datetime 类型的 dtype 现在将尝试将字符串参数(类似列表和标量)转换为匹配的 datetime 类型 (GH 36346)。

  • 添加了方法 IntegerArray.prod()IntegerArray.min()IntegerArray.max() (GH 33790)。

  • DataFrame 上调用 NumPy ufunc 时,如果可能,会保留扩展类型 (GH 23743)。

  • 调用二进制输入的 NumPy ufunc 在多个 DataFrame 对象上现在进行了对齐,与对 Series 进行的二元操作和 ufuncs 的行为匹配 (GH 23743)。这个改变已经在 pandas 1.2.1 中被撤销,并且不对齐 DataFrames 的行为已被弃用,请参阅 1.2.1 发布说明。

  • 在可能的情况下,RangeIndex.difference()RangeIndex.symmetric_difference() 将返回 RangeIndex 而不是 Int64Index (GH 36564)。

  • DataFrame.to_parquet() 现在支持 parquet 格式的列中的 MultiIndex (GH 34777)。

  • read_parquet()新增了use_nullable_dtypes=True选项,用于在结果 DataFrame 中尽可能使用pd.NA作为缺失值指示符的可空数据类型(默认为False,仅适用于engine="pyarrow")(GH 31242

  • 新增了Rolling.sem()Expanding.sem()来计算均值的标准误差(GH 26476

  • Rolling.var()Rolling.std()使用 Kahan summation 和 Welford's Method 来避免数值问题(GH 37051

  • DataFrame.corr()DataFrame.cov()使用 Welford's Method 来避免数值问题(GH 37448

  • DataFrame.plot()现在对scatterhexbin类型的图表识别xlabelylabel参数(GH 37001

  • DataFrame现在支持divmod操作(GH 37165

  • 当没有传递path参数时,DataFrame.to_parquet()现在返回一个bytes对象(GH 37105

  • Rolling现在支持固定窗口的closed参数(GH 34315

  • 具有datetime64datetime64tz数据类型的DatetimeIndexSeries现在支持stdGH 37436

  • Window现在支持在win_type中的所有 Scipy 窗口类型,并支持灵活的关键字参数(GH 34556

  • testing.assert_index_equal()现在具有check_order参数,允许按照无序方式检查索引(GH 37478

  • read_csv() 支持压缩文件的内存映射(GH 37621

  • DataFrame.groupby()DataFrame.resample()添加了对于函数minmaxfirstlastmin_count关键字支持(GH 37821GH 37768

  • 改进了DataFrame.merge()对于给定无效的合并列定义的错误报告(GH 16228

  • 通过实现 Kahan 求和改进了Rolling.skew()Rolling.kurt()Expanding.skew()Expanding.kurt()的数值稳定性(GH 6929

  • 改进了对于使用axis=1DataFrameGroupBy进行列子集选取的错误报告(GH 37725

  • DataFrame.merge()DataFrame.join()实现了cross方法(GH 5401

  • 当使用chunksize/iterator调用read_csv()read_sas()read_json()时,它们可以在with语句中使用,因为它们返回上下文管理器(GH 38225

  • 扩展了可用于 Excel 导出样式的命名颜色列表,使所有 CSS4 颜色都可用(GH 38247

显著的错误修复

这些是可能具有显著行为变化的错误修复。

DataFrame 减少的一致性

DataFrame.any()DataFrame.all() 现在使用 bool_only=True,将基于列来决定是否排除对象数据类型列,而不是检查是否 所有 对象数据类型列都可以被视为布尔型。

这可以防止应用于列子集的缩减可能导致更大的 Series 结果的病态行为。参见(GH 37799)。

In [24]: df = pd.DataFrame({"A": ["foo", "bar"], "B": [True, False]}, dtype=object)

In [25]: df["C"] = pd.Series([True, True]) 

先前的行为

In [5]: df.all(bool_only=True)
Out[5]:
C    True
dtype: bool

In [6]: df[["B", "C"]].all(bool_only=True)
Out[6]:
B    False
C    True
dtype: bool 

新行为

In [26]: In [5]: df.all(bool_only=True)
Out[26]: 
C    True
dtype: bool

In [27]: In [6]: df[["B", "C"]].all(bool_only=True)
Out[27]: 
C    True
dtype: bool 

其他使用numeric_only=None的 DataFrame 缩减也将避免这种病态行为(GH 37827):

In [28]: df = pd.DataFrame({"A": [0, 1, 2], "B": ["a", "b", "c"]}, dtype=object) 

先前的行为

In [3]: df.mean()
Out[3]: Series([], dtype: float64)

In [4]: df[["A"]].mean()
Out[4]:
A    1.0
dtype: float64 

新行为

In [3]: df.mean()
Out[3]:
A    1.0
dtype: float64

In [4]: df[["A"]].mean()
Out[4]:
A    1.0
dtype: float64 

此外,使用numeric_only=None进行 DataFrame 缩减将与其 Series 对应项保持一致。特别是,对于 Series 方法引发TypeError的缩减,DataFrame 缩减现在将考虑该列为非数值,而不是转换为可能具有不同语义的 NumPy 数组(GH 36076GH 28949GH 21020)。

In [29]: ser = pd.Series([0, 1], dtype="category", name="A")

In [30]: df = ser.to_frame() 

先前的行为

In [5]: df.any()
Out[5]:
A    True
dtype: bool 

新行为

In [5]: df.any()
Out[5]: Series([], dtype: bool) 

Python 的最低版本提升

pandas 1.2.0 支持 Python 3.7.1 及更高版本(GH 35214)。### 依赖项的最低版本提升

一些依赖关系的最低支持版本已更新(GH 35214)。如果已安装,现在我们要求:

最低版本 必需的 更改
numpy 1.16.5 X X
pytz 2017.3 X X
python-dateutil 2.7.3 X
bottleneck 1.2.1
numexpr 2.6.8 X
pytest (dev) 5.0.1 X
mypy (dev) 0.782 X

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

最低版本 更改
beautifulsoup4 4.6.0
fastparquet 0.3.2
fsspec 0.7.4
gcsfs 0.6.0
lxml 4.3.0 X
matplotlib 2.2.3 X
numba 0.46.0
openpyxl 2.6.0 X
pyarrow 0.15.0 X
pymysql 0.7.11 X
pytables 3.5.1 X
s3fs 0.4.0
scipy 1.2.0
sqlalchemy 1.2.8 X
xarray 0.12.3 X
xlrd 1.2.0 X
xlsxwriter 1.0.2 X
xlwt 1.3.0 X
pandas-gbq 0.12.0

查看 Dependencies 和 Optional dependencies 以获取更多信息。### 其他 API 更改

  • 对于日期时间类Index子类,现在对Series.sort_values()Index.sort_values()进行降序排序是稳定的。这将影响在多列上对 DataFrame 进行排序、使用产生重复项的键函数进行排序或在使用Index.sort_values()时请求排序索引时的排序顺序。在使用Series.value_counts()时,缺失值的计数不再必然位于重复计数列表的最后。相反,其位置对应于原始 Series 中的位置。在对日期时间类Index子类使用Index.sort_values()时,NaT 会忽略na_position参数并被排序到开头。现在它们尊重na_position,默认值为last,与其他Index子类相同 (GH 35992)

  • 将无效的fill_value传递给Categorical.take()DatetimeArray.take()TimedeltaArray.take()PeriodArray.take()现在会引发TypeError而不是ValueError (GH 37733)

  • 将无效的fill_value传递给带有CategoricalDtypeSeries.shift()现在会引发TypeError而不是ValueError (GH 37733)

  • 将无效值传递给IntervalIndex.insert()CategoricalIndex.insert()现在会引发TypeError而不是ValueError (GH 37733)

  • 尝试使用具有无效fill_valueCategoricalIndex重新索引 Series 现在会引发TypeError而不是ValueError (GH 37733)

  • CategoricalIndex.append()与包含非类别值的索引现在会转换而不是引发TypeError (GH 38098)

DataFrame 缩减的一致性

DataFrame.any()DataFrame.all()bool_only=True现在将基于逐列的方式确定是否排除对象 dtype 列,而不是检查是否 所有 对象 dtype 列都可以视为布尔值。

这样可以防止在对列子集应用缩减时出现更大的 Series 结果的病态行为。参见(GH 37799)。

In [24]: df = pd.DataFrame({"A": ["foo", "bar"], "B": [True, False]}, dtype=object)

In [25]: df["C"] = pd.Series([True, True]) 

旧行为

In [5]: df.all(bool_only=True)
Out[5]:
C    True
dtype: bool

In [6]: df[["B", "C"]].all(bool_only=True)
Out[6]:
B    False
C    True
dtype: bool 

新行为

In [26]: In [5]: df.all(bool_only=True)
Out[26]: 
C    True
dtype: bool

In [27]: In [6]: df[["B", "C"]].all(bool_only=True)
Out[27]: 
C    True
dtype: bool 

其他使用numeric_only=None的 DataFrame 缩减也将避免这种病态行为(GH 37827):

In [28]: df = pd.DataFrame({"A": [0, 1, 2], "B": ["a", "b", "c"]}, dtype=object) 

旧行为

In [3]: df.mean()
Out[3]: Series([], dtype: float64)

In [4]: df[["A"]].mean()
Out[4]:
A    1.0
dtype: float64 

新行为

In [3]: df.mean()
Out[3]:
A    1.0
dtype: float64

In [4]: df[["A"]].mean()
Out[4]:
A    1.0
dtype: float64 

此外,使用numeric_only=None进行的 DataFrame 缩减现在将与其 Series 对应物保持一致。特别是,对于 Series 方法引发TypeError的缩减,DataFrame 缩减现在将考虑该列为非数字,而不是转换为可能具有不同语义的 NumPy 数组(GH 36076GH 28949GH 21020)。

In [29]: ser = pd.Series([0, 1], dtype="category", name="A")

In [30]: df = ser.to_frame() 

旧行为

In [5]: df.any()
Out[5]:
A    True
dtype: bool 

新行为

In [5]: df.any()
Out[5]: Series([], dtype: bool) 

Python 的最低版本要求增加了

pandas 1.2.0 支持 Python 3.7.1 及更高版本(GH 35214)。

依赖项的最低版本要求增加了

一些依赖项的最低受支持版本已更新(GH 35214)。如果已安装,我们现在要求:

最低版本 要求 变更
numpy 1.16.5 X X
pytz 2017.3 X X
python-dateutil 2.7.3 X
bottleneck 1.2.1
numexpr 2.6.8 X
pytest (dev) 5.0.1 X
mypy (dev) 0.782 X

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

最低版本 变更
beautifulsoup4 4.6.0
fastparquet 0.3.2
fsspec 0.7.4
gcsfs 0.6.0
lxml 4.3.0 X
matplotlib 2.2.3 X
numba 0.46.0
openpyxl 2.6.0 X
pyarrow 0.15.0 X
pymysql 0.7.11 X
pytables 3.5.1 X
s3fs 0.4.0
scipy 1.2.0
sqlalchemy 1.2.8 X
xarray 0.12.3 X
xlrd 1.2.0 X
xlsxwriter 1.0.2 X
xlwt 1.3.0 X
pandas-gbq 0.12.0

查看依赖项和可选依赖项以获取更多信息。

其他 API 变更

  • 对于日期时间类Index子类,降序排序现在对于Series.sort_values()Index.sort_values()是稳定的。当在多列上对 DataFrame 进行排序、使用产生重复项的键函数进行排序,或在使用Index.sort_values()时请求排序索引时,这将影响排序顺序。在使用Series.value_counts()时,缺失值的计数不再必然出现在重复计数列表的最后。相反,它的位置对应于原始 Series 中的位置。在日期时间类Index子类上使用Index.sort_values()时,NaT(不是时间)会忽略na_position参数并被排序到开头。现在它们尊重na_position,默认值为last,与其他Index子类相同(GH 35992

  • 将无效的fill_value传递给Categorical.take()DatetimeArray.take()TimedeltaArray.take()PeriodArray.take()现在引发TypeError而不是ValueErrorGH 37733

  • 将无效的fill_value传递给Series.shift()CategoricalDtype一起现在引发TypeError而不是ValueErrorGH 37733

  • 将无效值传递给IntervalIndex.insert()CategoricalIndex.insert()现在引发TypeError而不是ValueErrorGH 37733

  • 尝试重新索引一个带有无效fill_valueCategoricalIndex现在引发TypeError而不是ValueErrorGH 37733

  • CategoricalIndex.append()与包含非类别值的索引现在会进行转换而不是引发TypeErrorGH 38098

废弃功能

  • MultiIndex.set_codes()MultiIndex.set_levels()中的弃用参数inplaceGH 35626

  • 所有Index子类的方法copy()的弃用参数dtype。使用astype()方法来改变 dtype(GH 35853

  • MultiIndex.copy()中的参数levelscodes已被弃用。请改用set_levels()set_codes()方法代替(GH 36685

  • 来自pandas.io.date_converters的日期解析函数parse_date_time()parse_date_fields()parse_all_fields()generic_parser()已被弃用,并将在将来的版本中移除;请使用to_datetime()代替(GH 35741

  • DataFrame.lookup()已被弃用,并将在将来的版本中移除,请改用DataFrame.melt()DataFrame.loc()代替(GH 35224

  • 方法Index.to_native_types()已被弃用。请改用.astype(str)代替(GH 28867

  • 用单个类似日期时间的字符串作为df[string]的索引已被弃用(由于索引行或选择列的歧义性),请使用df.loc[string]代替(GH 36179

  • 弃用Index.is_all_dates()GH 27744

  • Series.str.replace()regex的默认值将在将来的版本中从True更改为False。此外,当设置regex=True时,单个字符正则表达式将被视为字面字符串(GH 24804

  • 在比较DataFrameSeries之间的自动对齐已被弃用,在执行frame == ser之前执行frame, ser = frame.align(ser, axis=1, copy=False)GH 28759

  • Rolling.count()min_periods=None将在将来的版本中默认为窗口的大小(GH 31302

  • 使用“outer” ufuncs 在 DataFrames 上返回 4d ndarray 现已被弃用。首先转换为 ndarray(GH 23743

  • 在 tz-aware DatetimeIndex上弃用对 naive datetime对象的切片索引,以匹配标量索引行为(GH 36148

  • 返回np.ndarrayIndex.ravel()已被弃用,将来将返回相同索引的视图(GH 19956

  • 弃用在to_timedelta()中使用表示单位的字符串‘M’、‘Y’或‘y’(GH 36666

  • Index方法&|^的行为将被弃用,并且将来将与集合操作Index.intersection()Index.union()Index.symmetric_difference()一致,分别,将来将与匹配Series行为的逐点布尔操作一致。请改用命名的集合方法(GH 36758

  • Categorical.is_dtype_equal()CategoricalIndex.is_dtype_equal()已被弃用,将在将来的版本中移除(GH 37545)

  • Series.slice_shift()DataFrame.slice_shift() 已被弃用,请使用 Series.shift()DataFrame.shift() 替代(GH 37601

  • 对于无序的 DatetimeIndex 对象进行部分切片,使用不在索引中的键已弃用,并将在将来的版本中删除(GH 18531

  • PeriodIndex.astype() 中的 how 关键字已弃用,并将在将来的版本中删除,请改用 index.to_timestamp(how=how)GH 37982

  • 对于除 DatetimeIndexTimedeltaIndexPeriodIndex 外的 Index 子类,已弃用 Index.asi8()GH 37877

  • Categorical.remove_unused_categories() 中的 inplace 参数已弃用,并将在将来的版本中删除(GH 37643

  • DataFrame.info()null_counts 参数已弃用,并替换为 show_counts。它将在将来的版本中删除(GH 37999

在非对齐的 DataFrame 上调用 NumPy ufuncs

在 pandas 1.2.0 中,调用非对齐的 DataFrame 上的 NumPy ufuncs 的行为发生了变化(在调用 ufunc 之前对输入进行对齐),但在 pandas 1.2.1 中撤销了此更改。现在将不对齐的行为弃用,有关更多详情,请参阅 1.2.1 版本说明

性能改进

  • 当使用数组创建具有 strStringDtype 类型的 DataFrame 或 Series 时,性能有所提升,该数组包含许多字符串元素(GH 36304, GH 36317, GH 36325, GH 36432, GH 37371

  • DataFrameGroupBy.agg()SeriesGroupBy.agg() 中使用numba引擎的性能改进 (GH 35759)

  • 从一个巨大字典创建 Series.map() 时的性能改进 (GH 34717)

  • DataFrameGroupBy.transform()SeriesGroupBy.transform() 中使用numba引擎的性能改进 (GH 36240)

  • 修改了 Styler 的 uuid 方法,以在网络上传输数据时压缩数据,同时保持较低的表冲突概率 (GH 36345)

  • float dtype 列中使用非 ns 时间单位的 to_datetime() 的性能改进 (GH 20445)

  • IntervalArray 上设置值的性能改进 (GH 36310)

  • 现在内部索引方法 _shallow_copy() 使新索引和原始索引共享缓存属性,避免再次创建这些属性,如果在任一端创建了这些属性。这可以加快依赖于创建现有索引副本的操作速度 (GH 36840)

  • RollingGroupby.count()中的性能改进 (GH 35625)

  • 对于固定窗口的 Rolling.min()Rolling.max() 有轻微的性能下降 (GH 36567)

  • 在 python 3.8+ 使用 protocol=5 时在 DataFrame.to_pickle() 中减少了峰值内存使用量 (GH 34244)

  • 当对象具有许多索引标签时,例如 dir(ser) 时,dir 调用更快(GH 37450

  • ExpandingGroupby 的性能改进(GH 37064

  • Series.astype()DataFrame.astype()Categorical 的性能改进(GH 8628

  • DataFrame.groupby()float dtype 的性能改进(GH 28303),底层哈希函数的更改可能导致基于浮点索引的排序顺序的更改(例如 Index.value_counts()

  • pd.isin() 对具有超过 1e6 个元素的输入的性能改进(GH 36611

  • DataFrame.__setitem__() 的性能改进,支持类似列表的索引器(GH 37954

  • 在指定了 chunksize 时,read_json() 现在避免将整个文件读入内存(GH 34548

Bug 修复

类别

  • Categorical.fillna() 现在总是返回一个副本,无论是否有任何 NAs 被填充,都会验证传递的填充值,并禁止将 NaT 作为数值类别的填充值(GH 36530

  • Categorical.__setitem__() 中的 Bug 在尝试设置元组值时错误地引发异常(GH 20439

  • CategoricalIndex.equals() 中的 Bug 将非类别条目错误地转换为 np.nanGH 37667

  • CategoricalIndex.where() 中的 Bug 将非类别条目错误地设置为 np.nan,而不是引发 TypeErrorGH 37977

  • Categorical.to_numpy() 和带有 tz-aware datetime64 类别的 np.array(categorical) 的 Bug 错误地丢弃了时区信息,而不是转换为对象 dtype(GH 38136

日期时间类

  • DataFrame.combine_first()中存在一个错误,当列不在原始DataFrame中时,将其他DataFrame上的类似于 datetime 的列转换为整数 (GH 28481)

  • DatetimeArray.date中存在一个错误,在只读的后台数组中将引发ValueError错误 (GH 33530)

  • NaT比较中存在一个错误,未能在无效的不等式比较上引发TypeError (GH 35046)

  • DateOffset中存在一个错误,当输入值超出正常范围(例如,月份=12)时,从 pickle 文件重建的属性与原始对象不同(GH 34511)

  • DatetimeIndex.get_slice_bound()中存在一个错误,不接受datetime.date对象或具有时区感知的 naive TimestampDatetimeIndex (GH 35690)

  • DatetimeIndex.slice_locs()中存在一个错误,不接受datetime.date对象(GH 34077)

  • DatetimeIndex.searchsorted()TimedeltaIndex.searchsorted()PeriodIndex.searchsorted()Series.searchsorted()中存在一个错误,datetime64timedelta64Period dtype 中的NaT值的放置与 NumPy 不一致 (GH 36176, GH 36254)

  • DatetimeArrayTimedeltaArrayPeriodArray方法__setitem__中存在不一致,将字符串数组转换为类似于 datetime 的标量,但不是标量字符串 (GH 36261)

  • DatetimeArray.take()中存在一个错误,错误地允许fill_value与不匹配的时区 (GH 37356)

  • DatetimeIndex.shift 中的 Bug,在移动空索引时不正确地引发异常 (GH 14811)

  • TimestampDatetimeIndex 之间的比较,对于带有时区和不带时区的对象现在遵循标准库 datetime 的行为,对于 !=/== 返回 True/False,对于不等式比较则引发异常 (GH 28507)

  • DatetimeIndex.equals()TimedeltaIndex.equals() 中的 Bug,不正确地将 int64 索引视为相等 (GH 36744)

  • Series.to_json()DataFrame.to_json()read_json() 现在在 orient 结构为 table 时实现了时区解析 (GH 35973)

  • astype() 现在尝试直接从 object 转换为 datetime64[ns, tz],并从字符串中推断时区(GH 35973

  • TimedeltaIndex.sum()Series.sum() 中的 Bug,在空索引或序列上使用 timedelta64 数据类型时返回 NaT 而不是 Timedelta(0) (GH 31751)

  • DatetimeArray.shift() 中的 Bug,不正确地允许具有不匹配时区的 fill_value (GH 37299)

  • 在将非标量其他内容添加到带有非零 offsetBusinessDay 中的 Bug (GH 37457)

  • to_datetime() 中的 Bug,使用只读数组时不正确地引发异常 (GH 34857)

  • Series.isin() 中的 Bug,当 datetime64[ns] 数据类型和 DatetimeIndex.isin() 不正确地将整数转换为日期时间时 (GH 36621)

  • Series.isin() 中的 Bug,当 datetime64[ns] 数据类型和 DatetimeIndex.isin() 未考虑到带有时区和不带时区的日期时间始终不同时 (GH 35728)

  • Bug in Series.isin()PeriodDtype数据类型和PeriodIndex.isin()中,未考虑具有不同PeriodDtype参数的情况始终不同的问题(GH 37528

  • Bug in Period 构造函数现在正确处理value参数中的纳秒(GH 34621GH 17053

时间差

  • Bug in TimedeltaIndexSeriesDataFrametimedelta64数据类型和分母为NaT时的地板除法中存在问题(GH 35529

  • Bug in ISO 8601 持续时间的解析中存在问题,包括Timedeltato_datetime()GH 29773GH 36204

  • Bug in to_timedelta() 中的只读数组错误地引发异常(GH 34857

  • Bug in Timedelta 在字符串输入的子秒部分精度高于纳秒时错误地截断(GH 36738

时区

  • Bug in date_range()ambiguous=False的有效输入引发AmbiguousTimeError的问题(GH 35297

  • Bug in Timestamp.replace() 丢失了 fold 信息(GH 37610

数值

  • Bug in to_numeric() 中浮点精度不正确的问题(GH 31364

  • Bug in DataFrame.any()axis=1bool_only=True时忽略bool_only关键字的问题(GH 32432

  • Series.equals()中的错误,当 NumPy 数组与标量进行比较时引发ValueErrorGH 35267

  • Series中的错误,当两个具有不同时区的DatetimeIndex执行算术运算时,这些索引会错误地更改(GH 33671

  • 使用check_exact=False时,pandas.testing模块函数在复杂数值类型上的使用中出现的错误(GH 28235

  • DataFrame.__rmatmul__()中的错误处理报告转置形状(GH 21581

  • Series中的灵活算术方法中的错误,当与listtuplenp.ndarray进行操作时,结果将具有不正确的名称(GH 36760

  • IntegerArraytimedeltanp.timedelta64对象的乘法中的错误(GH 36870

  • MultiIndex中的错误,与元组进行比较时错误地将元组视为数组样本(GH 21517

  • DataFrame.diff()中的错误,处理datetime64类型,包括NaT值,未能正确填充NaT结果(GH 32441

  • DataFrame中的错误,算术运算错误地接受关键字参数(GH 36843

  • IntervalArraySeries比较时未返回 Series(GH 36908

  • DataFrame中的错误,允许与未定义结果的数组样本列表进行算术运算。行为更改为引发ValueErrorGH 36702

  • DataFrame.std() 中的错误,对于 timedelta64 类型和 skipna=False 会出现错误(GH 37392

  • DataFrame.min()DataFrame.max() 中的错误,对于 datetime64 类型和 skipna=False 会出现错误(GH 36907

  • DataFrame.idxmax()DataFrame.idxmin() 中的错误,混合数据类型会错误地引发 TypeErrorGH 38195

转换

  • DataFrame.to_dict() 中的错误,使用 orient='records' 时,现在会返回 datetime-like 列的 Python 本机日期对象(GH 21256

  • Series.astype() 中的错误,从 string 转换为 float 时出现 pd.NA 值(GH 37626

字符串

  • Series.to_string()DataFrame.to_string()DataFrame.to_latex() 中的错误,在 index=False 时会添加一个前导空格(GH 24980

  • to_numeric() 中的错误,尝试转换只包含数字字符串和 NA 的字符串类型 Series 时会引发 TypeErrorGH 37262

区间

  • DataFrame.replace()Series.replace() 中的错误,Interval 数据类型将被转换为对象数据类型(GH 34871

  • IntervalIndex.take() 中的错误,使用负索引和 fill_value=None 时(GH 37330

  • IntervalIndex.putmask() 中的 Bug,datetime 类型的数据错误地转换为对象 dtype (GH 37968)

  • IntervalArray.astype()中的 Bug 错误地丢失了 CategoricalDtype 对象的 dtype 信息 (GH 37984)

索引

  • PeriodIndex.get_loc() 中的 Bug,错误地在非日期字符串上引发 ValueError 而不是 KeyError,导致 Series.__getitem__()Series.__contains__()Series.loc.__getitem__() 中出现类似的错误 (GH 34240)

  • Index.sort_values() 中的 Bug,当传递空值时,该方法会尝试比较缺失值而不是将其推到排序顺序的末尾,导致方法中断 (GH 35584)

  • Index.get_indexer()Index.get_indexer_non_unique() 中的 Bug,返回 int64 数组而不是 intp (GH 36359)

  • DataFrame.sort_index() 中的 Bug,当参数 ascending 作为单级索引上的列表传递时,会给出错误的结果 (GH 32334)

  • DataFrame.reset_index() 中的 Bug,错误地在具有 Categorical dtype 的级别中存在缺失值的 MultiIndex 输入上引发 ValueError (GH 24206)

  • 在日期时间值上使用布尔掩码进行索引的 Bug,有时会返回视图而不是副本 (GH 36210)

  • DataFrame.__getitem__()DataFrame.loc.__getitem__() 中的 Bug,涉及 IntervalIndex 列和数字索引器 (GH 26490)

  • Series.loc.__getitem__() 中的 Bug,涉及非唯一的 MultiIndex 和空列表索引器 (GH 13691)

  • 在使用具有名为 "0" 的级别的 MultiIndexSeriesDataFrame 上索引时出现的 Bug(GH 37194

  • 在使用无符号整数数组作为索引器时,Series.__getitem__() 出现错误的结果或崩溃,而不是引发 KeyErrorGH 37218

  • Index.where()中的 Bug 错误地将数值转换为字符串(GH 37591

  • 在索引器是带有负步长的切片时,DataFrame.loc() 返回了空结果(GH 38071

  • 在索引是 object dtype 且给定的数值标签在索引中时,Series.loc()DataFrame.loc() 出现错误(GH 26491

  • 在从 MultiIndex 中的单个级别应用 loc 时,DataFrame.loc() 返回了请求的键加上缺失值(GH 27104

  • 在使用包含 NA 值的列表索引器索引 SeriesDataFrame 上的索引时出现的 Bug,该索引器具有 CategoricalIndex 类型(GH 37722

  • DataFrame.loc.__setitem__()中的 Bug 在使用混合数据类型的空 DataFrame 扩展时出现问题(GH 37932

  • 在列上使用 droplevel=False 时,DataFrame.xs() 忽略了这个参数(GH 19056

  • 在空 DataFrame 上使用 tolerance 不为 Nonemethod="nearest" 时,DataFrame.reindex() 错误地引发了 IndexingErrorGH 27315

  • 使用包含索引的 categories 中存在但索引本身不存在的元素的类似列表索引器进行索引时,SeriesDataFrame 的索引失败引发 KeyError 的错误(GH 37901

  • 将布尔标签插入具有数字 Index 列的 DataFrame 时,错误地转换为整数(GH 36319

  • DataFrame.iloc()Series.iloc()__setitem__ 中对齐对象的错误(GH 22046

  • 当部分标签被发现时,MultiIndex.drop() 没有引发错误(GH 37820

  • 当使用 slice(None) 给出剩余级别的缺失组合时,DataFrame.loc() 没有引发 KeyError 的错误(GH 19556

  • 当非整数切片被给定以从 MultiIndex 中选择值时,DataFrame.loc() 引发 TypeError 的错误(GH 25165, GH 24263

  • 当索引为 MultiIndex 且仅有一个级别时,Series.at() 返回一个元素而不是标量的错误(GH 38053

  • 当索引器与用于过滤的 MultiIndex 不同顺序时,DataFrame.loc() 返回并分配元素的顺序错误(GH 31330, GH 34603

  • DataFrame.loc()DataFrame.__getitem__() 存在 bug,当列是只有一个级别的 MultiIndex 时会引发 KeyError (GH 29749)

  • Series.__getitem__()DataFrame.__getitem__() 存在 bug,在 IntervalIndex 中不存在缺失键时会引发空白的 KeyError (GH 27365)

  • 在为 DataFrameSeries 设置新标签时存在 bug,当新标签不在索引的类别中时,会错误地引发 TypeError (GH 38098)

  • Series.loc()Series.iloc() 存在 bug,在长度相等的 object Series 中插入类似于 np.arraylisttuple 的列表时会引发 ValueError (GH 37748, GH 37486)

  • Series.loc()Series.iloc() 存在 bug,将 object Series 的所有值设置为类似于列表的 ExtensionArray 的所有值,而不是将其插入其中 (GH 38271)

缺失

  • SeriesGroupBy.transform() 现在正确处理了 dropna=False 情况下的缺失值 (GH 35014)

  • Series.nunique() 函数在 dropna=True 情况下存在 bug,当存在 NANone 缺失值时返回不正确的结果 (GH 37566)

  • Series.interpolate() 函数存在 bug,在使用 padbackfill 方法时,关键字参数 limit_arealimit_direction 无效 (GH 31048)

多重索引

  • 当使用DataFrame.xs()IndexSlice时出现错误,引发TypeError,错误消息为"Expected label or tuple of labels"GH 35301

  • 当索引中存在NaT值时,DataFrame.reset_index()引发ValueError,错误消息为"cannot convert float NaN to integer"GH 36541

  • 当与包含字符串和NaN值的MultiIndex一起使用时,DataFrame.combine_first()引发TypeErrorGH 36562

  • 当输入为不存在的键时,MultiIndex.drop()删除了NaN值(GH 18853

  • 当索引具有重复项且未排序时,MultiIndex.drop()中出现错误,删除了比预期更多的值(GH 33494

输入/输出

  • read_sas()在失败时不再泄漏资源(GH 35566

  • 当与包含bmode一起调用文件名时,DataFrame.to_csv()Series.to_csv()中出现ValueErrorGH 35058

  • 当使用float_precision='round_trip'时,read_csv()未处理decimalthousands参数(GH 35365

  • to_pickle()read_pickle()关闭了用户提供的文件对象(GH 35679

  • to_csv()始终将对于'gzip'的压缩参数传递给gzip.GzipFileGH 28103

  • to_csv()不支持对没有文件名的二进制文件对象进行 zip 压缩(GH 35058

  • to_csv()read_csv() 不支持对内部转换为文件对象的路径类对象进行 compressionencoding 的控制 (GH 35677, GH 26124, GH 32392)

  • DataFrame.to_pickle()Series.to_pickle()read_pickle() 不支持文件对象的压缩 (GH 26237, GH 29054, GH 29570)

  • LongTableBuilder.middle_separator() 中存在的 Bug 会在 LaTeX 文档的列表中复制 LaTeX longtable 条目 (GH 34360)

  • engine='python' 时,read_csv() 中存在的 Bug 会在第一行中存在多个项且第一个元素以 BOM 开头时截断数据 (GH 36343)

  • pandas-gbq 中移除了 private_keyverbose,因为它们不再被支持 (GH 34654, GH 30200)

  • 为了避免在 read_hdf() 中出现 ValueError,将 pytables 的最小版本提升至 3.5.1 (GH 24839)

  • delim_whitespace=Truesep=default 时,read_table()read_csv() 中存在的 Bug (GH 36583)

  • 使用 lines=Trueorient='records' 时,DataFrame.to_json()Series.to_json() 中存在的 Bug 会导致记录的最后一行不附加 'new line character' (GH 36888)

  • 在具有固定偏移时区的read_parquet()中,未识别时区的字符串表示的 bug (GH 35997, GH 36004)

  • DataFrame.to_html()DataFrame.to_string()DataFrame.to_latex()中,当同时指定float_format参数时,忽略了na_rep参数的 bug (GH 9046, GH 13828)

  • 输出复数时显示过多尾随零的渲染 bug (GH 36799)

  • 使用HDFStore时,当导出空的datetime64[ns, tz]数据类型的 DataFrame 到固定的 HDF5 存储时,会抛出TypeErrorbug (GH 20594)

  • 使用HDFStore时,当导出具有固定 HDF5 存储的datetime64[ns, tz]数据类型的 Series 时,会丢失时区信息的 bug (GH 20594)

  • read_csv()中,当engine="c"且请求了encoding时,关闭了用户提供的二进制文件句柄的 bug (GH 36980)

  • DataFrame.to_hdf()中,当dropna=True时未删除缺失行的 bug (GH 35719)

  • read_html()中,当向io参数提供pathlib.Path参数时,会引发TypeError的 bug (GH 37705)

  • DataFrame.to_excel()Series.to_excel()DataFrame.to_markdown()Series.to_markdown()现在支持写入到诸如 S3 和 Google Cloud Storage 等 fsspec URL 中的 bug (GH 33987)

  • skip_blank_lines=True 时,read_fwf() 中的一个错误未跳过空行(GH 37758)

  • 使用 read_json() 时,使用 dtype=False 将缺失值解析为 NaN 而不是 NoneGH 28501)

  • read_fwf() 推断压缩时使用了 compression=None,这与其他 read_* 函数不一致(GH 37909)

  • DataFrame.to_html()ExtensionDtype 列上忽略了 formatters 参数(GH 36525)

  • 将最低 xarray 版本提升到 0.12.3,以避免引用已删除的 Panel 类(GH 27101, GH 37983)

  • DataFrame.to_csv() 重新打开了同时实现了 os.PathLike 的文件句柄(GH 38125)

  • 将具有缺失值的切片 pyarrow.Table 转换为 DataFrame 时存在一个错误(GH 38525)

  • 在包含百分号的列名时,read_sql_table() 引发 sqlalchemy.exc.OperationalError 的一个错误(GH 37517)

期间

  • DataFrame.replace()Series.replace() 中存在的一个错误,会将 Period 类型转换为对象类型(GH 34871)

绘图

  • subplots=True 时,DataFrame.plot() 中的一个错误会在 x 轴不是不规则时间序列时旋转 xticklabels(GH 29460)

  • style 关键字中的标记字母有时会引发 ValueError 时,DataFrame.plot() 中存在的一个错误(GH 21003)

  • 在数值型或字符串的情况下,DataFrame.plot.bar()Series.plot.bar() 的刻度位置是按值顺序分配的,而不是实际值或智能排序(GH 26186, GH 11465)。此修复已在 pandas 1.2.1 中撤销,请参阅 1.2.1 版本更新(2021 年 1 月 20 日)

  • 同步坐标轴失去了其刻度标签,应该只发生在‘externally’共享坐标轴的最后一行或列上(GH 33819

  • 当 Series 或 DataFrame 被以固定频率索引时,且 x 轴下限大于上限时,Series.plot()DataFrame.plot() 存在一个 Bug,会抛出 ValueErrorGH 37454

  • subplots=False时,DataFrameGroupBy.boxplot()存在一个 Bug,会引发 KeyErrorGH 16748

  • 当未传递 sharey 参数时,DataFrame.plot()Series.plot() 存在一个 Bug,会覆盖 matplotlib 的共享 y 轴行为(GH 37942

  • 当存在 ExtensionDtype 列时,DataFrame.plot() 会引发 TypeError 的 Bug(GH 32073

Styler

  • 由于 rowspan 属性格式错误,导致 Styler.render() 生成的 HTML 错误,现在已经修正,与 w3 语法匹配(GH 38234

Groupby/resample/rolling

  • 当多个Categoricals进行分组时,DataFrameGroupBy.count()SeriesGroupBy.sum() 对丢失的类别返回 NaN。现在返回0GH 35028

  • DataFrameGroupBy.apply() 中存在错误,如果分组轴有重复条目,则有时会引发错误的 ValueErrorGH 16646)。

  • DataFrame.resample() 中存在错误,当从 "D" 转换到 "24H" 时进入夏令时时会引发 ValueErrorGH 35219)。

  • 在组合方法 DataFrame.groupby()DataFrame.resample() 以及 DataFrame.interpolate() 时存在错误,会引发 TypeErrorGH 35325)。

  • DataFrameGroupBy.apply() 中存在错误,如果在 .apply 之前调用了另一个 groupby 方法,则会从输出列中删除一个非干扰的分组列(GH 34656)。

  • 在对 DataFrameGroupBy 进行列子集操作时存在错误(例如 df.groupby('a')[['b']])),会重置 axis, dropna, group_keys, level, mutated, sort, 和 squeeze 到它们的默认值(GH 9959)。

  • DataFrameGroupBy.tshift() 中存在错误,当无法为组的索引推断频率时未能引发 ValueErrorGH 35937)。

  • DataFrame.groupby() 中的错误并不总是保留 any, all, bfill, ffill, shift 的列索引名称(GH 29764)。

  • DataFrameGroupBy.apply() 中存在错误,当 dropna=False 时,使用 np.nan 进行分组会引发错误(GH 35889)。

  • Rolling.sum()中的错误导致混合了浮点数和整数的数据类型且axis=1时返回错误值(GH 20649GH 35596

  • Rolling.count()中的错误,当使用FixedForwardWindowIndexer作为窗口,min_periods=0且窗口中只有缺失值时,返回np.nanGH 35579

  • 使用PeriodIndex时,Rolling产生不正确的窗口大小的错误(GH 34225

  • DataFrameGroupBy.ffill()DataFrameGroupBy.bfill()中的错误,当dropna=True时,NaN组会返回填充值而不是NaNGH 34725

  • RollingGroupby.count()中的错误,在指定closed参数时引发ValueErrorGH 35869)

  • DataFrameGroupBy.rolling()中的错误,在使用部分居中窗口时返回错误值(GH 36040

  • DataFrameGroupBy.rolling()中的错误,在包含NaN的时间感知窗口中返回错误值。现在引发ValueError,因为窗口现在不是单调的(GH 34617

  • Rolling.__iter__()中的错误,当min_periods大于window时未引发ValueErrorGH 37156

  • 使用 Rolling.var() 而不是 Rolling.std() 可避免在 Rolling.var() 仍在浮点精度范围内时出现数值问题,而 Rolling.std() 不会(GH 31286)

  • DataFrameGroupBy.quantile()Resampler.quantile() 在数值为 Timedelta 类型时引发 TypeError 错误(GH 29485

  • Rolling.median()Rolling.quantile() 对具有非单调起始或结束点的 BaseIndexer 子类的窗口返回错误值(GH 37153

  • DataFrame.groupby() 在单列分组时,使用 dropna=False 会从结果中删除 nan 组(GH 35646, GH 35542

  • DataFrameGroupBy.head()DataFrameGroupBy.tail()SeriesGroupBy.head()SeriesGroupBy.tail() 在使用 axis=1 时会引发错误(GH 9772

  • 在使用DataFrameGroupBy.transform()时存在 bug,当使用axis=1和转换核(例如“shift”)时,会引发错误 (GH 36308)

  • 在使用DataFrameGroupBy.resample()时存在 bug,使用.agg与 sum 一起会产生不同的结果,而仅调用.sum则不会 (GH 33548)

  • 在使用DataFrameGroupBy.apply()时存在 bug,在返回与原始框架相同的轴时,会删除nan组的值 (GH 38227)

  • 在使用DataFrameGroupBy.quantile()时存在 bug,当按列分组时,无法处理数组样式的q (GH 33795)

  • 在使用DataFrameGroupBy.rank()时存在 bug,当使用datetime64tz或 period 类型时,结果被错误地转换为这些类型,而不是返回float64类型 (GH 38187)

重塑

  • DataFrame.crosstab()中存在 bug,在具有重复行名称、重复列名称或行和列标签之间存在重复名称的输入上返回的结果不正确 (GH 22529)

  • 在使用DataFrame.pivot_table()时存在 bug,当使用aggfunc='count'aggfunc='sum'时,对于在Categorical上进行数据透视时,丢失的类别会返回NaN。现在返回0 (GH 31422)

  • 在使用concat()DataFrame构造函数时存在 bug,在某些情况下,输入索引名称不会保留 (GH 13475)

  • 在使用 func crosstab()时存在 bug,当同时使用多个列并且margins=Truenormalize=True时 (GH 35144)

  • 在使用DataFrame.stack()时存在 bug,在空 DataFrame.stack 时会引发错误 (GH 36113). 现在返回一个带有空 MultiIndex 的空 Series。

  • 修复了Series.unstack()中尝试对单级索引的 Series 进行 unstack 会引发ValueError的错误(GH 36113)

  • 修复了DataFrame.agg()中使用func={'name':<FUNC>}时,当DataFrame.columns==['Name']时错误地引发TypeError的问题(GH 36212)

  • 修复了Series.transform()中当参数func为字典时给出不正确的结果或引发错误的问题(GH 35811)

  • 修复了DataFrame.pivot()在行和列都是多级索引时未保留列的MultiIndex级别名称的问题(GH 36360)

  • 修复了DataFrame.pivot()在传递columns但未传递values时修改了index参数的问题(GH 37635)

  • 修复了DataFrame.join()返回的结果MultiIndex的非确定性级别顺序的问题(GH 36910)

  • 修复了DataFrame.combine_first()在包含string类型和只包含NA的一级MultiIndex时对齐错误的问题(GH 37591)

  • 修复了在merge()中合并DatetimeIndex与空 DataFrame 时的回归问题(GH 36895)

  • 修复了DataFrame.apply()中当func返回类型为dict时未设置返回值索引的错误(GH 37544)

  • 修复了DataFrame.merge()pandas.merge()how=righthow=left时返回结果的排序不一致的错误(GH 35382)

  • merge_ordered()中的错误,无法处理类似列表的left_byright_byGH 35269

  • merge_ordered()中的错误,在left_byright_by的长度等于leftright的行数时返回错误的连接结果(GH 38166

  • merge_ordered()中的错误,在left_byright_by中的元素不存在于left列或right列时没有引发异常(GH 38167

  • DataFrame.drop_duplicates()中的错误,未验证ignore_index关键字的布尔 dtype(GH 38274

ExtensionArray

  • 修复了通过字典实例化将DataFrame列设置为标量扩展类型时被视为对象类型而不是扩展类型的错误(GH 35965

  • 修复了astype()中等 dtype 和copy=False会返回一个新对象的错误(GH 28488

  • 修复了将 NumPy ufunc 应用于具有多个输出的IntegerArray返回None时的错误(GH 36913

  • 修复了PeriodArray__init__签名与DatetimeArrayTimedeltaArray的不一致性(GH 37289

  • 对于 BooleanArrayCategoricalDatetimeArrayFloatingArrayIntegerArrayPeriodArrayTimedeltaArrayPandasArray 的缩减现在是关键字方法(GH 37541

  • 修复了一个 Bug,当对包含类似 NaN 值的 ExtensionArray 进行成员检查时错误地引发了 TypeErrorGH 37867

其他

  • DataFrame.replace()Series.replace() 中存在一个 Bug,当传入无效参数组合时,错误地引发 AssertionError 而不是 ValueErrorGH 36045

  • DataFrame.replace()Series.replace() 中存在一个 Bug,涉及到数值和字符串 to_replaceGH 34789

  • 修复了在 Series.abs() 和在 Series 和 DataFrames 上调用的 ufuncs 中错误地传播元数据的 Bug(GH 28283

  • DataFrame.replace()Series.replace() 中存在一个 Bug,错误地将 PeriodDtype 强制转换为对象 dtype(GH 34871

  • 修复了元数据传播中的 Bug,当列名与元数据名称重叠时,错误地复制 DataFrame 列作为元数据(GH 37037

  • 修复了在 Series.dtSeries.str 访问器、DataFrame.duplicatedDataFrame.stackDataFrame.unstackDataFrame.pivotDataFrame.appendDataFrame.diffDataFrame.applymapDataFrame.update 方法中的元数据传播问题(GH 28283, GH 37381

  • 修复了使用 DataFrame.__getitem__ 选择列时元数据传播的问题(GH 28283

  • 在非 Index 上调用 Index.intersection() 时存在错误,未能正确设置返回的 Index 的名称(GH 38111

  • 在一些极端情况下,RangeIndex.intersection() 中存在错误,未能正确设置返回的 Index 的名称(GH 38197

  • 在一些极端情况下,Index.difference() 中存在错误,未能正确设置返回的 Index 的名称(GH 38268

  • Index.union() 中的错误表现不同,取决于操作数是 Index 还是其他类似列表的对象(GH 36384

  • 在非匹配的数值数据类型的情况下,Index.intersection() 中存在错误,转换为 object 数据类型而不是最小公共数据类型(GH 38122

  • IntervalIndex.union()中的错误,在空时返回一个类型错误的IndexGH 38282

  • 现在将一个具有 2 个或更多维度的数组传递给Series构造函数会引发更具体的ValueError,而不是一个裸露的ExceptionGH 35744

  • dir中的错误,dir(obj)不会显示在 pandas 对象实例上定义的属性(GH 37173

  • Index.drop()中的错误,在索��具有重复项时引发InvalidIndexError([GH 38051](https://github.com/pandas-dev/pandas/issues/38051)

  • RangeIndex.difference()中的错误,在某些情况下返回Int64Index,而应返回RangeIndexGH 38028

  • 修复了assert_series_equal()中的错误,当比较类似日期时间的数组与等效的非扩展数据类型数组时(GH 37609

  • is_bool_dtype()中的错误,当传递有效字符串如"boolean"时会引发异常(GH 38386

  • 修复了逻辑运算符中的回归错误,当DataFrame的列是具有未使用类别的CategoricalIndex时引发ValueErrorGH 38367

类别

  • Categorical.fillna()将始终返回一个副本,验证传递的填充值,无论是否有任何 NA 要填充,并禁止将NaT作为数值类别的填充值(GH 36530

  • Categorical.__setitem__()中的错误,当尝试设置元组值时错误地引发异常(GH 20439

  • CategoricalIndex.equals()中的错误,错误地将非类别条目转换为np.nanGH 37667

  • CategoricalIndex.where()中的错误,错误地将非类别条目设置为np.nan,而不是引发TypeErrorGH 37977

  • Categorical.to_numpy()np.array(categorical) 中存在的 bug,带有时区信息的 datetime64 类别错误地丢弃了时区信息,而不是转换为对象 dtype (GH 38136)

类似日期时间的

  • DataFrame.combine_first() 中存在的 bug 会在其他 DataFrame 上将类似日期时间的列转换为整数,当列在原始 DataFrame 中不存在时 (GH 28481)

  • DatetimeArray.date 中的一个 bug,会在只读的后备数组中引发 ValueErrorGH 33530

  • NaT 比较中的 bug,在无效的不等式比较中未能引发 TypeError (GH 35046)

  • DateOffset 中存在的 bug,从 pickle 文件重建的属性与输入值超出正常范围时的原始对象不同(例如 months=12)(GH 34511

  • DatetimeIndex.get_slice_bound() 中存在 bug,不接受 datetime.date 对象或带有时区信息的原生 TimestampDatetimeIndexGH 35690

  • DatetimeIndex.slice_locs() 中存在 bug,不接受 datetime.date 对象 (GH 34077)

  • DatetimeIndex.searchsorted()TimedeltaIndex.searchsorted()PeriodIndex.searchsorted()Series.searchsorted() 存在 bug,与 NumPy 中 datetime64timedelta64Period dtype 中 NaT 值的放置不一致 (GH 36176GH 36254)

  • DatetimeArrayTimedeltaArrayPeriodArray 方法 __setitem__ 中的不一致性,将字符串数组转换为类似日期时间的标量,但不转换标量字符串(GH 36261

  • DatetimeArray.take() 中的错误允许了不匹配的时区的 fill_valueGH 37356

  • DatetimeIndex.shift 中的错误,在移动空索引时错误地引发异常(GH 14811

  • TimestampDatetimeIndex 在有时区感知和无时区感知对象之间的比较现在遵循标准库 datetime 的行为,对于 !=/== 返回 True/False,对于不相等的比较则引发异常(GH 28507

  • DatetimeIndex.equals()TimedeltaIndex.equals() 中的错误,错误地将 int64 索引视为相等(GH 36744

  • Series.to_json()DataFrame.to_json()read_json() 现在在 table 结构的 orient 下实现了时区解析(GH 35973

  • astype() 现在尝试从字符串推断时区,直接从 object 转换为 datetime64[ns, tz]GH 35973

  • TimedeltaIndex.sum()Series.sum() 在空索引或系列上返回 NaT 而不是 Timedelta(0) 的错误,该索引或系列具有 timedelta64 类型(GH 31751

  • DatetimeArray.shift() 中的错误允许了不匹配的时区的 fill_valueGH 37299

  • 在将具有非零 offsetBusinessDay 添加到非标量其他对象时的错误(GH 37457

  • to_datetime() 中,使用只读数组时不正���地引发错误(GH 34857)

  • Series.isin() 中,datetime64[ns] 数据类型和 DatetimeIndex.isin() 不正确地将整数转换为日期时间(GH 36621)

  • Series.isin() 中,datetime64[ns] 数据类型和 DatetimeIndex.isin() 未考虑到时区感知和时区无关的日期时间始终不同(GH 35728)

  • Series.isin() 中,PeriodDtype 数据类型和 PeriodIndex.isin() 未考虑到具有不同 PeriodDtype 参数的情况,始终认为它们不同(GH 37528)

  • Period 构造函数中的错误现在正确处理了value参数中的纳秒(GH 34621GH 17053)

时间差

  • TimedeltaIndexSeriesDataFrame 中,timedelta64 数据类型和分母中的 NaT 进行地板除法时出现错误(GH 35529)

  • Timedeltato_datetime() 中解析 ISO 8601 时长的错误(GH 29773, GH 36204)

  • to_timedelta() 中,使用只读数组时不正确地引发错误(GH 34857)

  • Timedelta 中,当输入的字符串精度高于纳秒时,错误地截断为亚秒部分(GH 36738)

时区

  • date_range() 中,对于具有ambiguous=False的有效输入,引发AmbiguousTimeError错误(GH 35297)

  • Timestamp.replace() 中的错误,丢失了 fold 信息(GH 37610

数值

  • to_numeric() 中浮点精度不正确的错误(GH 31364)

  • DataFrame.any() 中的错误,当 axis=1bool_only=True 时,忽略了 bool_only 关键字(GH 32432

  • Series.equals() 中的错误,当将 NumPy 数组与标量进行比较时引发 ValueErrorGH 35267

  • 两个具有不同时区的 DatetimeIndex 的两个 Series 在执行算术操作时,错误地更改了这些索引(GH 33671

  • 当在复杂数值类型上使用 check_exact=False 时,pandas.testing 模块函数存在的错误(GH 28235

  • DataFrame.__rmatmul__() 中错误处理报告转置形状的错误(GH 21581

  • Series 弹性算术方法中的错误,当与 listtuplenp.ndarray 进行操作时,结果会有错误的名称(GH 36760

  • IntegerArray 乘法与 timedeltanp.timedelta64 对象存在的错误(GH 36870

  • MultiIndex 与元组比较时,错误地将元组视为类似数组(GH 21517

  • DataFrame.diff() 中的错误,包括 datetime64 dtypes 的 NaT 值未能正确填充 NaT 结果(GH 32441

  • DataFrame 算术运算中错误地接受关键字参数(GH 36843

  • IntervalArraySeries 比较时的错误,未返回 Series(GH 36908)

  • DataFrame 中存在的错误允许使用未定义结果的数组列表进行算术运算。行为已更改为引发ValueErrorGH 36702)

  • DataFrame.std() 中的错误,针对 timedelta64 类型和 skipna=FalseGH 37392)

  • DataFrame.min()DataFrame.max() 中的错误,针对 datetime64 类型和 skipna=FalseGH 36907)

  • DataFrame.idxmax()DataFrame.idxmin() 中的错误,混合 dtype 不正确地引发TypeErrorGH 38195)

转换

  • DataFrame.to_dict() 中的错误,在orient='records'时,现在返回原生的 Python datetime 对象,用于类似于日期时间的列(GH 21256)

  • Series.astype() 中的错误,将string转换为float时,在存在pd.NA值时引发(GH 37626)

字符串

  • Series.to_string(), DataFrame.to_string()DataFrame.to_latex()index=False时添加了一个前导空格的错误(GH 24980)

  • to_numeric() 中的错误,在尝试转换仅包含数字字符串和NA的字符串 dtype Series 时引发TypeErrorGH 37262)

区间

  • DataFrame.replace()Series.replace() 中,Interval dtypes 会被转换为对象 dtypes(GH 34871

  • 在使用负索引和 fill_value=NoneIntervalIndex.take() 中存在错误(GH 37330

  • IntervalIndex.putmask() 中,具有日期类似 dtype 的错误将其错误地转换为对象 dtype(GH 37968

  • IntervalArray.astype() 中存在错误,使用 CategoricalDtype 对象时会不正确地丢弃 dtype 信息(GH 37984

索引

  • PeriodIndex.get_loc() 中存在错误,当非日期字符串引发 ValueError 而不是 KeyError 时,会导致 Series.__getitem__()Series.__contains__()Series.loc.__getitem__() 中出现类似错误的情况(GH 34240

  • Index.sort_values() 中,当传递空值时,该方法会尝试比较缺失值而不是将它们推到排序顺序的末尾,从而导致方法中断(GH 35584

  • Index.get_indexer()Index.get_indexer_non_unique() 中,返回 int64 数组而不是 intpGH 36359

  • DataFrame.sort_index() 中,当参数 ascending 以列表形式传递给单层索引时,会得到错误的结果(GH 32334

  • DataFrame.reset_index() 中,对具有在具有 Categorical dtype 的级别中缺失值的 MultiIndex 输入不正确地引发了 ValueErrorGH 24206

  • 在对日期类似值进行布尔掩码索引时,有时会返回视图而不是副本(GH 36210

  • DataFrame.__getitem__()DataFrame.loc.__getitem__() 存在一个 bug,当列为 IntervalIndex,且使用数值索引器时 (GH 26490)

  • Series.loc.__getitem__() 存在一个 bug,当使用非唯一的 MultiIndex 和一个空列表索引器时 (GH 13691)

  • 在使用命名为 "0" 的级别的 MultiIndex 进行 SeriesDataFrame 索引时存在一个 bug (GH 37194)

  • Series.__getitem__() 存在一个 bug,当使用无符号整数数组作为索引器时,会产生错误的结果或段错误,而不是引发 KeyError (GH 37218)

  • Index.where() 中,将数值值错误地转换为字符串存在一个 bug (GH 37591)

  • 在索引为带负步长的切片时,DataFrame.loc() 返回空结果存在一个 bug (GH 38071)

  • Series.loc()DataFrame.loc() 存在一个 bug,当索引为 object 类型且给定的数值标签在索引中时,会引发异常 (GH 26491)

  • DataFrame.loc() 存在一个 bug,当对来自 MultiIndex 的单一级别应用 loc 时,返回了请求的键以及缺失的值 (GH 27104)

  • 在使用包含 NA 值的列表样式索引器的 CategoricalIndex 上进行 SeriesDataFrame 索引时存在一个 bug (GH 37722)

  • DataFrame.loc.__setitem__() 存在一个 bug,在扩展具有混合类型的空 DataFrame 时 (GH 37932)

  • Bug in DataFrame.xs() 忽略了droplevel=False用于列(GH 19056)

  • Bug in DataFrame.reindex() 对于具有tolerance不是Nonemethod="nearest"的空 DataFrame 错误地引发IndexingErrorGH 27315)

  • 在使用包含在索引的categories中但不在索引本身中的元素的列表样索引器对具有CategoricalIndexSeriesDataFrame进行索引时失败,未能引发KeyErrorGH 37901)

  • 在将布尔标签插入具有数字Index列的DataFrame时出现错误,错误地转换为整数(GH 36319)

  • Bug in DataFrame.iloc()Series.iloc()__setitem__中对齐对象时出现错误(GH 22046)

  • Bug in MultiIndex.drop() 如果标签部分找到,则不会引发错误(GH 37820)

  • Bug in DataFrame.loc() 在使用slice(None)为剩余级别提供缺失组合时未引发KeyErrorGH 19556)

  • Bug in DataFrame.loc() 在给定非整数切片以从MultiIndex选择值时引发TypeErrorGH 25165, GH 24263)

  • 当索引为只有一个级别的MultiIndex时,Series.at()返回具有一个元素而不是标量的Series存在错误(GH 38053

  • 当索引器与要筛选的MultiIndex的顺序不同而导致返回和分配元素顺序错误时,DataFrame.loc()存在错误(GH 31330GH 34603

  • 当列为只有一个级别的MultiIndex时,DataFrame.loc()DataFrame.__getitem__()引发KeyError存在错误(GH 29749

  • 当在IntervalIndex中没有缺失键时,Series.__getitem__()DataFrame.__getitem__()会引发空白的KeyError存在错误(GH 27365

  • 在使用DataFrameSeries上设置新标签时存在错误,当新标签不在索引的类别中时,会错误地引发TypeErrorGH 38098

  • 当在长度相等的object系列中插入类似列表的np.arraylisttuple时,Series.loc()Series.iloc()引发ValueError存在错误(GH 37748GH 37486

  • 当使用类似列表的ExtensionArray而不是插入它时,Series.loc()Series.iloc()将所有值设置为object系列的所有值存在错误(GH 38271

缺失

  • 对于dropna=FalseSeriesGroupBy.transform() 现在可以正确处理缺失值(GH 35014

  • 当同时存在NANone缺失值时,Series.nunique() 中的错误参数dropna=True返回不正确的结果(GH 37566

  • 在使用方法padbackfill时,Series.interpolate() 中的错误参数limit_arealimit_direction没有效果(GH 31048

多重索引

  • 当与IndexSlice一起使用时,DataFrame.xs() 中的错误会引发TypeError错误,错误信息为"Expected label or tuple of labels"GH 35301

  • 当索引中存在NaT值时,DataFrame.reset_index() 中的错误会引发ValueError错误,错误信息为"cannot convert float NaN to integer"GH 36541

  • 当包含字符串和NaN值的MultiIndexDataFrame.combine_first()一起使用时,会引发TypeError错误(GH 36562

  • MultiIndex.drop() 中的错误当输入不存在的键时删除了NaN值(GH 18853

  • 当索引存在重复并且未排序时,MultiIndex.drop() 中的错误会删除比预期更多的值(GH 33494

输入/输出

  • read_sas() 在失败时不再泄漏资源(GH 35566

  • DataFrame.to_csv()Series.to_csv() 在与包含 bmode 组合使用文件名时引发了 ValueErrorGH 35058)。

  • 使用 float_precision='round_trip'read_csv() 在处理 decimalthousands 参数时存在问题(GH 35365)。

  • to_pickle()read_pickle() 关闭了用户提供的文件对象(GH 35679)。

  • to_csv() 总是将 'gzip' 的压缩参数传递给 gzip.GzipFileGH 28103)。

  • to_csv() 不支持对没有文件名的二进制文件对象进行 zip 压缩(GH 35058)。

  • to_csv()read_csv() 不支持对内部转换为文件对象的路径对象进行 compressionencoding 的控制(GH 35677GH 26124GH 32392)。

  • DataFrame.to_pickle()Series.to_pickle()read_pickle() 不支持文件对象的压缩(GH 26237GH 29054GH 29570)。

  • LongTableBuilder.middle_separator() 中的错误会在 LaTeX 文档的表格列表中复制 LaTeX longtable 条目(GH 34360)。

  • 使用 engine='python'read_csv() 在首行存在多个项且第一个元素以 BOM 开头时截断数据(GH 36343)。

  • pandas-gbq 中移除了 read_gbq() 中的 private_keyverbose,因为它们不再受支持(GH 34654GH 30200)。

  • 将最低 pytables 版本提升至 3.5.1 以避免在 read_hdf() 中出现 ValueError 错误(GH 24839

  • delim_whitespace=Truesep=default 时,read_table()read_csv() 存在漏洞(GH 36583

  • 当与 lines=Trueorient='records' 一起使用时,DataFrame.to_json()Series.to_json() 的漏洞,记录的最后一行未附加‘换行字符’(GH 36888

  • 当存在固定偏移时区时,在 read_parquet() 中存在漏洞。时间区域的字符串表示形式未被识别(GH 35997, GH 36004

  • DataFrame.to_html()DataFrame.to_string()DataFrame.to_latex() 在指定 float_format 的同时忽略 na_rep 参数时存在漏洞(GH 9046, GH 13828

  • 复数输出渲染的 bug,显示过多尾随零(GH 36799

  • 当使用固定的 HDF5 存储导出空 DataFrame 时,HDFStore 存在一个 TypeError 错误(GH 20594

  • 当在固定的 HDF5 存储中导出具有 datetime64[ns, tz] 数据类型的 Series 时,HDFStore 会丢弃时区信息(GH 20594

  • engine="c" 且请求了 encoding 时,read_csv() 在关闭用户提供的二进制文件句柄(GH 36980

  • DataFrame.to_hdf() 中存在漏洞,当 dropna=True 时未删除缺失行(GH 35719

  • read_html()中的错误,在向io参数提供pathlib.Path参数时引发TypeErrorGH 37705

  • DataFrame.to_excel()Series.to_excel()DataFrame.to_markdown()Series.to_markdown()现在支持写入到诸如 S3 和 Google Cloud Storage 等 fsspec URL 中(GH 33987

  • read_fwf()中的错误,当skip_blank_lines=True时未跳过空行(GH 37758

  • 使用read_json()解析缺失值时,将dtype=False转换为NaN而不是NoneGH 28501

  • read_fwf()使用compression=None推断压缩,这与其他read_*函数不一致(GH 37909

  • DataFrame.to_html()忽略了ExtensionDtype列的formatters参数(GH 36525

  • 将最低 xarray 版本提升至 0.12.3,以避免引用已删除的Panel类(GH 27101GH 37983

  • DataFrame.to_csv()重新打开了实现os.PathLike的文件句柄(GH 38125

  • 在将带有缺失值的切片pyarrow.Table转换为 DataFrame 时存在错误(GH 38525

  • read_sql_table()中的错误,在列名包含百分号时引发sqlalchemy.exc.OperationalErrorGH 37517

期间

  • DataFrame.replace()Series.replace() 中的 Bug 会导致 Period 数据类型被转换为对象数据类型(GH 34871

绘图

  • subplots=True 时,DataFrame.plot() 中的 Bug 会旋转 x 轴刻度标签,即使 x 轴不是不规则时间序列(GH 29460

  • DataFrame.plot() 中的 Bug,有时在 style 关键字中使用的标记字母会导致 ValueErrorGH 21003

  • DataFrame.plot.bar()Series.plot.bar() 中,刻度位置是按值顺序分配的,而不是对数值进行智能排序或对字符串进行智能排序(GH 26186GH 11465)。该修复已在 pandas 1.2.1 中撤销,参见 1.2.1 版本新特性 (2021 年 1 月 20 日)

  • 并排的坐标轴会丢失它们的刻度标签,这只会发生在‘外部’共享轴的所有行或列中除了最后一行或列时(GH 33819

  • Series.plot()DataFrame.plot() 中的 Bug 在使用固定频率的 TimedeltaIndex 作为索引时,且 x 轴的下限大于上限时,会引发 ValueErrorGH 37454)

  • DataFrameGroupBy.boxplot() 中,当 subplots=False 时会引发 KeyErrorGH 16748

  • Bug 在 DataFrame.plot()Series.plot() 中,当没有传递 sharey 参数时,会覆盖 matplotlib 的共享 y 轴行为(GH 37942

  • Bug 在 DataFrame.plot() 中,当有 ExtensionDtype 列时会引发 TypeErrorGH 32073

Styler

  • Styler.render() HTML 中的 Bug 是由于 rowspan 属性的格式错误而导致生成错误,现在与 w3 语法匹配(GH 38234

Groupby/resample/rolling

  • Bug 在 DataFrameGroupBy.count()SeriesGroupBy.sum() 中,当在多个 Categoricals 上分组时,对于缺失的类别返回 NaN,现在返回 0GH 35028

  • Bug 在 DataFrameGroupBy.apply() 中,如果分组轴具有重复条目,有时会引发错误的 ValueErrorGH 16646

  • Bug 在 DataFrame.resample() 中,当从 "D" 重采样到 "24H" 时,在夏令时转换时会抛出 ValueErrorGH 35219

  • 当结合方法 DataFrame.groupby()DataFrame.resample()DataFrame.interpolate() 时,会引发 TypeErrorGH 35325

  • Bug 在 DataFrameGroupBy.apply() 中,如果在 .apply 之前调用了另一个 groupby 方法,则会丢弃一个非烦扰性分组列(GH 34656

  • 对于 DataFrameGroupBy 的列子集(例如 df.groupby('a')[['b']]))存在的问题会重置属性 axisdropnagroup_keyslevelmutatedsortsqueeze 到它们的默认值(GH 9959

  • DataFrameGroupBy.tshift() 中存在问题,当无法为组的索引推断频率时,未能引发 ValueError 错误(GH 35937

  • DataFrame.groupby() 中存在问题,对于 anyallbfillffillshift,不总是保留列索引名称(GH 29764

  • DataFrameGroupBy.apply() 中存在问题,当 dropna=False 时,使用 np.nan 组时会引发错误(GH 35889

  • Rolling.sum() 中返回了错误的值,当 float 和 integer 之间的数据类型混合且 axis=1 时(GH 20649, GH 35596)

  • Rolling.count() 中返回了 np.nan,其中 FixedForwardWindowIndexer 作为窗口,min_periods=0,窗口中仅包含缺失值(GH 35579

  • 在使用 PeriodIndex 时,Rolling 会产生错误的窗口大小(GH 34225

  • DataFrameGroupBy.ffill()DataFrameGroupBy.bfill() 中存在问题,当 dropna=True 时,NaN 组将返回填充值而不是 NaNGH 34725

  • RollingGroupby.count() 中存在问题,当指定 closed 参数时会引发 ValueError 错误(GH 35869

  • 具有部分中心窗口的 DataFrameGroupBy.rolling() 返回错误值(GH 36040)。

  • 具有包含 NaN 的时间感知窗口的 DataFrameGroupBy.rolling() 返回错误值。由于窗口现在不是单调的,引发 ValueErrorGH 34617)。

  • min_periods 大于 window 时,Rolling.__iter__() 中未引发 ValueErrorGH 37156)。

  • Rolling.var() 仍在浮点精度内而 Rolling.std() 不在时,使用 Rolling.var() 替代 Rolling.std() 可避免 Rolling.corr() 的数值问题(GH 31286)。

  • 当值为 Timedelta 类型时,DataFrameGroupBy.quantile()Resampler.quantile() 中出现 TypeError 错误(GH 29485)。

  • Rolling.median()Rolling.quantile() 在具有非单调起始或结束点的 BaseIndexer 子类的窗口中返回错误的值(GH 37153)。

  • DataFrame.groupby() 中存在的 Bug,在仅对单列进行分组时,使用 dropna=False 会从结果中丢弃 nan 组 (GH 35646, GH 35542)

  • DataFrameGroupBy.head()DataFrameGroupBy.tail()SeriesGroupBy.head()SeriesGroupBy.tail() 中存在的 Bug,在使用 axis=1 时会报错 (GH 9772)

  • DataFrameGroupBy.transform() 中存在的 Bug,在使用 axis=1 和转换核(例如“shift”)时会报错 (GH 36308)

  • DataFrameGroupBy.resample() 中存在的 Bug,在使用 .agg 和 sum 时产生的结果与仅调用 .sum 不同 (GH 33548)

  • DataFrameGroupBy.apply() 中存在的 Bug,在返回与原始框架相同轴的 nan 组时,会丢弃 nan 组的值 (GH 38227)

  • DataFrameGroupBy.quantile() 中存在的 Bug,在按列分组时,无法处理数组 q (GH 33795)

  • DataFrameGroupBy.rank()中存在的 Bug,当使用 datetime64tz 或 period dtype 时,错误地将结果转换为这些 dtype,而不是返回 float64 dtype (GH 38187)

重塑

  • DataFrame.crosstab() 中存在的 Bug,在具有重复行名称、重复列名称或行列标签之间存在重复名称的输入上,返回的结果不正确 (GH 22529)

  • DataFrame.pivot_table() 中存在的 Bug,当使用 aggfunc='count'aggfunc='sum' 时,在分类变量上透视时,缺失类别会返回 NaN。现在返回 0 (GH 31422)

  • 在某些情况下,concat()DataFrame 构造函数中输入的索引名称不会被保留(GH 13475

  • 在使用多个列且 margins=Truenormalize=True 时,crosstab() 的 func 中存在错误(GH 35144

  • 当一个空 DataFrame.stack 时,DataFrame.stack() 会引发错误。现在返回一个具有空 MultiIndex 的空 Series。(GH 36113

  • 在尝试对具有单个索引级别的 Series 进行 unstack 操作时,Series.unstack() 会引发 ValueErrorGH 36113

  • DataFrame.columns==['Name'] 时,使用 func={'name':<FUNC>}DataFrame.agg() 错误地引发 TypeErrorGH 36212

  • Series.transform() 中的错误会在参数 func 是字典时给出不正确的结果或引发错误(GH 35811

  • 当行和列都是多索引时,DataFrame.pivot() 不会保留列的 MultiIndex 级别名称(GH 36360

  • 当传递 columns 但未传递 values 时,DataFrame.pivot() 会修改 index 参数(GH 37635

  • DataFrame.join() 返回的结果 MultiIndex 的级别顺序是非确定性的(GH 36910

  • 使用 dtype 为 string 和只包含 NA 的一级 MultiIndex 时,DataFrame.combine_first() 会导致错误的对齐(GH 37591

  • merge() 中存在的回归错误,当与空 DataFrame 合并 DatetimeIndex 时(GH 36895

  • DataFrame.apply() 中存在的错误,当 func 返回类型为 dict 时未设置返回值的索引(GH 37544

  • DataFrame.merge()pandas.merge() 中存在的错误,在 how=righthow=left 时返回结果的顺序不一致(GH 35382

  • merge_ordered() 中存在的错误,不能处理类似列表的 left_byright_byGH 35269

  • merge_ordered() 中存在的错误,当 left_byright_by 的长度等于 leftright 的行数时返回错误的连接结果(GH 38166

  • merge_ordered() 中存在的错误,当 left_byright_by 中的元素不存在于 left 列或 right 列时未引发错误(GH 38167

  • DataFrame.drop_duplicates() 中存在的错误,未验证 ignore_index 关键字的布尔类型 dtype(GH 38274

ExtensionArray

  • 修复了通过字典实例化将 DataFrame 列设置为标量扩展类型时,将其视为对象类型而不是扩展类型的错误(GH 35965

  • 修复了使用相等 dtype 和 copy=Falseastype() 会返回新对象的错误(GH 28488

  • 修复了将多输出的 NumPy ufunc 应用于 IntegerArray 并返回 None 时的错误(GH 36913

  • 修复了 PeriodArray__init__ 签名与 DatetimeArrayTimedeltaArray 的签名不一致的问题(GH 37289

  • 对于 BooleanArrayCategoricalDatetimeArrayFloatingArrayIntegerArrayPeriodArrayTimedeltaArrayPandasArray 的缩减现在是关键字方法(GH 37541

  • 修复了一个 bug,当对包含类似 nan 的值的 ExtensionArray 进行成员检查时错误地引发了 TypeErrorGH 37867

其他

  • DataFrame.replace()Series.replace() 中存在 bug,当传递无效的参数组合时,错误地引发了 AssertionError 而不是 ValueErrorGH 36045

  • 在使用数值和字符串 to_replace 时,DataFrame.replace()Series.replace() 中存在 bug(GH 34789

  • 修复了在 Series.abs() 和在 Series 和 DataFrames 上调用的 ufuncs 中的元数据传播问题(GH 28283

  • 修复了DataFrame.replace()Series.replace() 错误地从 PeriodDtype 转换为 object dtype 的 bug(GH 34871)。

  • 修复了元数据传播中的错误,当列名与元数据名称重叠时,错误地将 DataFrame 列复制为元数据(GH 37037)。

  • 修复了在 Series.dtSeries.str 访问器、DataFrame.duplicatedDataFrame.stackDataFrame.unstackDataFrame.pivotDataFrame.appendDataFrame.diffDataFrame.applymapDataFrame.update 方法中的元数据传播问题(GH 28283GH 37381)。

  • 修复了在使用 DataFrame.__getitem__ 选择列时的元数据传播问题(GH 28283)。

  • 修复了Index.intersection()中的 bug,对于非Index 失败地设置了返回的Index的正确名称(GH 38111)。

  • 修复了在一些边缘情况下,RangeIndex.intersection() 失败地设置了返回的Index的正确名称的 bug(GH 38197)。

  • 修复了在一些边缘情况下,Index.difference() 失败地设置了返回的Index的正确名称的 bug(GH 38268)。

  • 修复了Index.union()在操作数是Index或其他类似列表时表现不同的错误 (GH 36384)

  • 修复了Index.intersection()在非匹配数值 dtype 情况下转换为object dtype 而不是最小公共 dtype 的错误 (GH 38122)

  • 修复了IntervalIndex.union()在为空时返回一个类型不正确的Index的错误 (GH 38282)

  • 现在,将具有 2 个或更多维度的数组传递给 Series 构造函数将引发更具体的ValueError,而不是裸露的Exception (GH 35744)

  • 修复了dir中的一个错误,即dir(obj)不会显示在实例上定义的属性,适用于 pandas 对象 (GH 37173)

  • 修复了Index.drop()在索引具有重复项时引发InvalidIndexError的错误 (GH 38051)

  • 修复了RangeIndex.difference()在某些情况下返回Int64Index而不是应该返回RangeIndex的错误 (GH 38028)

  • 修复了assert_series_equal()中的一个错误,当比较一个类似于日期时间的数组和一个等价的非扩展 dtype 数组时 (GH 37609)

  • 修复了is_bool_dtype()在传递有效字符串(如"boolean")时引发错误的错误 (GH 38386)

  • 修复了逻辑运算符在DataFrame的列是未使用的类别的CategoricalIndex时引发ValueError的错误 (GH 38367)

贡献者

共有 257 人为此版本贡献了补丁。名字后面带有“+”的人是首次贡献补丁。

  • 21CSM +

  • AbdulMAbdi +

  • Abhiraj Hinge +

  • Abhishek Mangla +

  • Abo7atm +

  • Adam Spannbauer +

  • Albert Villanova del Moral

  • Alex Kirko

  • Alex Lim +

  • Alex Thorne +

  • Aleš Erjavec +

  • Ali McMaster

  • Amanda Dsouza +

  • Amim Knabben +

  • Andrew Wieteska

  • Anshoo Rajput +

  • Anthony Milbourne

  • Arun12121 +

  • Asish Mahapatra

  • Avinash Pancham +

  • BeanNan +

  • Ben Forbes +

  • Brendan Wilby +

  • Bruno Almeida +

  • Byron Boulton +

  • Chankey Pathak

  • Chris Barnes +

  • Chris Lynch +

  • Chris Withers

  • Christoph Deil +

  • Christopher Hadley +

  • Chuanzhu Xu

  • Coelhudo +

  • Dan Moore

  • Daniel Saxton

  • David Kwong +

  • David Li +

  • David Mrva +

  • Deepak Pandey +

  • Deepyaman Datta

  • Devin Petersohn

  • Dmitriy Perepelkin +

  • Douglas Hanley +

  • Dāgs Grīnbergs +

  • Eli Treuherz +

  • Elliot Rampono +

  • Erfan Nariman

  • Eric Goddard

  • Eric Leung +

  • Eric Wieser

  • Ethan Chen +

  • Eve +

  • Eyal Trabelsi +

  • Fabian Gebhart +

  • Fangchen Li

  • Felix Claessen +

  • Finlay Maguire +

  • Florian Roscheck +

  • Gabriel Monteiro

  • Gautham +

  • Gerard Jorgensen +

  • Gregory Livschitz

  • Hans

  • Harsh Sharma

  • Honfung Wong +

  • Igor Gotlibovych +

  • Iqrar Agalosi Nureyza

  • Irv Lustig

  • Isaac Virshup

  • Jacob Peacock

  • Jacob Stevens-Haas +

  • Jan Müller +

  • Janus

  • Jeet Parekh

  • Jeff Hernandez +

  • Jeff Reback

  • Jiaxiang

  • Joao Pedro Berno Zanutto +

  • Joel Nothman

  • Joel Whittier +

  • John Karasinski +

  • John McGuigan +

  • Johnny Pribyl +

  • Jonas Laursen +

  • Jonathan Shreckengost +

  • Joris Van den Bossche

  • Jose +

  • JoseNavy +

  • Josh Temple +

  • Jun Kudo +

  • Justin Essert

  • Justin Sexton +

  • Kaiqi Dong

  • Kamil Trocewicz +

  • Karthik Mathur

  • Kashif +

  • Kenny Huynh

  • Kevin Sheppard

  • Kumar Shivam +

  • Leonardus Chen +

  • Levi Matus +

  • Lucas Rodés-Guirao +

  • Luis Pinto +

  • Lynch +

  • Marc Garcia

  • Marco Gorelli

  • Maria-Alexandra Ilie +

  • Marian Denes

  • Mark Graham +

  • Martin Durant

  • Matt Roeschke

  • Matthew Roeschke

  • Matthias Bussonnier

  • Maxim Ivanov +

  • Mayank Chaudhary +

  • MeeseeksMachine

  • Meghana Varanasi +

  • Metehan Kutlu +

  • Micael Jarniac +

  • Micah Smith +

  • Michael Marino

  • Miroslav Šedivý

  • Mohammad Jafar Mashhadi

  • Mohammed Kashif +

  • Nagesh Kumar C +

  • Nidhi Zare +

  • Nikhil Choudhary +

  • Number42

  • Oleh Kozynets +

  • OlivierLuG

  • Pandas 开发团队

  • Paolo Lammens +

  • Paul Ganssle

  • Pax +

  • Peter Liu +

  • Philip Cerles +

  • Pranjal Bhardwaj +

  • Prayag Savsani +

  • Purushothaman Srikanth +

  • Qbiwan +

  • Rahul Chauhan +

  • Rahul Sathanapalli +

  • Rajat Bishnoi +

  • Ray Bell

  • Reshama Shaikh +

  • Richard Shadrach

  • Robert Bradshaw

  • Robert de Vries

  • Rohith295

  • S Mono +

  • S.TAKENO +

  • Sahid Velji +

  • Sam Cohen +

  • Sam Ezebunandu +

  • Sander +

  • Sarthak +

  • Sarthak Vineet Kumar +

  • Satrio H Wicaksono +

  • Scott Lasley

  • Shao Yang Hong +

  • Sharon Woo +

  • Shubham Mehra +

  • Simon Hawkins

  • Sixuan (Cherie) Wu +

  • Souris Ash +

  • Steffen Rehberg

  • Suvayu Ali

  • Sven

  • SylvainLan +

  • T. JEGHAM +

  • Terji Petersen

  • Thomas Dickson +

  • Thomas Heavey +

  • Thomas Smith

  • Tobias Pitters

  • Tom Augspurger

  • Tomasz Sakrejda +

  • Torsten Wörtwein +

  • Ty Mick +

  • UrielMaD +

  • Uwe L. Korn

  • Vikramaditya Gaonkar +

  • VirosaLi +

  • W.R +

  • Warren White +

  • Wesley Boelrijk +

  • William Ayd

  • Yanxian Lin +

  • Yassir Karroum +

  • Yong Kai Yi +

  • Yuanhao Geng +

  • Yury Mikhaylov +

  • Yutaro Ikeda

  • Yuya Takashina +

  • Zach Brookler +

  • Zak Kohler +

  • ZhihuiChen0903 +

  • abmyii

  • alexhtn +

  • asharma13524 +

  • attack68

  • beanan +

  • chinhwee

  • cleconte987

  • danchev +

  • ebardie +

  • edwardkong

  • elliot rampono +

  • estasney +

  • gabicca

  • geetha-rangaswamaiah +

  • gfyoung

  • guru kiran

  • hardikpnsp +

  • icanhazcodeplz +

  • ivanovmg +

  • jbrockmendel

  • jeschwar

  • jnecus

  • joooeey +

  • junk +

  • krajatcl +

  • lacrosse91 +

  • leo +

  • lpkirwin +

  • lrjball

  • lucasrodes +

  • ma3da +

  • mavismonica +

  • mlondschien +

  • mzeitlin11 +

  • nguevara +

  • nrebena

  • parkdj1 +

  • partev

  • patrick

  • realead

  • rxxg +

  • samilAyoub +

  • sanderland

  • shawnbrown

  • sm1899 +

  • smartvinnetou

  • ssortman +

  • steveya +

  • taytzehao +

  • tiagohonorato +

  • timhunderwood

  • tkmz-n +

  • tnwei +

  • tpanza +

  • vineethraj510 +

  • vmdhhh +

  • xinrong-databricks +

  • yonas kassa +

  • yonashub +

  • Ádám Lippai +

1.1.5 版本的新特性(2020 年 12 月 7 日)

原文:pandas.pydata.org/docs/whatsnew/v1.1.5.html

这些是 pandas 1.1.5 版本的更改。查看发行说明以获取包括其他 pandas 版本的完整更改日志。

修复的回归

  • 修复了将类似时间间隔的标量加到DatetimeIndex时不正确引发的回归问题(GH 37295

  • 修复了当SeriesIndex的名称为元组时,调用Series.groupby()时引发的回归问题(GH 37755

  • 修复了在给定一维元组以从MultiIndex选择时,DataFrame.loc()Series.loc()__setitem__的回归问题(GH 37711

  • 修复了对带有 NumPy dtyped 操作数的ExtensionDtypeSeries进行原地操作时的回归问题(GH 37910

  • 修复了对groupby迭代器进行元数据传播时的回归问题(GH 37343

  • 修复了从DatetimeIndex构造的MultiIndex不保留频率的回归问题(GH 35563

  • 修复了在将具有 datetime64 值的SparseArray传递给Index构造函数时引发AttributeError的回归问题(GH 35843

  • 修复了在具有整数 dtype 的列中对DataFrame.unstack()的回归问题(GH 37115

  • 修复了在反序列化后对带有CategoricalDtypeSeries进行索引时的回归问题(GH 37631

  • 修复了在对象类型列中存在超出范围的日期时间对象时,DataFrame.groupby() 聚合的回归问题 (GH 36003)

  • 修复了在对标签进行分组时,当索引中存在标签时,df.groupby(..).rolling(..)生成的 MultiIndex 的回归问题 (GH 37641)

  • 修复了在其他操作(例如 DataFrame.pivot())之后未填充 NaNDataFrame.fillna() 的回归问题 (GH 36495).

  • 修复了df.groupby(..).rolling(..)中的性能回归问题 (GH 38038)

  • 修复了在至少一个索引具有重复项时,MultiIndex.intersection() 返回重复项的回归问题 (GH 36915)

  • 修复了DataFrameGroupBy.first()SeriesGroupBy.first()DataFrameGroupBy.last()SeriesGroupBy.last()在将None视为非 NA 值时的回归问题 (GH 38286) ## Bug 修复

  • Python 3.9 中 pytables 方法的错误 (GH 38041) ## 其他

  • 只在 CI 任务中设置 -Werror 作为编译器标志 (GH 33315, GH 33314) ## 贡献者

总共有 12 人为此版本提交了补丁。名字旁边有“+”符号的人第一次为此版本提交了补丁。

  • Andrew Wieteska

  • Fangchen Li

  • Janus

  • Joris Van den Bossche

  • Matthew Roeschke

  • MeeseeksMachine

  • Pandas 开发团队

  • Richard Shadrach

  • Simon Hawkins

  • Uwe L. Korn

  • jbrockmendel

  • patrick ## 修复的回归问题

  • 修复了将时间间隔标量添加到 DatetimeIndex 时错误地引发的回归问题 (GH 37295)

  • 修复了当SeriesIndex的名称为元组时,Series.groupby()引发异常的回归问题(GH 37755

  • 修复了在为MultiIndex选择一维元组进行__setitem__时,DataFrame.loc()Series.loc()上的回归问题(GH 37711

  • 修复了在使用带有 NumPy dtyped 操作数的ExtensionDtypeSeries上进行原地操作时的回归问题(GH 37910

  • 修复了对groupby迭代器进行元数据传播时的回归问题(GH 37343

  • 修复了从DatetimeIndex构造的MultiIndex不保留频率的回归问题(GH 35563

  • 修复了在将具有 datetime64 值的SparseArray传递给构造函数时,Index引发AttributeError的回归问题(GH 35843

  • 修复了具有整数数据类型的列的DataFrame.unstack()中的回归问题(GH 37115

  • 修复了在反序列化后使用CategoricalDtypeSeries进行索引时的回归问题(GH 37631

  • 修复了在对象数据类型列中存在越界日期时间对象时,DataFrame.groupby()聚合的回归问题(GH 36003

  • 修复了使用df.groupby(..).rolling(..)进行分组时,当按索引中的标签进行分组时,导致的结果MultiIndex的回归问题(GH 37641

  • 修复了DataFrame.fillna()在其他操作(如DataFrame.pivot())后未填充NaN的回归问题(GH 36495

  • 修复了df.groupby(..).rolling(..)中的性能退化(GH 38038

  • 修复了MultiIndex.intersection()中的回归问题,当索引中至少有一个重复项时返回重复项(GH 36915

  • 修复了DataFrameGroupBy.first()SeriesGroupBy.first()DataFrameGroupBy.last()SeriesGroupBy.last()中的回归问题,当None被视为非缺失值时(GH 38286

修复的 Bug

  • Python 3.9 中 pytables 方法的错误(GH 38041

其他

贡献者

共有 12 人为此版本贡献了补丁。名字旁边有“+”符号的人第一次贡献了补丁。

  • Andrew Wieteska

  • Fangchen Li

  • Janus

  • Joris Van den Bossche

  • Matthew Roeschke

  • MeeseeksMachine

  • Pandas 开发团队

  • Richard Shadrach

  • Simon Hawkins

  • Uwe L. Korn

  • jbrockmendel

  • patrick

1.1.4 新内容(2020 年 10 月 30 日)

原文:pandas.pydata.org/docs/whatsnew/v1.1.4.html

这些是 pandas 1.1.4 版本的更改。查看发布说明以获取包括其他 pandas 版本的完整更改日志。

修复的回归问题

  • 修复了当namesdict_keys类型时,read_csv()抛出ValueError的回归问题 (GH 36928)

  • 修复了read_csv()在指定了index_col参数且超过 100 万行时的回归问题 (GH 37094)

  • 修复了尝试变异DateOffset对象时不再引发AttributeError的回归问题 (GH 36940)

  • 修复了当传递位置参数以传递给聚合函数时,DataFrame.agg()会失败的回归问题 (GH 36948)

  • 修复了带有sort=False参数的RollingGroupby中未能被尊重的回归问题 (GH 36889)

  • 修复了Series.astype()方法在将None转换为"nan"时的回归问题 (GH 36904)

  • 修复了对只读数据的Series.rank()方法失败的回归问题 (GH 37290)

  • 修复了在RollingGroupby中导致索引为对象 dtype 时段错误的回归问题 (GH 36727)

  • 修复了当输入为DataFrame且仅评估了Series时,DataFrame.resample(...).apply(...)()引发AttributeError的回归问题 (GH 36951)

  • 修复了带有可空整数 dtype 的DataFrame.groupby(..).std()中的回归问题 (GH 37415)

  • 修复了PeriodDtype与其字符串表示形式的相等性和不相等性比较的回归问题 (GH 37265)

  • 修复了切片DatetimeIndex在不规则时间序列上出现 AssertionError 或在未排序索引上时引发的回归问题,带有 pd.NaT (GH 36953) 或未排序索引 (GH 35509)

  • 修复了某些偏移量的回归问题(pd.offsets.Day()及以下),不再可散列 (GH 37267)

  • 修复了 StataReader 中的回归,当使用迭代器读取数据集时,需要手动设置 chunksize (GH 37280)

  • 修复了与 DataFrame.iloc() 结合使用时的 setitem 回归问题,尝试在使用布尔列表进行筛选时设置值时引发错误 (GH 36741)

  • 修复了在将 Series 与 setitem 结合使用时,在设置值之前对齐的回归问题 (GH 37427)

  • 修复了 MultiIndex.is_monotonic_increasing 在至少一个级别中出现 NaN 时返回错误结果的回归问题 (GH 37220)

  • 修复了对 Series 的就地算术操作(+=)不更新父 DataFrame/Series 的回归问题 (GH 36373) ## 问题修复

  • Bug causing groupby(...).sum() 和类似操作不保留元数据 (GH 29442)

  • Series.isin()DataFrame.isin() 中的 Bug 在目标为只读时引发 ValueError (GH 37174)

  • DataFrameGroupBy.fillna()SeriesGroupBy.fillna() 中的 Bug 在 1.0.5 之后引入了性能回归 (GH 36757)

  • DataFrame.info() 中的 Bug 在 DataFrame 具有整数列名时引发 KeyError (GH 37245)

  • DataFrameGroupby.apply()中的错误会在分组时删除CategoricalIndex([GH 35792](https://github.com/pandas-dev/pandas/issues/35792) ## 贡献者

总共有 18 人为此版本贡献了补丁。名字后面带有“+”的人第一次贡献了补丁。

  • Daniel Saxton

  • Fangchen Li

  • Janus +

  • Joris Van den Bossche

  • Kevin Sheppard

  • Marco Gorelli

  • Matt Roeschke

  • Matthew Roeschke

  • MeeseeksMachine

  • Pandas 开发团队

  • Paul Ganssle

  • Richard Shadrach

  • Simon Hawkins

  • Thomas Smith

  • Tobias Pitters

  • abmyii +

  • jbrockmendel

  • patrick ## 修复的回归问题

  • 修复了read_csv()方法在namesdict_keys类型时引发ValueError的回归问题(GH 36928

  • 修复了read_csv()在超过 100 万行并指定index_col参数时的回归问题(GH 37094

  • 修复了尝试改变DateOffset对象时不再引发AttributeError的回归问题(GH 36940

  • 修复了DataFrame.agg()在传递给聚合函数的位置参数时会失败并引发TypeError的回归问题(GH 36948)。

  • 修复了RollingGroupbysort=False未被尊重的回归问题(GH 36889

  • 修复了Series.astype()None转换为"nan"时转换为字符串时的回���问题(GH 36904

  • 修复了Series.rank()方法在只读数据上失败的回归问题(GH 37290

  • 修复了RollingGroupby在对象 dtype 的索引下导致分段错误的回归问题(GH 36727

  • 修复了DataFrame.resample(...).apply(...)()在输入为DataFrame且仅评估Series时引发AttributeError的回归问题(GH 36951

  • 修复了带有可空整数 dtype 的DataFrame.groupby(..).std()的回归问题(GH 37415

  • 修复了PeriodDtype在比较相等和不相等时与其字符串表示形式的回归问题(GH 37265)

  • 修复了在不规则时间序列上切片 DatetimeIndex 或未排序索引时引发 AssertionError 的回归问题(GH 36953GH 35509)

  • 修复了某些偏移量(pd.offsets.Day()及以下)不再可哈希的回归问题(GH 37267)

  • 修复了使用迭代器读取数据集时,需要手动设置 chunksizeStataReader 的回归问题(GH 37280)

  • 修复了在使用布尔列表过滤时尝试设置值时引发错误的 DataFrame.iloc() 的回归问题(GH 36741)

  • 修复了设置一系列值之前对齐 Series 的回归问题(GH 37427)

  • 修复了 MultiIndex.is_monotonic_increasing 在至少一个级别中存在 NaN 时返回错误结果的回归问题(GH 37220)

  • 修复了对 Series 进行就地算术运算(+=)时未更新父 DataFrame/Series 的回归问题(GH 36373)

Bug fixes

  • 导致 groupby(...).sum() 和类似方法不保留元数据的错误已修复(GH 29442)

  • 当目标是只读时,Series.isin()DataFrame.isin() 引发 ValueError 的错误已修复(GH 37174)

  • DataFrameGroupBy.fillna()SeriesGroupBy.fillna() 中引入的性能回归问题已在 1.0.5 之后修复(GH 36757)

  • DataFrame.info() 中存在的 Bug,在 DataFrame 有整数列名时引发了 KeyError (GH 37245)

  • DataFrameGroupby.apply() 中存在的 Bug 会在分组时丢弃 CategoricalIndex (GH 35792)

贡献者

总共有 18 人对此版本进行了贡献。名字后面带有“+”的人第一次贡献了一个补丁。

  • Daniel Saxton

  • Fangchen Li

  • Janus +

  • Joris Van den Bossche

  • Kevin Sheppard

  • Marco Gorelli

  • Matt Roeschke

  • Matthew Roeschke

  • MeeseeksMachine

  • Pandas 开发团队

  • Paul Ganssle

  • Richard Shadrach

  • Simon Hawkins

  • Thomas Smith

  • Tobias Pitters

  • abmyii +

  • jbrockmendel

  • patrick

posted @ 2024-06-26 10:33  绝不原创的飞龙  阅读(1)  评论(0编辑  收藏  举报