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

Pandas 2.2 中文文档(四十五)

原文:pandas.pydata.org/docs/

新特性 1.3.5(2021 年 12 月 12 日)

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

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

修复的回归问题

  • 修复了在比较浮点数与对象数据类型的 Series.equals() 中的回归问题,与 None 比较时 (GH 44190)

  • 修复了 merge_asof() 中的回归问题,当数组作为连接键提供时引发错误(GH 42844

  • 修复了在使用 DateTimeIndex 为空组和 uint8uint16uint32 列重新采样 DataFrame 时引发 RuntimeError 的回归问题 (GH 43329)

  • 修复了在在夏令时转换附近创建一个时区感知的 Timestamp 标量的 DataFrame 的回归问题 (GH 42505)

  • 修复了在 read_csv() 中的性能回归问题 (GH 44106)

  • 修复了在 Series.duplicated()Series.drop_duplicates() 中的回归问题,当 Series 具有 Categorical 数据类型且具有布尔类别时 (GH 44351)

  • 修复了在 DataFrameGroupBy.sum()SeriesGroupBy.sum() 中的回归问题,timedelta64[ns] 数据类型包含 NaT 时未能将该值视为 NA (GH 42659)

  • 修复了当 RollingGroupby.cov()RollingGroupby.corr() 中的 other 与每个组的形状相同时,结果中会错误返回多余组的回归问题 (GH 42915) ## 贡献者

总共有 10 人对此版本做出了贡献。带有“+”符号的人首次为此版本做出了贡献。

  • Ali McMaster

  • Matthew Roeschke

  • Matthew Zeitlin

  • MeeseeksMachine

  • Pandas 开发团队

  • Patrick Hoefler

  • Simon Hawkins

  • Thomas Li

  • Tobias Pitters

  • jbrockmendel ## 修复的回归问题

  • 修复了在Series.equals()中的回归问题,当将 dtype 为 object 的浮点数与 None 进行比较时(GH 44190

  • 修复了在提供数组作为连接键时,merge_asof()引发错误的回归问题(GH 42844

  • 修复了在使用DateTimeIndexDataFrame进行重采样时的回归问题,当存在空组和uint8uint16uint32列时,错误地引发RuntimeErrorGH 43329

  • 修复了在从时区感知的Timestamp标量创建DataFrame时,接近夏令时转换的回归问题(GH 42505

  • 修复了在read_csv()中的性能回归问题(GH 44106

  • 修复了在Series.duplicated()Series.drop_duplicates()中的回归问题,当 Series 具有布尔类别的Categorical dtype 时(GH 44351

  • 修复了在DataFrameGroupBy.sum()SeriesGroupBy.sum()中的回归问题,当包含NaTtimedelta64[ns] dtype 时未能将该值视为 NA(GH 42659

  • 修复了在RollingGroupby.cov()RollingGroupby.corr()中的回归问题,当other与每个组的形状相同时,结果中会错误返回多余的组(GH 42915

贡献者

总共有 10 人对这个版本做出了贡献。名字后面带有“+”符号的人是第一次为该版本贡献代码。

  • Ali McMaster

  • Matthew Roeschke

  • Matthew Zeitlin

  • MeeseeksMachine

  • Pandas 开发团队

  • Patrick Hoefler

  • Simon Hawkins

  • Thomas Li

  • Tobias Pitters

  • jbrockmendel

1.3.4 版本的新功能(2021 年 10 月 17 日)

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

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

修复的回归

  • 修复了DataFrame.convert_dtypes()中错误地将字节字符串转换为字符串的回归(GH 43183

  • 修复了DataFrameGroupBy.agg()SeriesGroupBy.agg()axis=1MultiIndex上以混合数据类型失败时静默失败的回归(GH 43209

  • 修复了带有整数和NaN键的merge()outer合并时失败的回归(GH 43550

  • 修复了在 32 位平台上使用method="spearman"DataFrame.corr()引发ValueError的回归(GH 43588

  • 修复了MultiIndex.equals()中的性能回归(GH 43549

  • 修复了在DataFrameGroupBy.first()SeriesGroupBy.first()DataFrameGroupBy.last()SeriesGroupBy.last()中的性能回归,以及与StringDtype一起的回归(GH 41596)

  • 修复了Series.cat.reorder_categories()中未能更新Series上类别的回归(GH 43232

  • 修复了在Series.cat.categories()设置器上失败更新Series上类别的回归(GH 43334

  • 修复了在read_csv()中的回归,在memory_map=True时引发UnicodeDecodeError异常的问题(GH 43540

  • 修复了在column不是字符串的任何标量时引发AssertionErrorDataFrame.explode()中的回归(GH 43314

  • 修复了在某些情况下尝试多次传递argskwargs给用户提供的funcSeries.aggregate()中的回归(GH 43357

  • 修复了迭代DataFrame.groupby.rolling对象时的回归,导致如果输入的分组未排序,则结果 DataFrame 的索引不正确(GH 43386

  • 修复了在输入分组未排序时,DataFrame.groupby.rolling.cov()DataFrame.groupby.rolling.corr()计算结果不正确的回归(GH 43386

  • 修复了在pandas.DataFrame.groupby.rolling()pandas.api.indexers.FixedForwardWindowIndexer中导致 segfaults 和窗口端点混合在组间的 bug(GH 43267

  • 修复了具有NaT值的 datetimelike 值的DataFrameGroupBy.mean()SeriesGroupBy.mean()返回不正确结果的 bug(GH 43132

  • 修复了在某些情况下未将第一个args传递给用户提供的funcSeries.aggregate()中的 bug(GH 43357

  • 修复了Series.rolling.quantile()Series.rolling.median()中的内存泄漏问题(GH 43339

  • 编译 pandas 所需的最低版本的 Cython 现在是 0.29.24 (GH 43729) ## 贡献者

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

  • Alexey Györi +

  • DSM

  • Irv Lustig

  • Jeff Reback

  • Julien de la Bruère-T +

  • Matthew Zeitlin

  • MeeseeksMachine

  • Pandas 开发团队

  • Patrick Hoefler

  • Richard Shadrach

  • Shoham Debnath

  • Simon Hawkins

  • Thomas Li

  • aptalca +

  • jbrockmendel

  • michal-gh +

  • realead ## 修复的回归

  • 修复了 DataFrame.convert_dtypes() 中错误地将字节���符串转换为字符串的回归 (GH 43183)

  • 修复了在 axis=1 上沿着 MultiIndex 失败的情况下,DataFrameGroupBy.agg()SeriesGroupBy.agg() 会静默失败的回归 (GH 43209)

  • 修复了在整数和 NaN 键上使用 outer 合并时 merge() 失败的回归 (GH 43550)

  • 修复了在 32 位平台上使用 method="spearman"DataFrame.corr() 出现 ValueError 的回归 (GH 43588)

  • 修复了 MultiIndex.equals() 中的性能回归 (GH 43549)

  • 修复了在 StringDtype 中的性能回归,DataFrameGroupBy.first()SeriesGroupBy.first()DataFrameGroupBy.last()SeriesGroupBy.last() (GH 41596)

  • 修复了在Series.cat.reorder_categories()中的回归,未能更新Series上的类别(GH 43232

  • 修复了在Series.cat.categories()的设置器中的回归,未能更新Series上的类别(GH 43334

  • 修复了在read_csv()中的回归,当memory_map=True时引发UnicodeDecodeError异常(GH 43540

  • 修复了在DataFrame.explode()中的回归,在column是任何不是字符串的标量时引发AssertionErrorGH 43314

  • 修复了在Series.aggregate()中的回归,尝试在某些情况下多次传递argskwargs到用户提供的func时(GH 43357

  • 修复了在迭代DataFrame.groupby.rolling对象时的回归,导致结果 DataFrame 具有不正确的索引,如果输入分组未排序(GH 43386

  • 修复了DataFrame.groupby.rolling.cov()DataFrame.groupby.rolling.corr()中的回归,在输入分组未排序时计算不正确的结果(GH 43386

Bug fixes

  • 修复了pandas.DataFrame.groupby.rolling()pandas.api.indexers.FixedForwardWindowIndexer中的 bug,导致 segfaults 和窗口端点在组之间混合(GH 43267

  • 修复了DataFrameGroupBy.mean()SeriesGroupBy.mean()中的 bug,包括NaT值的 datetimelike 值返回不正确的结果(GH 43132

  • 修复了Series.aggregate()中在某些情况下未将第一个args传递给用户提供的func的错误 (GH 43357)

  • 修复了Series.rolling.quantile()Series.rolling.median()中的内存泄漏问题 (GH 43339)

其他

  • 编译 pandas 所需的 Cython 的最低版本现在是0.29.24 (GH 43729)

贡献者

总共有 17 人为这个版本贡献了补丁。名字旁边带有“+”符号的人是第一次贡献补丁的。

  • Alexey Györi +

  • DSM

  • Irv Lustig

  • Jeff Reback

  • Julien de la Bruère-T +

  • Matthew Zeitlin

  • MeeseeksMachine

  • Pandas 开发团队

  • Patrick Hoefler

  • Richard Shadrach

  • Shoham Debnath

  • Simon Hawkins

  • Thomas Li

  • aptalca +

  • jbrockmendel

  • michal-gh +

  • realead

1.3.3 中的新功能(2021 年 9 月 12 日)

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

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

修复的回归问题

  • 修复了DataFrame构造函数在为定义的Index和长度为一的Timestamp列表广播时失败的问题(GH 42810)

  • 修复了DataFrameGroupBy.agg()SeriesGroupBy.agg()在某些情况下错误地引发异常的问题(GH 42390)

  • 修复了DataFrameGroupBy.apply()SeriesGroupBy.apply()中即使dropna=False也会删除nan值的回归问题(GH 43205)

  • 修复了DataFrameGroupBy.quantile()SeriesGroupBy.quantile()中的回归问题,这些问题在使用pandas.NA时失败(GH 42849)

  • 修复了merge()中的回归问题,on列具有ExtensionDtypebool数据类型时,在rightouter合并中被转换为objectGH 40073)

  • 修复了RangeIndex.where()RangeIndex.putmask()在结果不表示RangeIndex时引发AssertionError的回归问题(GH 43240)

  • 修复了read_parquet()中的回归问题,其中fastparquet引擎在 fastparquet 0.7.0 中无法正常工作(GH 43075)

  • 修复了DataFrame.loc.__setitem__()在将数组设置为单元格值时引发ValueError的回归问题 (GH 43422)

  • 修复了is_list_like()在对象的__iter__设置为None时被识别为可迭代的回归问题 (GH 43373)

  • 修复了DataFrame.__getitem__()对非单调索引的 DatetimeIndex 的切片引发错误的回归问题 (GH 43223)

  • 修复了Resampler.aggregate()在列选择后使用时的回归问题,如果func是聚合函数的列表,则会引发错误(GH 42905

  • 修复了DataFrame.corr()中 Kendall 相关性会对具有重复值的列产生不正确结果的回归问题(GH 43401

  • 修复了DataFrame.groupby()在具有对象类型的列上进行聚合时,导致这些列的结果丢失的回归问题 (GH 42395, GH 43108)

  • 修复了Series.fillna()在用无法无损转换的数据类型(如用float64填充的float32)填充float类型的Series时引发TypeError的回归问题 (GH 43424)

  • 修复了read_csv()在文件句柄为tempfile.SpooledTemporaryFile对象时引发AttributeError的回归问题 (GH 43439)

  • 修复了core.window.ewm.ExponentialMovingWindow.mean()中性能回归问题 (GH 42333) ## 性能改进

  • DataFrame.__setitem__()中,当键或值不是 DataFrame 或键不是类似列表时,性能得到改进 (GH 43274) ## 问题修复

  • 修复了在DataFrameGroupBy.agg()DataFrameGroupBy.transform()中使用engine="numba"时,index数据未正确传递给func的错误(GH 43133) ## 贡献者

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

  • Ali McMaster

  • Irv Lustig

  • Matthew Roeschke

  • Matthew Zeitlin

  • MeeseeksMachine

  • Pandas 开发团队

  • Patrick Hoefler

  • Prerana Chakraborty +

  • Richard Shadrach

  • Shoham Debnath

  • Simon Hawkins

  • Thomas Li

  • Torsten Wörtwein

  • Zach Rait +

  • aiudirog +

  • attack68

  • jbrockmendel

  • suoniq + ## 修复的回归

  • 修复了在DataFrame构造函数中定义的Index和长度为一的Timestamp列表广播失败的回归(GH 42810)

  • 修复了DataFrameGroupBy.agg()SeriesGroupBy.agg()在某些情况下错误地引发的回归(GH 42390)

  • 修复了DataFrameGroupBy.apply()SeriesGroupBy.apply()中即���dropna=False也会删除nan值的回归(GH 43205)

  • 修复了DataFrameGroupBy.quantile()SeriesGroupBy.quantile()在使用pandas.NA时失败的回归(GH 42849)

  • 修复了merge()中的回归问题,其中具有ExtensionDtypebool数据类型的on列在rightouter合并中被转换为objectGH 40073)

  • 修复了RangeIndex.where()RangeIndex.putmask()中的回归问题,当结果不表示RangeIndex时引发AssertionErrorGH 43240)

  • 修复了read_parquet()中的回归问题,其中 fastparquet 引擎在 fastparquet 0.7.0 中无法正常工作(GH 43075)

  • 修复了DataFrame.loc.__setitem__()中的回归问题,当将数组设置为单元格值时引发ValueErrorGH 43422)

  • 修复了is_list_like()中的回归问题,其中将__iter__设置为None的对象被识别为可迭代对象(GH 43373)

  • 修复了DataFrame.__getitem__()中的回归问题,当索引非单调时,对DatetimeIndex的切片引发错误(GH 43223)

  • 修复了Resampler.aggregate()中的回归问题,当在列选择后使用时,如果func是一组聚合函数,则会引发错误(GH 42905)

  • 修复了DataFrame.corr()中的回归问题,其中 Kendall 相关性会对具有重复值的列产生不正确的结果(GH 43401)

  • 修复了DataFrame.groupby()中的回归问题,其中对具有对象类型的列进行聚合会丢失这些列的结果(GH 42395, GH 43108)

  • 修复了Series.fillna()中的回归问题,当使用无法无损转换的 dtype(例如用float64填充的float32)填充float Series时引发TypeErrorGH 43424)

  • 修复了read_csv()中的回归问题,当文件句柄是tempfile.SpooledTemporaryFile对象时引发AttributeErrorGH 43439

  • 修复了core.window.ewm.ExponentialMovingWindow.mean()中的性能回归(GH 42333

性能改进

  • DataFrame.__setitem__()的键或值不是DataFrame时,或者键不是类似列表时,对性能进行了改进(GH 43274

Bug 修复

  • 修复了DataFrameGroupBy.agg()DataFrameGroupBy.transform()engine="numba"的 bug,其中index数据没有被正确传递给funcGH 43133

贡献者

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

  • Ali McMaster

  • Irv Lustig

  • Matthew Roeschke

  • Matthew Zeitlin

  • MeeseeksMachine

  • Pandas 开发团队

  • Patrick Hoefler

  • Prerana Chakraborty +

  • Richard Shadrach

  • Shoham Debnath

  • Simon Hawkins

  • Thomas Li

  • Torsten Wörtwein

  • Zach Rait +

  • aiudirog +

  • attack68

  • jbrockmendel

  • suoniq +

1.3.2 版本的新功能 (2021 年 8 月 15 日)

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

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

修复的回归

  • 在可空数据类型的DataFrame.isin()Series.isin()中的性能回归 (GH 42714)

  • 使用通过DataFrame.pop()创建的布尔索引更新Series的值时出现的回归已修复 (GH 42530)

  • DataFrame.from_records()中的回归,当记录为空时 (GH 42456)

  • 在通过切片连接创建的 DataFrame 进行移位并填充值时,DataFrame.shift()中发生TypeError的回归已修复 (GH 42719)

  • func参数返回列表且axis=1时的DataFrame.agg()中的回归 (GH 42727)

  • DataFrame.drop()中的回归,如果MultiIndex存在重复并且索引器是元组或元组列表时不起作用 (GH 42771)

  • 修复了read_csv()在参数namesprefix都设置为None时引发ValueError的回归 (GH 42387)

  • Timestamp对象和纳秒datetime64对象之间的比较中修复了回归,超出了纳秒datetime64的实现范围 (GH 42794)

  • 修复了 Styler.highlight_min()Styler.highlight_max() 中的回归问题,pandas.NA 未能成功忽略 (GH 42650)

  • 修复了 concat() 中的回归问题,在 axis=1 Series 连接时未遵守 copy=False (GH 42501)

  • Series.nlargest()Series.nsmallest() 中的回归问题,具有可空整数或浮点数 dtype (GH 42816)

  • 修复了 Series.quantile() 中与 Int64Dtype 相关的回归问题 (GH 42626)

  • 修复了 Series.groupby()DataFrame.groupby() 中的回归问题,使用元组命名的 Series 作为 by 参数会错误地引发异常 (GH 42731) ## Bug fixes

  • read_excel() 中的 Bug 在读取具有重复列的文件时修改了 dtypes 字典 (GH 42462)

  • 对扩展类型的 1D 切片变成了 ExtensionArrays 上的 N 维切片 (GH 42430)

  • 修复了 Series.rolling()DataFrame.rolling() 中的 Bug,在 center=Truewindow 覆盖所有行的偏移量时,第一行未正确计算窗口边界 (GH 42753)

  • Styler.hide_columns() 现在隐藏索引名称标题行以及列标题(GH 42101)

  • Styler.set_sticky()已修改 CSS 以控制列/索引名称,并确保正确的粘性位置(GH 42537

  • 在 PYTHONOPTIMIZED 模式下反序列化日期时间索引时出现的错误(GH 42866) ## 贡献者

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

  • Alexander Gorodetsky +

  • Fangchen Li

  • Fred Reiss

  • Justin McOmie +

  • Matthew Zeitlin

  • MeeseeksMachine

  • Pandas 开发团队

  • Patrick Hoefler

  • Richard Shadrach

  • Shoham Debnath

  • Simon Hawkins

  • Thomas Li

  • Wenjun Si

  • attack68

  • dicristina +

  • jbrockmendel ## 修复的回归问题

  • 在可空数据类型的情况下,DataFrame.isin()Series.isin()中的性能回归问题 (GH 42714)

  • 使用通过DataFrame.pop()创建的布尔索引更新Series值时的回归问题 (GH 42530)

  • DataFrame.from_records()中的回归问题,记录为空时 (GH 42456)

  • 在通过切片连接创建 DataFrame 并填充值时,DataFrame.shift()中的回归问题,出现TypeError (GH 42719)

  • func参数返回列表且axis=1时,DataFrame.agg()中的回归问题(GH 42727)

  • MultiIndex存在重复项且索引器是元组或元组列表时,DataFrame.drop()中的回归问题不起作用 (GH 42771)

  • 修复了read_csv()在参数namesprefix都设置为None时引发ValueError的回归问题(GH 42387)

  • 修复了 Timestamp 对象与纳秒 datetime64 对象之间的比较中出现超出实现范围的回归问题(GH 42794

  • 修复了 Styler.highlight_min()Styler.highlight_max() 中的一个回归 bug,pandas.NA 未能被成功忽略(GH 42650

  • 修复了concat()中的一个 bug,copy=Falseaxis=1 Series 连接时未被尊重(GH 42501

  • Series.nlargest()Series.nsmallest() 中的一个回归 bug,当可空整数或浮点数 dtype 时引起了回归(GH 42816

  • 修复了Series.quantile()中的一个 bug,与 Int64Dtype 进行比较时出现回归问题(GH 42626

  • 修复了Series.groupby()DataFrame.groupby()中的一个 bug,使用一个以元组命名的 Series 作为 by 参数会错误地引发异常(GH 42731

Bug 修复

  • read_excel() 中的一个 bug 修改了读取具有重复列的文件时的 dtypes 字典(GH 42462

  • 1D 扩展类型的切片变成了扩展数组的 N 维切片(GH 42430

  • 修复了Series.rolling()DataFrame.rolling()中的一个 bug,当center=Truewindow是覆盖所有行的偏移时,第一行没有正确计算窗口边界(GH 42753

  • Styler.hide_columns()现在隐藏了索引名称头行以及列标题(GH 42101

  • Styler.set_sticky()已经修改了 CSS 以控制列/索引名称,并确保正确的粘性位置(GH 42537

  • 在 PYTHONOPTIMIZED 模式下反序列化日期时间索引的错误(GH 42866)

贡献者

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

  • Alexander Gorodetsky +

  • Fangchen Li

  • Fred Reiss

  • Justin McOmie +

  • Matthew Zeitlin

  • MeeseeksMachine

  • Pandas 开发团队

  • Patrick Hoefler

  • Richard Shadrach

  • Shoham Debnath

  • Simon Hawkins

  • Thomas Li

  • Wenjun Si

  • attack68

  • dicristina +

  • jbrockmendel

1.3.1 中的新功能(2021 年 7 月 25 日)

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

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

修复的回归

  • 无法在 PyPy 上构建 Pandas (GH 42355)

  • 使用旧版本的 pandas 构建的 DataFrame 无法被反序列化 (GH 42345)

  • 从字典的字典构建 DataFrame 的性能回归 (GH 42248)

  • 修复了 DataFrame.agg() 中的回归,在 DataFrame 具有扩展数组 dtype、重复索引和 axis=1 时丢失值 (GH 42380)

  • 修复了 DataFrame.astype() 中的回归,改变了非连续数据的顺序(GH 42396)

  • 在需要转换的缩减操作中,DataFrame 中的性能回归,例如在整数数据上执行 DataFrame.mean() 时(GH 38592)

  • orient 参数为“records”, “dict”, 或 “split” 时,DataFrame.to_dict()Series.to_dict() 中的性能回归 (GH 42352)

  • 在使用 list 子类进行索引时不正确地引发 TypeError 的回归已修复 (GH 42433, GH 42461)

  • 修复了 DataFrame.isin()Series.isin() 中的回归,当包含至少一个缺失值的可空数据时引发 TypeError (GH 42405)

  • 在具有布尔 dtype 和整数 dtype 的对象之间的 concat() 中,将其转换为对象而不是整数的回归已修复 (GH 42092)

  • Series 构造函数不接受 dask.Array 的 bug (GH 38645)

  • 修复了SettingWithCopyWarning显示错误 stacklevel 的回归问题 (GH 42570)

  • 修复了merge_asof()by 列之一在索引中时引发 KeyError 的回归问题 (GH 34488)

  • 修复了to_datetime()cache=True 时返回 pd.NaT 的回归问题 (GH 42259)

  • 修复了SeriesGroupBy.value_counts()在对只有一行的 Series 调用时导致 IndexError 的回归问题 (GH 42618) ## Bug 修复

  • 修复了DataFrame.transpose()在 DataFrame 具有扩展数组数据类型和重复索引时丢失值的 bug (GH 42380)

  • 修复了DataFrame.to_xml()在使用 index=False 和偏移索引调用时引发 KeyError 的 bug (GH 42458)

  • 修复了Styler.set_sticky()对于单索引列情况下未正确处理索引名称的 bug (GH 42537)

  • 修复了DataFrame.copy()在结果中未合并块的 bug (GH 42579) ## 贡献者

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

  • Fangchen Li

  • GYvan +

  • Matthew Roeschke

  • Matthew Zeitlin

  • MeeseeksMachine

  • Pandas 开发团队

  • Patrick Hoefler

  • Richard Shadrach

  • Shoham Debnath +

  • Simon Hawkins

  • Stephan Heßelmann +

  • Stephen +

  • Thomas Li

  • Zheyuan +

  • attack68

  • jbrockmendel

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

  • Pandas 无法在 PyPy 上构建 (GH 42355)

  • 使用旧版本的 pandas 构建的 DataFrame 无法被反序列化 (GH 42345)

  • 在从字典的字典构造DataFrame时存在性能回归(GH 42248)

  • 修复了DataFrame.agg()中的回归,在 DataFrame 具有扩展数组 dtype、重复索引和axis=1时丢失值(GH 42380)

  • 修复了DataFrame.astype()中更改非连续数据顺序的回归(GH 42396)

  • 在需要转换的减少操作中存在DataFrame中的性能回归,例如对整数数据进行DataFrame.mean()GH 38592)

  • DataFrame.to_dict()Series.to_dict()中存在性能回归,当orient参数为“records”、“dict”或“split”之一时(GH 42352)

  • 修复了使用list子类进行索引时引发TypeError的回归(GH 42433, GH 42461)

  • 修复了在包含至少一个缺失值的可空数据中,DataFrame.isin()Series.isin()引发TypeError的回归(GH 42405)

  • 在具有布尔 dtype 和整数 dtype 的对象之间的concat()中存在回归,将其转换为对象而不是整数(GH 42092)

  • Series构造函数中不接受dask.Array的错误(GH 38645)

  • 修复了SettingWithCopyWarning显示不正确的 stacklevel 的回归(GH 42570)

  • 修复了merge_asof()中的回归,当by列之一在索引中时引发KeyErrorGH 34488)

  • 修复了 to_datetime() 返回 pd.NaT 的回归,当 cache=True 时产生重复值的输入时 (GH 42259)

  • 修复了 SeriesGroupBy.value_counts() 中的回归,当在只有一行的 Series 上调用时导致 IndexError 的问题(GH 42618

问题修复

  • 修复了当 DataFrame 具有扩展数组 dtype 和重复索引时,DataFrame.transpose() 丢弃值的错误(GH 42380

  • 修复了 DataFrame.to_xml() 中的 bug,在使用 index=False 和偏移索引调用时引发 KeyError 的问题 (GH 42458)

  • 修复了 Styler.set_sticky() 中的 bug,未正确处理单索引列情况下的索引名称 (GH 42537)

  • 修复了 DataFrame.copy() 中的 bug,未能在结果中合并块 (GH 42579)

贡献者

本次发布共有 17 人贡献了补丁。名字后面带有“+”的人是首次贡献补丁的。

  • Fangchen Li

  • GYvan +

  • Matthew Roeschke

  • Matthew Zeitlin

  • MeeseeksMachine

  • Pandas 开发团队

  • Patrick Hoefler

  • Richard Shadrach

  • Shoham Debnath +

  • Simon Hawkins

  • Stephan Heßelmann +

  • Stephen +

  • Thomas Li

  • Zheyuan +

  • attack68

  • jbrockmendel

  • neelmraman +

1.3.0 中的新内容(2021 年 7 月 2 日)

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

这些是 pandas 1.3.0 的变化。 有关包括 pandas 其他版本的完整更改日志,请参阅 Release notes。

警告

当读取新的 Excel 2007+(.xlsx)文件时,默认参数engine=None将在选项io.excel.xlsx.reader设置为"auto"时在所有情况下使用openpyxl引擎。 以前,某些情况下将使用xlrd引擎。 有关此更改的背景,请参阅 What’s new 1.2.0。

Enhancements

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

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

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

我们添加了对使用`read_xml()`和`DataFrame.to_xml()`读取和呈现浅版本的[XML](https://www.w3.org/standards/xml/core)文档的 I/O 支持。 使用[lxml](https://lxml.de)作为解析器,XPath 1.0 和 XSLT 1.0 都可用([GH 27554](https://github.com/pandas-dev/pandas/issues/27554))。

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

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

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

更多内容,请参阅 IO 工具用户指南中的 Writing XML。 ### Styler 增强

我们在Styler上进行了一些重点开发。请参阅已修订和改进的 Styler 文档(GH 39720, GH 39317, GH 40493)。

  • 方法Styler.set_table_styles()现在可以接受更自然的 CSS 语言作为参数,例如'color:red;'而不是[('color', 'red')]GH 39563)。
  • 方法 Styler.highlight_null()Styler.highlight_min()Styler.highlight_max() 现在允许自定义 CSS 高亮而不是默认的背景着色(GH 40242
  • Styler.apply() 现在接受在 axis=None 时返回 ndarray 的函数,使其与 axis=0axis=1 的行为一致(GH 39359
  • 当通过 Styler.apply()Styler.applymap() 提供格式不正确的 CSS 时,在渲染时现在会引发错误(GH 39660
  • Styler.format() 现在接受关键字参数 escape 用于可选的 HTML 和 LaTeX 转义(GH 40388, GH 41619
  • Styler.background_gradient() 增加了参数 gmap 来提供特定的渐变映射进行着色(GH 22727
  • Styler.clear() 现在还清除了 Styler.hidden_indexStyler.hidden_columnsGH 40484
  • 添加了方法 Styler.highlight_between()GH 39821
  • 添加了方法 Styler.highlight_quantile()GH 40926
  • 添加了方法 Styler.text_gradient() (GH 41098)
  • 添加了方法 Styler.set_tooltips(),以允许悬停工具提示;这可以增强交互式显示 (GH 21266, GH 40284)
  • 添加了参数 precision 到方法 Styler.format() 以控制浮点数的显示 (GH 40134)
  • Styler 渲染的 HTML 输出现在遵循 w3 HTML Style Guide (GH 39626)
  • Styler 类的许多功能现在部分或完全可用于具有非唯一索引或列的 DataFrame (GH 41143)
  • 通过分别对索引或列进行稀疏化使用 new styler options,可更好地控制显示,这些选项也可以通过 option_context() 使用 (GH 41142)
  • 添加了选项 styler.render.max_elements,以避免对大型 DataFrame 进行样式设置时浏览器过载 (GH 40712)
  • 添加了方法 Styler.to_latex() (GH 21673, GH 42320),这也允许一些有限的 CSS 转换 (GH 40731)
  • 添加了方法 Styler.to_html() (GH 13379)
  • 添加了方法 Styler.set_sticky(),以使索引和列标题在滚动 HTML 框架中永久可见 (GH 29072) ### DataFrame 构造函数遵循 copy=False

当将字典传递给 DataFramecopy=False 时,将不再进行复制 (GH 32960)。

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

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

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

df["A"] 仍然是 arr 的视图:

In [4]: arr[0] = 0

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

当未传递 copy 参数时,默认行为将保持不变,即会进行复制。### 基于 PyArrow 的字符串数据类型

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

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

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

警告

string[pyarrow] 目前被视为实验性功能。实现和部分 API 可能会在无警告的情况下发生更改。

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

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

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

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

您还可以使用 pandas 选项创建基于 PyArrow 的字符串数组。

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

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

通常的字符串访问器方法有效。在适当的情况下,DataFrame 的 Series 或列的返回类型也将具有字符串 dtype。

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

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

返回整数的字符串访问器方法将返回具有 Int64Dtype 的值。

In [13]: s.str.count("a")
Out[13]: 
0       1
1    <NA>
2       0
dtype: Int64 
```  ### 居中的日期时间滚动窗口

在 DataFrame 和 Series 对象上执行滚动计算时,现在可以使用居中的日期时间窗口 ([GH 38780](https://github.com/pandas-dev/pandas/issues/38780))。例如:

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

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

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

+   `DataFrame.rolling()`、`Series.rolling()`、`DataFrame.expanding()` 和 `Series.expanding()` 现在支持 `method` 参数,并提供了一个 `'table'` 选项,可对整个 `DataFrame` 执行窗口操作。参见窗口概述以获取性能和功能上的优势([GH 15095](https://github.com/pandas-dev/pandas/issues/15095),[GH 38995](https://github.com/pandas-dev/pandas/issues/38995))

+   `ExponentialMovingWindow` 现在支持一个 `online` 方法,可以以在线方式执行 `mean` 计算。参见窗口概述([GH 41673](https://github.com/pandas-dev/pandas/issues/41673))

+   添加了 `MultiIndex.dtypes()`([GH 37062](https://github.com/pandas-dev/pandas/issues/37062))

+   在 `DataFrame.resample()` 的 `origin` 参数中添加了 `end` 和 `end_day` 选项([GH 37804](https://github.com/pandas-dev/pandas/issues/37804))

+   在 `read_csv()` 和 `engine="c"` 时,当 `usecols` 和 `names` 不匹配时,改进了错误消息([GH 29042](https://github.com/pandas-dev/pandas/issues/29042))

+   在 窗口方法 中传递无效的 `win_type` 参数时,改进了错误消息的一致性([GH 15969](https://github.com/pandas-dev/pandas/issues/15969))

+   现在 `read_sql_query()` 接受一个 `dtype` 参数,根据用户输入来转换 SQL 数据库中的列数据([GH 10285](https://github.com/pandas-dev/pandas/issues/10285))

+   当 `usecols` 未指定时,在 `read_csv()` 中如果标题或给定的名称长度与数据长度不匹配,则会引发 `ParserWarning`([GH 21768](https://github.com/pandas-dev/pandas/issues/21768))

+   在使用 `DataFrame.to_sql()` 时,将 pandas 到 SQLAlchemy 的整数类型映射进行了改进([GH 35076](https://github.com/pandas-dev/pandas/issues/35076))

+   `to_numeric()`现在支持可空`ExtensionDtype`对象的降级转换([GH 33013](https://github.com/pandas-dev/pandas/issues/33013))

+   在`MultiIndex.set_names`和`MultiIndex.rename`中添加了对类似字典的名称的支持([GH 20421](https://github.com/pandas-dev/pandas/issues/20421))

+   `read_excel()`现在可以自动检测 .xlsb 文件和旧版 .xls 文件([GH 35416](https://github.com/pandas-dev/pandas/issues/35416), [GH 41225](https://github.com/pandas-dev/pandas/issues/41225))

+   `ExcelWriter`现在接受一个`if_sheet_exists`参数,用于控制在写入现有工作表时附加模式的行为([GH 40230](https://github.com/pandas-dev/pandas/issues/40230))

+   `Rolling.sum()`、`Expanding.sum()`、`Rolling.mean()`、`Expanding.mean()`、`ExponentialMovingWindow.mean()`、`Rolling.median()`、`Expanding.median()`、`Rolling.max()`、`Expanding.max()`、`Rolling.min()`和`Expanding.min()`现在支持使用 `engine` 关键字进行 [Numba](http://numba.pydata.org/) 执行([GH 38895](https://github.com/pandas-dev/pandas/issues/38895), [GH 41267](https://github.com/pandas-dev/pandas/issues/41267))

+   `DataFrame.apply()`现在可以接受 NumPy 一元运算符作为字符串,例如`df.apply("sqrt")`,这在 `Series.apply()`中已经存在([GH 39116](https://github.com/pandas-dev/pandas/issues/39116))

+   `DataFrame.apply()`现在可以接受非可调用 DataFrame 属性作为字符串,例如`df.apply("size")`,这在 `Series.apply()`中已经存在([GH 39116](https://github.com/pandas-dev/pandas/issues/39116))

+   `DataFrame.applymap()`现在可以接受 kwargs 以传递给用户提供的`func`([GH 39987](https://github.com/pandas-dev/pandas/issues/39987))

+   现在,对于`Series.__getitem__()`和`DataFrame.__getitem__()`,不允许将`DataFrame`索引器传递给`iloc`([GH 39004](https://github.com/pandas-dev/pandas/issues/39004))

+   `Series.apply()`现在可以接受类似列表或字典的参数,而不是列表或字典,例如`ser.apply(np.array(["sum", "mean"]))`,这在`DataFrame.apply()`中已经存在([GH 39140](https://github.com/pandas-dev/pandas/issues/39140))

+   `DataFrame.plot.scatter()`现在可以接受一个分类列作为参数`c`([GH 12380](https://github.com/pandas-dev/pandas/issues/12380), [GH 31357](https://github.com/pandas-dev/pandas/issues/31357))

+   当 Series 具有`MultiIndex`且索引器具有太多维度时,现在对于`Series.loc()`会提出一个有用的错误消息([GH 35349](https://github.com/pandas-dev/pandas/issues/35349))

+   `read_stata()`现在支持从压缩文件中读取数据([GH 26599](https://github.com/pandas-dev/pandas/issues/26599))

+   增加了对从压缩文件读取数据的`ISO 8601`类似时间戳的解析支持到`Timedelta`中([GH 37172](https://github.com/pandas-dev/pandas/issues/37172))

+   在`FloatingArray`中增加了对一元运算符的支持([GH 38749](https://github.com/pandas-dev/pandas/issues/38749))

+   `RangeIndex`现在可以直接通过传递`range`对象来构造,例如`pd.RangeIndex(range(3))`([GH 12067](https://github.com/pandas-dev/pandas/issues/12067))

+   `Series.round()`和`DataFrame.round()`现在可以处理可空整数和浮点类型([GH 38844](https://github.com/pandas-dev/pandas/issues/38844))

+   `read_csv()` 和 `read_json()` 提供参数 `encoding_errors` 来控制如何处理编码错误([GH 39450](https://github.com/pandas-dev/pandas/issues/39450))

+   `DataFrameGroupBy.any()`, `SeriesGroupBy.any()`, `DataFrameGroupBy.all()`, 和 `SeriesGroupBy.all()` 在使用具有可空数据类型的 Kleene 逻辑([GH 37506](https://github.com/pandas-dev/pandas/issues/37506))

+   `DataFrameGroupBy.any()`, `SeriesGroupBy.any()`, `DataFrameGroupBy.all()`, 和 `SeriesGroupBy.all()` 返回一个 `BooleanDtype`,用于具有可空数据类型的列([GH 33449](https://github.com/pandas-dev/pandas/issues/33449))

+   `DataFrameGroupBy.any()`, `SeriesGroupBy.any()`, `DataFrameGroupBy.all()`, 和 `SeriesGroupBy.all()` 在包含 `pd.NA` 的 `object` 数据上即使 `skipna=True` 也会引发异常([GH 37501](https://github.com/pandas-dev/pandas/issues/37501))

+   `DataFrameGroupBy.rank()` 和 `SeriesGroupBy.rank()` 现在支持对象 dtype 数据([GH 38278](https://github.com/pandas-dev/pandas/issues/38278))

+   当`data`参数是不是由 NumPy `ndarray` 组成的 Python 可迭代对象时,构造 `DataFrame` 或 `Series` 将会得到一个精度为 NumPy 标量的最大值的 dtype;当`data`是 NumPy `ndarray` 时已经是这种情况了([GH 40908](https://github.com/pandas-dev/pandas/issues/40908))

+   在 `pivot_table()` 中添加关键字`sort`,以允许结果不排序([GH 39143](https://github.com/pandas-dev/pandas/issues/39143))

+   在`DataFrame.value_counts()` 中添加关键字`dropna`,以允许计算包含`NA`值的行数([GH 41325](https://github.com/pandas-dev/pandas/issues/41325))

+   `Series.replace()` 现在将结果转换为`PeriodDtype`,而不是`object` dtype([GH 41526](https://github.com/pandas-dev/pandas/issues/41526))

+   在`Rolling`、`Expanding`和`ExponentialMovingWindow`的`corr`和`cov`方法中,当`other`不是`DataFrame` 或 `Series` 时,改进了错误消息([GH 41741](https://github.com/pandas-dev/pandas/issues/41741))

+   `Series.between()` 现在可以接受`left`或`right`作为`inclusive`参数,以仅包括左侧或右侧边界([GH 40245](https://github.com/pandas-dev/pandas/issues/40245))

+   `DataFrame.explode()` 现在支持同时爆炸多列。其`column`参数现在也接受字符串列表或元组,以同时在多列上爆炸([GH 39240](https://github.com/pandas-dev/pandas/issues/39240))

+   `DataFrame.sample()` 现在接受 `ignore_index` 参数,在采样后重置索引,类似于 `DataFrame.drop_duplicates()` 和 `DataFrame.sort_values()` ([GH 38581](https://github.com/pandas-dev/pandas/issues/38581))  ## 显著的错误修复

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

### `Categorical.unique` 现在始终保持与原始数据类型相同

以前,使用分类数据调用 `Categorical.unique()` 时,新数组中未使用的类别将被移除,使得新数组的数据类型与原始数据类型不同 ([GH 18291](https://github.com/pandas-dev/pandas/issues/18291))

举例来说,给定:

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

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

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

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

先前行为:

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

新行为:

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

In [22]: original.dtype == unique.dtype
Out[22]: True 
```  ### 在 `DataFrame.combine_first()` 中保留数据类型

`DataFrame.combine_first()` 现在会保留数据类型 ([GH 7509](https://github.com/pandas-dev/pandas/issues/7509))

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

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

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

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

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

先前行为:

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

新行为:

In [28]: combined.dtypes
Out[28]: 
A    float64
B      int64
C    float64
dtype: object 
```  ### Groupby 方法 agg 和 transform 不再改变可调用函数的返回数据类型

以前,方法 `DataFrameGroupBy.aggregate()`、`SeriesGroupBy.aggregate()`、`DataFrameGroupBy.transform()` 和 `SeriesGroupBy.transform()` 可能会在参数 `func` 是可调用函数时转换结果数据类型,可能导致不良结果 ([GH 21240](https://github.com/pandas-dev/pandas/issues/21240))。如果结果是数值型且转换回输入数据类型不会改变任何值(通过 `np.allclose` 测量),则会发生转换。现在不再发生此类转换。

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

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

先前行为:

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

新行为:

In [31]: df.groupby('key').agg(lambda x: x.sum())
Out[31]: 
 a  b
key 
1    1  2 
```  ### `DataFrameGroupBy.mean()`、`DataFrameGroupBy.median()` 和 `GDataFrameGroupBy.var()`、`SeriesGroupBy.mean()`、`SeriesGroupBy.median()` 和 `SeriesGroupBy.var()` 的返回结果现在为 `float`

以前,这些方法可能会根据输入值的不同而产生不同的数据类型。现在,这些方法将始终返回浮点数据类型。([GH 41137](https://github.com/pandas-dev/pandas/issues/41137))

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

以前的行为:

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

新行为:

In [33]: df.groupby(df.index).mean()
Out[33]: 
 a    b    c
0  1.0  1.0  1.0 
```  ### 尝试使用 `loc` 和 `iloc` 设置值时进行原地操作

使用 `loc` 或 `iloc` 设置整个列时,pandas 会尝试将值插入现有数据而不是创建全新的数组。

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

In [35]: values = df.values

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

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

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

以前的行为:

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

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

新行为:

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

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

In [40]: np.shares_memory(df["A"], values)
Out[40]: True 
```  ### 当设置 `frame[keys] = values` 时永不原地操作

使用 `frame[keys] = values` 设置多列时,新的数组将替换这些键的预先存在的数组,这些数组 *不会* 被覆盖 ([GH 39510](https://github.com/pandas-dev/pandas/issues/39510))。因此,列将保留 `values` 的数据类型,而不会转换为现有数组的数据类型。

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

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

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

以前的行为:

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

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

新行为:

In [43]: df.dtypes
Out[43]: 
A    int64
dtype: object 
```  ### 设置非布尔值到布尔类型的 Series 时进行一致的转换

将非布尔值设置到具有 `dtype=bool` 的 `Series` 中现在始终转换为 `dtype=object` ([GH 38709](https://github.com/pandas-dev/pandas/issues/38709))

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

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

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

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

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

以前的行为:

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

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

新行为:

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

In [2]:ser2
Out [2]:
0    True
1     2.0
dtype: object 
```  ### DataFrameGroupBy.rolling 和 SeriesGroupBy.rolling 不再返回分组列的值

分组列现在会从 `groupby.rolling` 操作的结果中删除 ([GH 32262](https://github.com/pandas-dev/pandas/issues/32262))

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

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

以前的行为:

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

新行为:

In [46]: df.groupby("A").rolling(2).sum()
Out[46]: 
 B
A 
1 0  NaN
 1  1.0
2 2  NaN
3 3  NaN 
```  ### 移除了滚动方差和标准差的人为截断

`Rolling.std()` 和 `Rolling.var()` 将不再将小于 `~1e-8` 和 `~1e-15` 的结果人为截断为零 ([GH 37051](https://github.com/pandas-dev/pandas/issues/37051), [GH 40448](https://github.com/pandas-dev/pandas/issues/40448), [GH 39872](https://github.com/pandas-dev/pandas/issues/39872))。

但是,当数值较大时,可能会在结果中存在浮点数残留。

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

In [48]: s.rolling(3).var()
Out[48]: 
0         NaN
1         NaN
2    1.333333
3    0.000000
dtype: float64 
```  ### DataFrameGroupBy.rolling 和 SeriesGroupBy.rolling �� MultiIndex 中不再删除结果中的级别

`DataFrameGroupBy.rolling()` 和 `SeriesGroupBy.rolling()` 将不再在结果中删除具有 `MultiIndex` 的 `DataFrame` 的级别。这可能导致在生成的 `MultiIndex` 中出现级别的重复,但此更改恢复了版本 1.1.3 中存在的行为 ([GH 38787](https://github.com/pandas-dev/pandas/issues/38787), [GH 38523](https://github.com/pandas-dev/pandas/issues/38523))。

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

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

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

先前的行为:

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

新行为:

In [52]: df.groupby('label1').rolling(1).sum()
Out[52]: 
 a    b
label1 label1 label2 
idx1   idx1   idx2    1.0  2.0 
```  ## 不兼容的 API 更改

### 增加了依赖项的最低版本

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

| Package | Minimum Version | Required | Changed |
| --- | --- | --- | --- |
| numpy | 1.17.3 | X | X |
| pytz | 2017.3 | X |  |
| python-dateutil | 2.7.3 | X |  |
| bottleneck | 1.2.1 |  |  |
| numexpr | 2.7.0 |  | X |
| pytest (dev) | 6.0 |  | X |
| mypy (dev) | 0.812 |  | X |
| setuptools | 38.6.0 |  | X |

对于[可选库](https://pandas.pydata.org/docs/getting_started/install.html),一般建议使用最新版本。以下表格列出了在 pandas 开发过程中当前正在测试的每个库的最低版本。低于最低测试版本的可选库可能仍然可用,但不被视为受支持。

| Package | Minimum Version | Changed |
| --- | --- | --- |
| beautifulsoup4 | 4.6.0 |  |
| fastparquet | 0.4.0 | X |
| fsspec | 0.7.4 |  |
| gcsfs | 0.6.0 |  |
| lxml | 4.3.0 |  |
| matplotlib | 2.2.3 |  |
| numba | 0.46.0 |  |
| openpyxl | 3.0.0 | X |
| pyarrow | 0.17.0 | X |
| pymysql | 0.8.1 | X |
| pytables | 3.5.1 |  |
| s3fs | 0.4.0 |  |
| scipy | 1.2.0 |  |
| sqlalchemy | 1.3.0 | X |
| tabulate | 0.8.7 | X |
| xarray | 0.12.0 |  |
| xlrd | 1.2.0 |  |
| xlsxwriter | 1.0.2 |  |
| xlwt | 1.3.0 |  |
| pandas-gbq | 0.12.0 |  |

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

+   部分初始化的 `CategoricalDtype` 对象(即`categories=None`的对象)将不再等同于完全初始化的 dtype 对象 ([GH 38516](https://github.com/pandas-dev/pandas/issues/38516))

+   在 `DataFrame` 上访问 `_constructor_expanddim`,在 `Series` 上访问 `_constructor_sliced` 现在会引发 `AttributeError`。 以前会引发 `NotImplementedError` ([GH 38782](https://github.com/pandas-dev/pandas/issues/38782))

+   添加了新的 `engine` 和 `**engine_kwargs` 参数到 `DataFrame.to_sql()` 来支持其他未来的“SQL 引擎”。 目前我们仍然只在底层使用`SQLAlchemy`,但计划支持更多的引擎,例如 [turbodbc](https://turbodbc.readthedocs.io/en/latest/) ([GH 36893](https://github.com/pandas-dev/pandas/issues/36893))

+   从 `PeriodIndex` 字符串表示中删除了多余的 `freq` ([GH 41653](https://github.com/pandas-dev/pandas/issues/41653))

+   `ExtensionDtype.construct_array_type()` 现在是 `ExtensionDtype` 子类的必需方法,而不是可选的方法 ([GH 24860](https://github.com/pandas-dev/pandas/issues/24860))

+   在非可哈希的 pandas 对象上调用 `hash` 现在将引发 `TypeError` 并显示内置错误消息(例如`unhashable type: 'Series'`)。 以前会引发一个自定义消息,例如 `'Series' 对象是可变的,因此不能被哈希`。 此外,`isinstance(<Series>, abc.collections.Hashable)` 现在将返回 `False` ([GH 40013](https://github.com/pandas-dev/pandas/issues/40013))

+   `Styler.from_custom_template()` 现在有两个新参数用于模板名称,并删除了旧的 `name`,因为引入了模板继承以更好地解析 ([GH 42053](https://github.com/pandas-dev/pandas/issues/42053))。 还需要对 Styler 属性进行子类修改。  ### 构建

+   `.pptx` 和 `.pdf` 格式的文档已不再包含在轮子或源分发中。 ([GH 30741](https://github.com/pandas-dev/pandas/issues/30741))  ## 弃用功能

### 在 DataFrame reductions 和 DataFrameGroupBy 操作中弃用删除 DataFrame 中的无用列

在具有 `numeric_only=None`(默认值)的 `DataFrame` 上调用归约(例如 `.min`, `.max`, `.sum`),如果归约引发 `TypeError`,则会被静默地忽略并从结果中删除。

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

例如:

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

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

旧行为

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

未来行为

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

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

类似地,当对 DataFrameGroupBy 应用函数时,函数引发 TypeError 的列目前会被静默地忽略并从结果中删除。

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

例如:

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

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

旧行为

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

未来行为

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

In [6]: gb[["A"]].prod(numeric_only=False)
Out[6]:
 A
1   2
2  12 
```  ### 其他废弃功能

+   废弃允许标量传递给 `Categorical` 构造函数 ([GH 38433](https://github.com/pandas-dev/pandas/issues/38433))

+   废弃构造 `CategoricalIndex` 时未传递类似列表的数据 ([GH 38944](https://github.com/pandas-dev/pandas/issues/38944))

+   废弃允许子类特定关键字参数在 `Index` 构造函数中使用,直接使用特定的子类代替 ([GH 14093](https://github.com/pandas-dev/pandas/issues/14093), [GH 21311](https://github.com/pandas-dev/pandas/issues/21311), [GH 22315](https://github.com/pandas-dev/pandas/issues/22315), [GH 26974](https://github.com/pandas-dev/pandas/issues/26974))

+   废弃日期时间类 (`timedelta64[ns]`, `datetime64[ns]`, `Datetime64TZDtype`, `PeriodDtype`) 的 `astype()` 方法将转换为整数类型,应改用 `values.view(...)` ([GH 38544](https://github.com/pandas-dev/pandas/issues/38544))。此废弃功能在 pandas 1.4.0 中被撤销。

+   废弃 `MultiIndex.is_lexsorted()` 和 `MultiIndex.lexsort_depth()`,请使用 `MultiIndex.is_monotonic_increasing()` 代替 ([GH 32259](https://github.com/pandas-dev/pandas/issues/32259))

+   废弃关键字 `try_cast` 在 `Series.where()`、`Series.mask()`、`DataFrame.where()`、`DataFrame.mask()` 中;如果需要,手动转换结果 ([GH 38836](https://github.com/pandas-dev/pandas/issues/38836))

+   弃用对`Timestamp`对象与`datetime.date`对象的比较。不要再使用例如`ts <= mydate`,而是使用`ts <= pd.Timestamp(mydate)`或`ts.date() <= mydate` ([GH 36131](https://github.com/pandas-dev/pandas/issues/36131))

+   弃用`Rolling.win_type`返回`"freq"` ([GH 38963](https://github.com/pandas-dev/pandas/issues/38963))

+   弃用`Rolling.is_datetimelike` ([GH 38963](https://github.com/pandas-dev/pandas/issues/38963))

+   弃用`DataFrame`索引器用于`Series.__setitem__()`和`DataFrame.__setitem__()` ([GH 39004](https://github.com/pandas-dev/pandas/issues/39004))

+   弃用`ExponentialMovingWindow.vol()` ([GH 39220](https://github.com/pandas-dev/pandas/issues/39220))

+   使用`.astype`在`datetime64[ns]` dtype 和`DatetimeTZDtype`之间进行转换已被弃用,并且将在将来版本中引发警告,应该使用`obj.tz_localize`或`obj.dt.tz_localize`代替 ([GH 38622](https://github.com/pandas-dev/pandas/issues/38622))

+   在`DataFrame.unstack()`、`DataFrame.shift()`、`Series.shift()`和`DataFrame.reindex()`中,将`datetime.date`对象强制转换为`datetime64`作为`fill_value`已经被弃用,应该传递`pd.Timestamp(dateobj)` ([GH 39767](https://github.com/pandas-dev/pandas/issues/39767))

+   弃用`Styler.set_na_rep()`和`Styler.set_precision()`,建议使用带有`na_rep`和`precision`的`Styler.format()`,分别作为现有和新的输入参数 ([GH 40134](https://github.com/pandas-dev/pandas/issues/40134), [GH 40425](https://github.com/pandas-dev/pandas/issues/40425))

+   弃用`Styler.where()`,建议使用`Styler.applymap()`的另一种形式 ([GH 40821](https://github.com/pandas-dev/pandas/issues/40821))

+   弃用在`Series.transform()`和`DataFrame.transform()`中允许部分失败,当`func`类似于列表或字典且引发除`TypeError`之外的异常时;当`func`引发除`TypeError`之外的异常时,将在将来的版本中引发警告 ([GH 40211](https://github.com/pandas-dev/pandas/issues/40211))

+   弃用了`read_csv()`和`read_table()`中`error_bad_lines`和`warn_bad_lines`参数,而采用`on_bad_lines`参数([GH 15122](https://github.com/pandas-dev/pandas/issues/15122))

+   弃用了在`DataFrame`构造函数中支持`np.ma.mrecords.MaskedRecords`的方式,应传入`{name: data[name] for name in data.dtype.names}`([GH 40363](https://github.com/pandas-dev/pandas/issues/40363))

+   弃用了在不同层级上使用`merge()`、`DataFrame.merge()`和`DataFrame.join()`,导致不同层级的数量不同([GH 34862](https://github.com/pandas-dev/pandas/issues/34862))

+   弃用了在`ExcelWriter`中使用`**kwargs`的方式;改用关键字参数`engine_kwargs`代替([GH 40430](https://github.com/pandas-dev/pandas/issues/40430))

+   弃用了`DataFrame`和`Series`聚合中的`level`关键字;应使用 groupby 代替([GH 39983](https://github.com/pandas-dev/pandas/issues/39983))

+   弃用了`Categorical.remove_categories()`、`Categorical.add_categories()`、`Categorical.reorder_categories()`、`Categorical.rename_categories()`、`Categorical.set_categories()`的`inplace`参数,并将在将来的版本中移除([GH 37643](https://github.com/pandas-dev/pandas/issues/37643))

+   弃用了通过`suffixes`关键字在`merge()`中生成重复列的方式,并且存在已有列([GH 22818](https://github.com/pandas-dev/pandas/issues/22818))

+   弃用了设置`Categorical._codes`的方法,应创建一个新的`Categorical`并传入所需的代码([GH 40606](https://github.com/pandas-dev/pandas/issues/40606))

+   弃用了在`read_excel()`和`ExcelFile.parse()`中的`convert_float`可选参数([GH 41127](https://github.com/pandas-dev/pandas/issues/41127))

+   弃用了`DatetimeIndex.union()`的混合时区行为;在将来的版本中,两者将被转换为 UTC 而不是对象数据类型([GH 39328](https://github.com/pandas-dev/pandas/issues/39328))

+   对于使用`engine="c"`的`read_csv()`,弃用了对超出边界索引使用`usecols`的特殊处理([GH 25623](https://github.com/pandas-dev/pandas/issues/25623))

+   弃用了在`DataFrame`构造函数中具有首个元素为分类的列表的特殊处理;改为传递`pd.DataFrame({col: categorical, ...})`([GH 38845](https://github.com/pandas-dev/pandas/issues/38845))

+   当传递`dtype`并且数据无法转换为该 dtype 时,弃用了`DataFrame`构造函数的行为。在未来的版本中,这将引发异常而不是被静默忽略([GH 24435](https://github.com/pandas-dev/pandas/issues/24435))

+   弃用了`Timestamp.freq`属性。对于使用它的属性(`is_month_start`、`is_month_end`、`is_quarter_start`、`is_quarter_end`、`is_year_start`、`is_year_end`),当你有一个`freq`时,使用例如`freq.is_month_start(ts)`([GH 15146](https://github.com/pandas-dev/pandas/issues/15146))

+   使用`DatetimeTZDtype`数据和`datetime64[ns]` dtype 构造`Series`或`DataFrame`已被弃用。使用`Series(data).dt.tz_localize(None)`代替([GH 41555](https://github.com/pandas-dev/pandas/issues/41555),[GH 33401](https://github.com/pandas-dev/pandas/issues/33401))

+   当`Series`构造中使用大整数值和小整数 dtype 导致静默溢出时,弃用了该行为;改为使用`Series(data).astype(dtype)`([GH 41734](https://github.com/pandas-dev/pandas/issues/41734))

+   弃用了浮点数据和整数 dtype 转换的`DataFrame`构造行为,即使是损失性的;在未来的版本中,这将保持浮点型,与`Series`的行为一致([GH 41770](https://github.com/pandas-dev/pandas/issues/41770))

+   当传递包含字符串的数据且没有传递`dtype`时,弃用了对`Series`构造中的`timedelta64[ns]`、`datetime64[ns]`或`DatetimeTZDtype` dtype 的推断行为([GH 33558](https://github.com/pandas-dev/pandas/issues/33558))

+   在将来的版本中,使用 `datetime64[ns]` 数据和 `DatetimeTZDtype` 构造 `Series` 或 `DataFrame` 将把数据视为壁钟时间而不是 UTC 时间(匹配 DatetimeIndex 行为)。要将数据视为 UTC 时间,请使用 `pd.Series(data).dt.tz_localize("UTC").dt.tz_convert(dtype.tz)` 或 `pd.Series(data.view("int64"), dtype=dtype)`([GH 33401](https://github.com/pandas-dev/pandas/issues/33401))

+   废弃了将列表作为 `key` 传递给 `DataFrame.xs()` 和 `Series.xs()` 的方式([GH 41760](https://github.com/pandas-dev/pandas/issues/41760))

+   废弃了在 `Series.between()` 中使用布尔参数作为标准参数值 `{"left", "right", "neither", "both"}`([GH 40628](https://github.com/pandas-dev/pandas/issues/40628))

+   废弃了对以下所有内容使用位置参数传递的方式,特殊情况除外([GH 41485](https://github.com/pandas-dev/pandas/issues/41485)):

    +   `concat()`(除了 `objs`)

    +   `read_csv()`(除了 `filepath_or_buffer`)

    +   `read_table()`(除了 `filepath_or_buffer`)

    +   `DataFrame.clip()` 和 `Series.clip()`(除了 `upper` 和 `lower`)

    +   `DataFrame.drop_duplicates()`(除了 `subset`)、`Series.drop_duplicates()`、`Index.drop_duplicates()` 和 `MultiIndex.drop_duplicates()`

    +   `DataFrame.drop()`(除了 `labels`)和 `Series.drop()`

    +   `DataFrame.dropna()` 和 `Series.dropna()`

    +   `DataFrame.ffill()`, `Series.ffill()`, `DataFrame.bfill()` 和 `Series.bfill()`

    +   `DataFrame.fillna()` 和 `Series.fillna()` (除了 `value`)

    +   `DataFrame.interpolate()` 和 `Series.interpolate()` (除了 `method`)

    +   `DataFrame.mask()` 和 `Series.mask()` (除了 `cond` 和 `other`)

    +   `DataFrame.reset_index()` (除了 `level`) 和 `Series.reset_index()`

    +   `DataFrame.set_axis()` 和 `Series.set_axis()` (除了 `labels`)

    +   `DataFrame.set_index()` (除了 `keys`)

    +   `DataFrame.sort_index()` 和 `Series.sort_index()`

    +   `DataFrame.sort_values()` (除了 `by`) 和 `Series.sort_values()`

    +   `DataFrame.where()` 和 `Series.where()` (除了 `cond` 和 `other`)

    +   `Index.set_names()` 和 `MultiIndex.set_names()`(除了 `names`)

    +   `MultiIndex.codes()`(除了 `codes`)

    +   `MultiIndex.set_levels()`(除了 `levels`)

    +   `Resampler.interpolate()`(除了 `method`)## 性能改进

+   `IntervalIndex.isin()` 的性能改进([GH 38353](https://github.com/pandas-dev/pandas/issues/38353))

+   `Series.mean()` 可空数据类型的性能改进([GH 34814](https://github.com/pandas-dev/pandas/issues/34814))

+   `Series.isin()` 可空数据类型的性能改进([GH 38340](https://github.com/pandas-dev/pandas/issues/38340))

+   `DataFrame.fillna()` 在可为空的浮点数和可为空的整数数据类型下,使用 `method="pad"` 或 `method="backfill"` 的性能改进([GH 39953](https://github.com/pandas-dev/pandas/issues/39953))

+   `DataFrame.corr()` 在 `method=kendall` 下的性能改进([GH 28329](https://github.com/pandas-dev/pandas/issues/28329))

+   `DataFrame.corr()` 在 `method=spearman` 下的性能改进([GH 40956](https://github.com/pandas-dev/pandas/issues/40956), [GH 41885](https://github.com/pandas-dev/pandas/issues/41885))

+   `Rolling.corr()` 和 `Rolling.cov()` 的性能改进([GH 39388](https://github.com/pandas-dev/pandas/issues/39388))

+   `RollingGroupby.corr()`、`ExpandingGroupby.corr()`、`ExpandingGroupby.corr()` 和 `ExpandingGroupby.cov()` 的性能改进([GH 39591](https://github.com/pandas-dev/pandas/issues/39591))

+   `unique()` 对象数据类型的性能改进([GH 37615](https://github.com/pandas-dev/pandas/issues/37615))

+   `json_normalize()` 在基本情况下(包括分隔符)的性能改进([GH 40035](https://github.com/pandas-dev/pandas/issues/40035) [GH 15621](https://github.com/pandas-dev/pandas/issues/15621))

+   `ExpandingGroupby` 聚合方法的性能改进([GH 39664](https://github.com/pandas-dev/pandas/issues/39664))

+   在 `Styler` 中的性能改进,渲染时间减少了超过 50%,现在与 `DataFrame.to_html()` 相匹配 ([GH 39972](https://github.com/pandas-dev/pandas/issues/39972) [GH 39952](https://github.com/pandas-dev/pandas/issues/39952), [GH 40425](https://github.com/pandas-dev/pandas/issues/40425))

+   方法 `Styler.set_td_classes()` 现在与 `Styler.apply()` 和 `Styler.applymap()` 一样高效,甚至在某些情况下更高效 ([GH 40453](https://github.com/pandas-dev/pandas/issues/40453))

+   在带有 `times` 参数的 `ExponentialMovingWindow.mean()` 中的性能改进 ([GH 39784](https://github.com/pandas-dev/pandas/issues/39784))

+   在需要 Python 回退实现时的 `DataFrameGroupBy.apply()` 和 `SeriesGroupBy.apply()` 中的性能改进 ([GH 40176](https://github.com/pandas-dev/pandas/issues/40176))

+   在将 PyArrow 布尔数组转换为 pandas 可空布尔数组时的性能改进 ([GH 41051](https://github.com/pandas-dev/pandas/issues/41051))

+   数据拼接性能改进,对于 `CategoricalDtype` 类型的数据拼接 ([GH 40193](https://github.com/pandas-dev/pandas/issues/40193))

+   在具有可空数据类型的`DataFrameGroupBy.cummin()`、`SeriesGroupBy.cummin()`、`DataFrameGroupBy.cummax()`和`SeriesGroupBy.cummax()`中的性能改进 ([GH 37493](https://github.com/pandas-dev/pandas/issues/37493))

+   具有 nan 值的`Series.nunique()`中的性能改进 ([GH 40865](https://github.com/pandas-dev/pandas/issues/40865))

+   在具有`DatetimeTZDtype`的`DataFrame.transpose()`、`Series.unstack()`中的性能改进 ([GH 40149](https://github.com/pandas-dev/pandas/issues/40149))

+   在懒加载入口点中的`Series.plot()`和`DataFrame.plot()`中的性能改进 ([GH 41492](https://github.com/pandas-dev/pandas/issues/41492))  ## Bug fixes

### 分类

+   当标量数据被传递时,`CategoricalIndex`中的错误不正确地未引发`TypeError`([GH 38614](https://github.com/pandas-dev/pandas/issues/38614))

+   当传递的`Index`不是分类的,但其值都是类别中的标签时,`CategoricalIndex.reindex`中的错误([GH 28690](https://github.com/pandas-dev/pandas/issues/28690))

+   从`date`对象的对象类型数组构造`Categorical`时,未能正确进行往返处理,即未能正确使用`astype`进行往返处理 ([GH 38552](https://github.com/pandas-dev/pandas/issues/38552))

+   从`ndarray`和`CategoricalDtype`构造`DataFrame`中存在的错误([GH 38857](https://github.com/pandas-dev/pandas/issues/38857))

+   在将分类值设置到 `DataFrame` 的对象 dtype 列中时出现错误 ([GH 39136](https://github.com/pandas-dev/pandas/issues/39136))

+   在使用 `DataFrame.reindex()` 时出现了一个错误,当新索引包含重复项且旧索引是一个 `CategoricalIndex` 时,会引发 `IndexError` ([GH 38906](https://github.com/pandas-dev/pandas/issues/38906))

+   在使用 `Categorical.fillna()` 时,当用非分类元组填充时,会引发 `NotImplementedError` 而不是 `ValueError` ([GH 41914](https://github.com/pandas-dev/pandas/issues/41914))

### Datetimelike

+   在 `DataFrame` 和 `Series` 构造函数中,有时会从 `Timestamp`(或 `Timedelta`)的 `data` 中删除纳秒,其 `dtype` 为 `datetime64[ns]`(或 `timedelta64[ns]`) ([GH 38032](https://github.com/pandas-dev/pandas/issues/38032))

+   在使用 `DataFrame.first()` 和 `Series.first()` 时出现错误,当偏移量为一个月时,当第一天是月份的最后一天时返回错误的结果 ([GH 29623](https://github.com/pandas-dev/pandas/issues/29623))

+   在构建一个含有不匹配的 `datetime64` 数据和 `timedelta64` dtype 的 `DataFrame` 或 `Series` 时出现错误,或者反之,未能引发 `TypeError` ([GH 38575](https://github.com/pandas-dev/pandas/issues/38575), [GH 38764](https://github.com/pandas-dev/pandas/issues/38764), [GH 38792](https://github.com/pandas-dev/pandas/issues/38792))

+   在使用 `datetime64[ns]` dtype 类型的 `datetime` 对象或 `timedelta64[ns]` dtype 类型的 `timedelta` 对象构建 `Series` 或 `DataFrame` 时出现错误,超出范围 ([GH 38792](https://github.com/pandas-dev/pandas/issues/38792), [GH 38965](https://github.com/pandas-dev/pandas/issues/38965))

+   在 `DatetimeIndex.intersection()`, `DatetimeIndex.symmetric_difference()`, `PeriodIndex.intersection()`, `PeriodIndex.symmetric_difference()` 中存在 Bug,当与 `CategoricalIndex` 进行操作时,始终返回对象类型 ([GH 38741](https://github.com/pandas-dev/pandas/issues/38741))

+   在 `DatetimeIndex.intersection()` 中存在 Bug,当频率为非 Tick 时,`n != 1` 时返回错误结果 ([GH 42104](https://github.com/pandas-dev/pandas/issues/42104))

+   在 `Series.where()` 中存在 Bug,错误地将 `datetime64` 值转换为 `int64` ([GH 37682](https://github.com/pandas-dev/pandas/issues/37682))

+   `Categorical` 中的 Bug 错误地将 `datetime` 对象类型转换为 `Timestamp` ([GH 38878](https://github.com/pandas-dev/pandas/issues/38878))

+   在 `Timestamp` 对象和纳秒 `datetime64` 实现边界外的 `datetime64` 对象之间的比较中存在 Bug ([GH 39221](https://github.com/pandas-dev/pandas/issues/39221))

+   在 `Timestamp.round()`, `Timestamp.floor()`, `Timestamp.ceil()` 的实现边界附近的值中存在 Bug,导致 `Timestamp` 错误地舍入为 `Timestamp` ([GH 39244](https://github.com/pandas-dev/pandas/issues/39244))

+   在 `Timedelta.round()`, `Timedelta.floor()`, `Timedelta.ceil()` 的实现边界附近的值中存在 Bug,导致 `Timedelta` 错误地舍入为 `Timestamp` ([GH 38964](https://github.com/pandas-dev/pandas/issues/38964))

+   在 `date_range()` 中存在 Bug,在极端情况下,错误地创建包含 `NaT` 的 `DatetimeIndex` 而不是引发 `OutOfBoundsDatetime` ([GH 24124](https://github.com/pandas-dev/pandas/issues/24124))

+   `infer_freq()` 错误地未能推断带有时区且跨越 DST 边界的 `DatetimeIndex` 的 ‘H’ 频率的 Bug([GH 39556](https://github.com/pandas-dev/pandas/issues/39556))

+   由 `DatetimeArray` 或 `TimedeltaArray` 支持的 `Series` 有时无法将数组的 `freq` 设置为 `None` 的 Bug([GH 41425](https://github.com/pandas-dev/pandas/issues/41425))

### 时间差

+   由非纳秒单位的 `np.timedelta64` 对象构造 `Timedelta` 时出现 Bug,该单位超出了 `timedelta64[ns]` 的边界([GH 38965](https://github.com/pandas-dev/pandas/issues/38965))

+   构造 `TimedeltaIndex` 时的 Bug,错误地接受了 `np.datetime64("NaT")` 对象([GH 39462](https://github.com/pandas-dev/pandas/issues/39462))

+   从仅包含符号而没有数字的输入字符串构造 `Timedelta` 时出现 Bug 未能引发错误([GH 39710](https://github.com/pandas-dev/pandas/issues/39710))

+   构造 `TimedeltaIndex` 和 `to_timedelta()` 时,当传递非纳秒 `timedelta64` 数组并在转换为 `timedelta64[ns]` 时溢出时未能引发 Bug([GH 40008](https://github.com/pandas-dev/pandas/issues/40008))

### 时区

+   不同的 `tzinfo` 对象表示 UTC 未被视为等价的 Bug([GH 39216](https://github.com/pandas-dev/pandas/issues/39216))

+   Bug in `dateutil.tz.gettz("UTC")` 未被识别为等同于其他表示 UTC 的 `tzinfos` 的 Bug([GH 39276](https://github.com/pandas-dev/pandas/issues/39276))

### 数值

+   `DataFrame.quantile()` 和 `DataFrame.sort_values()` 中的 Bug 导致了不正确的后续索引行为([GH 38351](https://github.com/pandas-dev/pandas/issues/38351))

+   `DataFrame.sort_values()` 中的 Bug,在空 `by` 时引发了 [`IndexError`](https://docs.python.org/3/library/exceptions.html#IndexError "(in Python v3.12)")([GH 40258](https://github.com/pandas-dev/pandas/issues/40258)")

+   `DataFrame.select_dtypes()` 在 `include=np.number` 时会丢弃数值型 `ExtensionDtype` 列([GH 35340](https://github.com/pandas-dev/pandas/issues/35340))

+   `DataFrame.mode()` 和 `Series.mode()` 在空输入时未保持一致的整数 `Index` 存在错误([GH 33321](https://github.com/pandas-dev/pandas/issues/33321))

+   `DataFrame.rank()` 在 DataFrame 包含 `np.inf` 时存在错误([GH 32593](https://github.com/pandas-dev/pandas/issues/32593))

+   `DataFrame.rank()` 存在错误,当 `axis=0` 并且列包含不可比较的类型时会引发 `IndexError`([GH 38932](https://github.com/pandas-dev/pandas/issues/38932))

+   `Series.rank()`、`DataFrame.rank()`、`DataFrameGroupBy.rank()` 和 `SeriesGroupBy.rank()` 处理最负的 `int64` 值为缺失值存在错误([GH 32859](https://github.com/pandas-dev/pandas/issues/32859))

+   `DataFrame.select_dtypes()` 在 Windows 和 Linux 中 `include="int"` 时存在不同的行为([GH 36596](https://github.com/pandas-dev/pandas/issues/36596))

+   `DataFrame.apply()` 和 `DataFrame.agg()` 在传递参数 `func="size"` 时存在错误,会操作整个 `DataFrame` 而不是行或列([GH 39934](https://github.com/pandas-dev/pandas/issues/39934))

+   `DataFrame.transform()` 在传递字典且列丢失时会引发 `SpecificationError`;现在会引发 `KeyError`([GH 40004](https://github.com/pandas-dev/pandas/issues/40004))

+   在使用 `pct=True` 且连续组之间存在相等值时,`DataFrameGroupBy.rank()` 和 `SeriesGroupBy.rank()` 会给出错误的结果([GH 40518](https://github.com/pandas-dev/pandas/issues/40518))

+   在参数 `level=None` 时,`Series.count()` 在 32 位平台上会返回 `int32` 结果([GH 40908](https://github.com/pandas-dev/pandas/issues/40908))

+   在对象数据上使用方法 `any` 和 `all` 的 `Series` 和 `DataFrame` 缩减操作不会返回布尔结果([GH 12863](https://github.com/pandas-dev/pandas/issues/12863), [GH 35450](https://github.com/pandas-dev/pandas/issues/35450), [GH 27709](https://github.com/pandas-dev/pandas/issues/27709))

+   在包含 NA 值且数据类型为可空整数或浮点数的 Series 上使用 `Series.clip()` 会失败([GH 40851](https://github.com/pandas-dev/pandas/issues/40851))

+   在 `np.int64` 数据类型的 `other` 上使用 `UInt64Index.where()` 和 `UInt64Index.putmask()` 会错误地引发 `TypeError`([GH 41974](https://github.com/pandas-dev/pandas/issues/41974))

+   在提供的聚合函数的顺序中,`DataFrame.agg()` 不会对聚合轴进行排序,当一个或多个聚合函数未能产生结果时([GH 33634](https://github.com/pandas-dev/pandas/issues/33634))

+   在缺失值上使用 `DataFrame.clip()` 不会将其解释为无阈值([GH 40420](https://github.com/pandas-dev/pandas/issues/40420))

### 转换

+   在使用`orient='records'`参数时,`Series.to_dict()` 存在的问题,现在返回 Python 本机类型([GH 25969](https://github.com/pandas-dev/pandas/issues/25969))

+   在转换日期时间类(`datetime64[ns]`、`datetime64[ns, tz]`、`timedelta64`、`period`)数据类型时,`Series.view()` 和 `Index.view()` 存在的问题([GH 39788](https://github.com/pandas-dev/pandas/issues/39788))

+   从空的`np.recarray`创建`DataFrame`未保留原始 dtypes 的错误([GH 40121](https://github.com/pandas-dev/pandas/issues/40121))

+   从`frozenset`构造时,`DataFrame`未能引发`TypeError`的错误([GH 40163](https://github.com/pandas-dev/pandas/issues/40163))

+   当数据无法转换为该 dtype 时,`Index`构造默默地忽略传递的`dtype`的错误([GH 21311](https://github.com/pandas-dev/pandas/issues/21311))

+   当转换为`dtype='categorical'`时,`StringArray.astype()`返回到 NumPy 并在转换时引发错误的错误([GH 40450](https://github.com/pandas-dev/pandas/issues/40450))

+   当给定一个数字 NumPy dtype 低于 int64、uint64 和 float64 的数组时,`factorize()`中的错误是唯一值未保持其原始 dtype([GH 41132](https://github.com/pandas-dev/pandas/issues/41132))

+   创建包含`ExtensionDtype`和`copy=True`的字典的`DataFrame`构造中出现的错误,未能复制失败([GH 38939](https://github.com/pandas-dev/pandas/issues/38939))

+   在将`Float64DType`作为输入时,`qcut()`引发错误([GH 40730](https://github.com/pandas-dev/pandas/issues/40730))

+   使用`datetime64[ns]`数据和`dtype=object`构造`DataFrame`和`Series`时出现的错误,结果是`datetime`对象而不是`Timestamp`对象([GH 41599](https://github.com/pandas-dev/pandas/issues/41599))

+   使用`timedelta64[ns]`数据和`dtype=object`构造`DataFrame`和`Series`时出现的错误,结果是`np.timedelta64`对象而不是`Timedelta`对象([GH 41599](https://github.com/pandas-dev/pandas/issues/41599))

+   当给定一个需要分别转换为 `PeriodDtype` 或 `IntervalDtype` 的 `Period` 或 `Interval` 对象的二维对象-dtype `np.ndarray` 时,在 `DataFrame` 构造时存在的 bug ([GH 41812](https://github.com/pandas-dev/pandas/issues/41812))

+   通过列表和一个 `PandasDtype` 构建 `Series` 时存在的 bug([GH 39357](https://github.com/pandas-dev/pandas/issues/39357))

+   创建 `Series` 时存在的一个 bug,来自一个不适合于 `int64` dtype 边界的 `range` 对象([GH 30173](https://github.com/pandas-dev/pandas/issues/30173))

+   通过一个所有键都是元组且需要重新索引的 `Index` 和一个 `dict` 构建 `Series` 时存在的 bug([GH 41707](https://github.com/pandas-dev/pandas/issues/41707))

+   在识别 Series、Index 或具有 Period dtype 的数组时,在 `infer_dtype()` 中存在的 bug([GH 23553](https://github.com/pandas-dev/pandas/issues/23553))

+   在对一般的 `ExtensionArray` 对象调用 `infer_dtype()` 时出现的 bug,将会返回 `"unknown-array"` 而不是报错([GH 37367](https://github.com/pandas-dev/pandas/issues/37367))

+   在空 DataFrame 上调用 `DataFrame.convert_dtypes()` 时出现的 bug,错误地引发了 `ValueError`([GH 40393](https://github.com/pandas-dev/pandas/issues/40393))

### 字符串

+   当原始对象没有任何 chunk 时,从 `pyarrow.ChunkedArray` 转换为 `StringArray` 时存在的 bug([GH 41040](https://github.com/pandas-dev/pandas/issues/41040))

+   `Series.replace()` 和 `DataFrame.replace()` 中的一个 bug,对于 `StringDType` 数据,使用 `regex=True` 忽略了替换([GH 41333](https://github.com/pandas-dev/pandas/issues/41333),[GH 35977](https://github.com/pandas-dev/pandas/issues/35977))

+   `Series.str.extract()` 中的一个 bug,使用 `StringArray` 返回空的 `DataFrame` 时返回 object dtype([GH 41441](https://github.com/pandas-dev/pandas/issues/41441))

+   `Series.str.replace()` 中的一个 bug,在 `regex=False` 时忽略了 `case` 参数([GH 41602](https://github.com/pandas-dev/pandas/issues/41602))

### 区间

+   当与 `CategoricalIndex` 进行操作时,`IntervalIndex.intersection()` 和 `IntervalIndex.symmetric_difference()` 中的一个 bug 总是返回 object-dtype([GH 38653](https://github.com/pandas-dev/pandas/issues/38653),[GH 38741](https://github.com/pandas-dev/pandas/issues/38741))

+   当至少一个 `Index` 对象具有在另一个对象中存在的重复项时,`IntervalIndex.intersection()` 中的一个 bug 返回重复项([GH 38743](https://github.com/pandas-dev/pandas/issues/38743))

+   `IntervalIndex.union()`、`IntervalIndex.intersection()`、`IntervalIndex.difference()` 和 `IntervalIndex.symmetric_difference()` 现在在与不兼容 dtype 的另一个 `IntervalIndex` 进行操作时,会转换为适当的 dtype 而不是引发 `TypeError`([GH 39267](https://github.com/pandas-dev/pandas/issues/39267))

+   `PeriodIndex.union()`、`PeriodIndex.intersection()`、`PeriodIndex.symmetric_difference()`、`PeriodIndex.difference()` 现在在与不兼容 dtype 的另一个 `PeriodIndex` 进行操作时,会转换为 object dtype 而不是引发 `IncompatibleFrequency`([GH 39306](https://github.com/pandas-dev/pandas/issues/39306))

+   当存在 NA 值时,`IntervalIndex.is_monotonic()`、`IntervalIndex.get_loc()`、`IntervalIndex.get_indexer_for()` 和 `IntervalIndex.__contains__()` 中的一个 bug([GH 41831](https://github.com/pandas-dev/pandas/issues/41831))

### 索引

+   Bug in `Index.union()` 和 `MultiIndex.union()` 当 `Index` 不是单调的或 `sort` 设置为 `False` 时,丢弃重复的 `Index` 值 ([GH 36289](https://github.com/pandas-dev/pandas/issues/36289), [GH 31326](https://github.com/pandas-dev/pandas/issues/31326), [GH 40862](https://github.com/pandas-dev/pandas/issues/40862))

+   Bug in `CategoricalIndex.get_indexer()` 在非唯一时未能引发 `InvalidIndexError` ([GH 38372](https://github.com/pandas-dev/pandas/issues/38372))

+   Bug in `IntervalIndex.get_indexer()` 当 `target` 具有 `CategoricalDtype`,且索引和目标均包含 NA 值时 ([GH 41934](https://github.com/pandas-dev/pandas/issues/41934))

+   Bug in `Series.loc()` 当输入被布尔列表过滤并且要设置的值是具有较低维度的列表时,引发 `ValueError` ([GH 20438](https://github.com/pandas-dev/pandas/issues/20438))

+   Bug in 向 `DataFrame` 插入许多新列时,导致不正确的后续索引行为 ([GH 38380](https://github.com/pandas-dev/pandas/issues/38380))

+   Bug in `DataFrame.__setitem__()` 当将多个值设置为重复列时引发 `ValueError` ([GH 15695](https://github.com/pandas-dev/pandas/issues/15695))

+   Bug in `DataFrame.loc()`, `Series.loc()`, `DataFrame.__getitem__()` 和 `Series.__getitem__()` 返回非单调 `DatetimeIndex` 的字符串切片的不正确元素 ([GH 33146](https://github.com/pandas-dev/pandas/issues/33146))

+   Bug in `DataFrame.reindex()` 和 `Series.reindex()` 在具有时区感知索引的情况下,对于 `method="ffill"` 和 `method="bfill"` 以及指定的 `tolerance` 引发 `TypeError` ([GH 38566](https://github.com/pandas-dev/pandas/issues/38566))

+   Bug in `DataFrame.reindex()` 在 `datetime64[ns]` 或 `timedelta64[ns]` 的情况下,当 `fill_value` 需要转换为对象 dtype 时,错误地转换为整数 ([GH 39755](https://github.com/pandas-dev/pandas/issues/39755))

+   当使用指定列和非空`DataFrame`值在空`DataFrame`上设置时,`DataFrame.__setitem__()`引发`ValueError`的错误([GH 38831](https://github.com/pandas-dev/pandas/issues/38831))

+   当`DataFrame`具有重复列时,对唯一列进行操作时,`DataFrame.loc.__setitem__()`引发`ValueError`的错误([GH 38521](https://github.com/pandas-dev/pandas/issues/38521))

+   当使用字典值设置混合 dtype 时,`DataFrame.iloc.__setitem__()`和`DataFrame.loc.__setitem__()`的错误([GH 38335](https://github.com/pandas-dev/pandas/issues/38335))

+   当提供布尔生成器时,`Series.loc.__setitem__()`和`DataFrame.loc.__setitem__()`引发`KeyError`的错误([GH 39614](https://github.com/pandas-dev/pandas/issues/39614))

+   当提供生成器时,`Series.iloc()`和`DataFrame.iloc()`引发`KeyError`的错误([GH 39614](https://github.com/pandas-dev/pandas/issues/39614))

+   当右侧是具有错误列数的`DataFrame`时,`DataFrame.__setitem__()`未引发`ValueError`的错误([GH 38604](https://github.com/pandas-dev/pandas/issues/38604))

+   当使用标量索引器设置`Series`时,`Series.__setitem__()`引发`ValueError`的错误([GH 38303](https://github.com/pandas-dev/pandas/issues/38303))

+   当作为输入的`DataFrame`只有一行时,`DataFrame.loc()`删除`MultiIndex`的级别的错误([GH 10521](https://github.com/pandas-dev/pandas/issues/10521))

+   在使用现有字符串进行切片时,`DataFrame.__getitem__()`和`Series.__getitem__()`始终引发`KeyError`的错误,其中`Index`具有毫秒值([GH 33589](https://github.com/pandas-dev/pandas/issues/33589))

+   在将`timedelta64`或`datetime64`值设置到数值`Series`时出现的错误,无法转换为对象 dtype([GH 39086](https://github.com/pandas-dev/pandas/issues/39086),[GH 39619](https://github.com/pandas-dev/pandas/issues/39619))

+   在向具有不匹配的 `IntervalDtype` 的 `Series` 或 `DataFrame` 中设置 `Interval` 值时的错误,错误地将新值强制转换为现有的 dtype([GH 39120](https://github.com/pandas-dev/pandas/issues/39120))

+   在将 `datetime64` 值设置到具有整数 dtype 的 `Series` 中时的错误,错误地将 datetime64 值转换为整数([GH 39266](https://github.com/pandas-dev/pandas/issues/39266))

+   在将 `np.datetime64("NaT")` 设置到具有 `Datetime64TZDtype` 的 `Series` 中时的错误,错误地将时区不可感知的值视为时区感知的([GH 39769](https://github.com/pandas-dev/pandas/issues/39769))

+   当 `key=NaN` 并且指定了 `method` 但 `NaN` 不在 `Index` 中时,`Index.get_loc()` 中的错误未引发 `KeyError`([GH 39382](https://github.com/pandas-dev/pandas/issues/39382))

+   `DatetimeIndex.insert()` 在向时区感知的索引中插入 `np.datetime64("NaT")` 时存在的错误,错误地将时区不可感知的值视为时区感知的([GH 39769](https://github.com/pandas-dev/pandas/issues/39769))

+   在 `Index.insert()` 中的错误,当设置一个无法容纳在现有 `frame.columns` 中的新列时,或者在 `Series.reset_index()` 或 `DataFrame.reset_index()` 中的错误,未将其转换为兼容的 dtype 而是错误地引发异常([GH 39068](https://github.com/pandas-dev/pandas/issues/39068))

+   在 `RangeIndex.append()` 中的错误,将长度为 1 的单个对象错误地连接起来([GH 39401](https://github.com/pandas-dev/pandas/issues/39401))

+   在 `RangeIndex.astype()` 中的错误,当转换为 `CategoricalIndex` 时,类别变成了 `Int64Index` 而不是 `RangeIndex`([GH 41263](https://github.com/pandas-dev/pandas/issues/41263))

+   在使用布尔索引器将 `numpy.timedelta64` 值设置到对象 dtype 的 `Series` 中时的错误([GH 39488](https://github.com/pandas-dev/pandas/issues/39488))

+   在使用`at`或`iat`将数值值设置为布尔类型`Series`时,失败将其转换为对象类型([GH 39582](https://github.com/pandas-dev/pandas/issues/39582))

+   在尝试使用行切片索引并将列表设置为值时,`DataFrame.__setitem__()`和`DataFrame.iloc.__setitem__()`会引发`ValueError`的错误([GH 40440](https://github.com/pandas-dev/pandas/issues/40440))

+   在`DataFrame.loc()`中,当在`MultiIndex`中未找到键且级��未完全指定时,未引发`KeyError`的错误([GH 41170](https://github.com/pandas-dev/pandas/issues/41170))

+   在设置扩展时,`DataFrame.loc.__setitem__()`中的错误会在扩展轴中的索引包含重复项时错误地引发异常([GH 40096](https://github.com/pandas-dev/pandas/issues/40096))

+   在使用`MultiIndex`时,`DataFrame.loc.__getitem__()`中的错误会在至少一个索引列具有浮点类型且我们检索标量时转换为浮点数时引发异常([GH 41369](https://github.com/pandas-dev/pandas/issues/41369))

+   在`DataFrame.loc()`中的错误匹配非布尔索引元素([GH 20432](https://github.com/pandas-dev/pandas/issues/20432))

+   在具有`CategoricalIndex`的`Series`或`DataFrame`上使用`np.nan`进行索引时,当存在`np.nan`键时错误地引发`KeyError`([GH 41933](https://github.com/pandas-dev/pandas/issues/41933))

+   在使用`ExtensionDtype`的`Series.__delitem__()`中的错误会错误地转换为`ndarray`([GH 40386](https://github.com/pandas-dev/pandas/issues/40386))

+   在使用`CategoricalIndex`时,`DataFrame.at()`中的错误会在传递整数键时返回不正确的结果([GH 41846](https://github.com/pandas-dev/pandas/issues/41846))

+   在具有重复索引器的情况下,`DataFrame.loc()`返回的`MultiIndex`顺序错误([GH 40978](https://github.com/pandas-dev/pandas/issues/40978))

+   在使用 `DatetimeIndex` 时,`DataFrame.__setitem__()` 在使用 `str` 子类作为列名时引发 `TypeError` 的 Bug([GH 37366](https://github.com/pandas-dev/pandas/issues/37366)

+   `PeriodIndex.get_loc()` 中的 Bug 在给定具有不匹配 `freq` 的 `Period` 时未能引发 `KeyError`([GH 41670](https://github.com/pandas-dev/pandas/issues/41670))

+   在使用 `UInt64Index` 和负整数键时,Bug `.loc.__getitem__` 在某些情况下引发 `OverflowError` 而不是 `KeyError`,在其他情况下则转换为正整数([GH 41777](https://github.com/pandas-dev/pandas/issues/41777))

+   `Index.get_indexer()` 中的错误在某些情况下未能因无效的 `method`、`limit` 或 `tolerance` 参数而引发 `ValueError`([GH 41918](https://github.com/pandas-dev/pandas/issues/41918))

+   当使用无效字符串切片 `Series` 或 `DataFrame` 时,`TimedeltaIndex` 引发 `ValueError` 而不是 `TypeError` 的 Bug([GH 41821](https://github.com/pandas-dev/pandas/issues/41821))

+   `Index` 构造函数中的错误有时会悄悄地忽略指定的 `dtype`,导致问题([GH 38879](https://github.com/pandas-dev/pandas/issues/38879))

+   `Index.where()` 的行为现在与 `Index.putmask()` 的行为相匹配,即 `index.where(mask, other)` 与 `index.putmask(~mask, other)` 相匹配([GH 39412](https://github.com/pandas-dev/pandas/issues/39412))

### 缺失

+   `Grouper` 中的错误未正确传播 `dropna` 参数;`DataFrameGroupBy.transform()` 现在正确处理了 `dropna=True` 的缺失值([GH 35612](https://github.com/pandas-dev/pandas/issues/35612))

+   `isna()`、`Series.isna()`、`Index.isna()`、`DataFrame.isna()`中的 bug,以及相应的`notna`函数不识别`Decimal("NaN")`对象([GH 39409](https://github.com/pandas-dev/pandas/issues/39409))

+   `DataFrame.fillna()`中的 bug,不接受字典作为`downcast`关键字([GH 40809](https://github.com/pandas-dev/pandas/issues/40809))

+   `isna()`中的 bug,不返回可空类型的掩码副本,导致任何后续掩码修改都会更改原始数组([GH 40935](https://github.com/pandas-dev/pandas/issues/40935))

+   `DataFrame`构造中的 bug,当包含`NaN`的浮点数据和整数`dtype`时,转换而不是保留`NaN`([GH 26919](https://github.com/pandas-dev/pandas/issues/26919))

+   `Series.isin()`和`MultiIndex.isin()`中的 bug,如果它们位于元组中,则不会将所有 NaN 视为等效([GH 41836](https://github.com/pandas-dev/pandas/issues/41836))

### 多重索引

+   `DataFrame.drop()`中的 bug,在`MultiIndex`不唯一且未提供`level`时引发`TypeError`([GH 36293](https://github.com/pandas-dev/pandas/issues/36293))

+   `MultiIndex.intersection()`中的 bug,在结果中重复`NaN`([GH 38623](https://github.com/pandas-dev/pandas/issues/38623))

+   `MultiIndex.equals()`中的 bug,当`MultiIndex`包含`NaN`时错误地返回`True`,即使它们的顺序不同([GH 38439](https://github.com/pandas-dev/pandas/issues/38439))

+   `MultiIndex.intersection()`中的 bug,当与`CategoricalIndex`相交时,总是返回空结果([GH 38653](https://github.com/pandas-dev/pandas/issues/38653))

+   `MultiIndex.difference()`中的 bug,当索引包含不可排序的条目时错误地引发`TypeError`([GH 41915](https://github.com/pandas-dev/pandas/issues/41915))

+   `MultiIndex.reindex()` 存在 Bug,在空的 `MultiIndex` 上使用时,只对特定级别进行索引时会引发 `ValueError` ([GH 41170](https://github.com/pandas-dev/pandas/issues/41170))

+   `MultiIndex.reindex()` 存在 Bug,当重新对平坦的 `Index` 重新索引时引发 `TypeError` ([GH 41707](https://github.com/pandas-dev/pandas/issues/41707))

### I/O

+   `Index.__repr__()` 存在 Bug,当 `display.max_seq_items=1` 时 ([GH 38415](https://github.com/pandas-dev/pandas/issues/38415))

+   `read_csv()` 存在 Bug,在参数 `decimal` 设置为科学计数法且 `engine="python"` 时无法识别科学计数法 ([GH 31920](https://github.com/pandas-dev/pandas/issues/31920))

+   `read_csv()` 在解释 `NA` 值为注释时存在 Bug,当 `NA` 包含注释字符串时,对 `engine="python"` 进行了修复([GH 34002](https://github.com/pandas-dev/pandas/issues/34002))

+   `read_csv()` 存在 Bug,当具有多个标题列且指定了 `index_col` 时,文件没有数据行时引发 `IndexError` ([GH 38292](https://github.com/pandas-dev/pandas/issues/38292))

+   `read_csv()` 存在 Bug,在 `engine="python"` 的情况下,`usecols` 的长度与 `names` 不同时不被接受 ([GH 16469](https://github.com/pandas-dev/pandas/issues/16469))

+   `read_csv()` 存在 Bug,在指定 `delimiter=","`、`usecols` 和 `parse_dates` 时,返回对象 dtype,对于 `engine="python"` 的情况 ([GH 35873](https://github.com/pandas-dev/pandas/issues/35873))

+   `read_csv()` 存在 Bug,在 `engine="c"` 的情况下指定 `names` 和 `parse_dates` 会引发 `TypeError` ([GH 33699](https://github.com/pandas-dev/pandas/issues/33699))

+   `read_clipboard()` 和 `DataFrame.to_clipboard()` 在 WSL 中无法正常工作的 Bug ([GH 38527](https://github.com/pandas-dev/pandas/issues/38527))

+   允许为 `read_sql()`、`read_sql_query()` 和 `read_sql_table()` 的 `parse_dates` 参数设置自定义错误值 ([GH 35185](https://github.com/pandas-dev/pandas/issues/35185))

+   当尝试应用于`DataFrame`或`Series`的子类时,`DataFrame.to_hdf()`和`Series.to_hdf()`存在一个 bug,导致`KeyError`([GH 33748](https://github.com/pandas-dev/pandas/issues/33748))

+   在保存具有非字符串 dtype 的 DataFrame 时,`HDFStore.put()`存在一个 bug,导致错误的`TypeError`([GH 34274](https://github.com/pandas-dev/pandas/issues/34274))

+   在`json_normalize()`中存在一个 bug,导致生成器对象的第一个元素不包含在返回的 DataFrame 中([GH 35923](https://github.com/pandas-dev/pandas/issues/35923))

+   在应该解析日期列并且对`engine="python"`指定了`usecols`时,`read_csv()`存在一个 bug,将千位分隔符应用于日期列([GH 39365](https://github.com/pandas-dev/pandas/issues/39365))

+   在指定多个标题和索引列时,`read_excel()`存在一个 bug,前向填充`MultiIndex`名称([GH 34673](https://github.com/pandas-dev/pandas/issues/34673))

+   在`read_excel()`中存在一个 bug,未遵守`set_option()`([GH 34252](https://github.com/pandas-dev/pandas/issues/34252))

+   在可空布尔 dtype 上,`read_csv()`存在一个 bug,未切换`true_values`和`false_values`([GH 34655](https://github.com/pandas-dev/pandas/issues/34655))

+   在使用`orient="split"`时,`read_json()`存在一个 bug,未能保持数字字符串索引([GH 28556](https://github.com/pandas-dev/pandas/issues/28556))

+   如果`chunksize`为非零且查询未返回结果,则`read_sql()`将返回一个空生成器。现在返回一个包含单个空 DataFrame 的生成器([GH 34411](https://github.com/pandas-dev/pandas/issues/34411))

+   在使用`where`参数时,`read_hdf()`存在一个 bug,当在分类字符串列上进行过滤时,返回意外记录([GH 39189](https://github.com/pandas-dev/pandas/issues/39189))

+   Bug in `read_sas()` 在`datetimes`为 null 时引发`ValueError`([GH 39725](https://github.com/pandas-dev/pandas/issues/39725))

+   Bug in `read_excel()` 从单列电子表格中删除空值([GH 39808](https://github.com/pandas-dev/pandas/issues/39808))

+   Bug in `read_excel()` 对某些文件类型加载尾随的空行/列([GH 41167](https://github.com/pandas-dev/pandas/issues/41167))

+   Bug in `read_excel()` 当 excel 文件具有`MultiIndex`标题后跟两个空行且没有索引时,引发`AttributeError`([GH 40442](https://github.com/pandas-dev/pandas/issues/40442))

+   Bug in `read_excel()`,`read_csv()`,`read_table()`,`read_fwf()`和`read_clipboard()` 在`MultiIndex`标题后的一个空行会被删除([GH 40442](https://github.com/pandas-dev/pandas/issues/40442))

+   Bug in `DataFrame.to_string()` 当`index=False`时,错位截断列([GH 40904](https://github.com/pandas-dev/pandas/issues/40904))

+   Bug in `DataFrame.to_string()` 当`index=False`时,添加额外的点并错位截断行([GH 40904](https://github.com/pandas-dev/pandas/issues/40904))

+   Bug in `read_orc()` 总是引发`AttributeError`([GH 40918](https://github.com/pandas-dev/pandas/issues/40918))

+   Bug in `read_csv()` 和 `read_table()` 如果定义了`names`和`prefix`,则静默忽略`prefix`,现在引发`ValueError`([GH 39123](https://github.com/pandas-dev/pandas/issues/39123))

+   Bug in `read_csv()` 和 `read_excel()` 当`mangle_dupe_cols`设置为`True`时,不尊重重复列名的 dtype��[GH 35211](https://github.com/pandas-dev/pandas/issues/35211))

+   当 `delimiter` 和 `sep` 定义但 `sep` 被静默忽略时,`read_csv()` 现在会引发 `ValueError`([GH 39823](https://github.com/pandas-dev/pandas/issues/39823))

+   当之前调用了 `sys.setprofile` 时,`read_csv()` 和 `read_table()` 对参数的解释出现错误([GH 41069](https://github.com/pandas-dev/pandas/issues/41069))

+   在从 PyArrow 转换到 pandas(例如,用于读取 Parquet)时存在 bug,可空数据类型和 PyArrow 数组的数据缓冲区大小不是 dtype 大小的倍数时会出现问题([GH 40896](https://github.com/pandas-dev/pandas/issues/40896))

+   当 pandas 无法确定文件类型但用户指定了 `engine` 参数时,`read_excel()` 会引发错误([GH 41225](https://github.com/pandas-dev/pandas/issues/41225))

+   当在 excel 文件中复制时,如果第一列存在空值,则`read_clipboard()` 中的 bug 会将值移到错误的列中([GH 41108](https://github.com/pandas-dev/pandas/issues/41108))

+   当尝试将不兼容的列附加到字符串列时,`DataFrame.to_hdf()` 和 `Series.to_hdf()` 会引发 `TypeError`([GH 41897](https://github.com/pandas-dev/pandas/issues/41897))

### 周期

+   `Period` 对象或 `Index`、`Series` 或 `DataFrame` 之间的比较,如果 `PeriodDtype` 不匹配,现在会像其他不匹配类型的比较一样,对于相等返回 `False`,对于不相等返回 `True`,对于不相等的检查引发 `TypeError`([GH 39274](https://github.com/pandas-dev/pandas/issues/39274))

### 绘图

+   在传递 2D `ax` 参数时,`plotting.scatter_matrix()` 报错([GH 16253](https://github.com/pandas-dev/pandas/issues/16253))

+   当 Matplotlib 的 `constrained_layout` 启用时,防止出现警告([GH 25261](https://github.com/pandas-dev/pandas/issues/25261))

+   `DataFrame.plot()` 中的一个错误,如果该函数被重复调用,有些调用使用了`yerr`,而其他调用则没有,图例中显示的颜色是错误的([GH 39522](https://github.com/pandas-dev/pandas/issues/39522))

+   `DataFrame.plot()` 中的一个错误,如果该函数被重复调用,有些调用使用了`secondary_y`,而其他调用使用了`legend=False`,则图例中显示的颜色是错误的([GH 40044](https://github.com/pandas-dev/pandas/issues/40044))

+   `DataFrame.plot.box()` 中的一个错误,当选择了`dark_background`主题时,图中的上限或下限标记不可见([GH 40769](https://github.com/pandas-dev/pandas/issues/40769))

### Groupby/resample/rolling

+   `DataFrameGroupBy.agg()` 和 `SeriesGroupBy.agg()` 中的一个错误,即对 `PeriodDtype` 类型的列错误地过于激进地进行了转换([GH 38254](https://github.com/pandas-dev/pandas/issues/38254))

+   `SeriesGroupBy.value_counts()` 中的一个错误,即在分组的分类序列中未观察到的类别未被计入([GH 38672](https://github.com/pandas-dev/pandas/issues/38672))

+   `SeriesGroupBy.value_counts()` 中的一个错误,即在空的序列上引发了错误([GH 39172](https://github.com/pandas-dev/pandas/issues/39172))

+   `GroupBy.indices()` 中的一个错误,即在分组键中存在空值时,会包含不存在的索引([GH 9304](https://github.com/pandas-dev/pandas/issues/9304))

+   修复了 `DataFrameGroupBy.sum()` 和 `SeriesGroupBy.sum()` 中的一个错误,通过使用 Kahan 求和现在可以避免精度丢失([GH 38778](https://github.com/pandas-dev/pandas/issues/38778))

+   修复了 `DataFrameGroupBy.cumsum()`、`SeriesGroupBy.cumsum()`、`DataFrameGroupBy.mean()` 和 `SeriesGroupBy.mean()` 中的 Bug,通过使用 Kahan 求和导致精度丢失([GH 38934](https://github.com/pandas-dev/pandas/issues/38934))

+   `Resampler.aggregate()` 和 `DataFrame.transform()` 中的 Bug,在缺少键具有混合数据类型时抛出 `TypeError` 而不是 `SpecificationError`([GH 39025](https://github.com/pandas-dev/pandas/issues/39025))

+   `DataFrameGroupBy.idxmin()` 和 `DataFrameGroupBy.idxmax()` 中的 Bug,涉及 `ExtensionDtype` 列([GH 38733](https://github.com/pandas-dev/pandas/issues/38733))

+   `Series.resample()` 中的 Bug,当索引是由 `NaT` 组成的 `PeriodIndex` 时会引发异常([GH 39227](https://github.com/pandas-dev/pandas/issues/39227))

+   `RollingGroupby.corr()` 和 `ExpandingGroupby.corr()` 中的 Bug,当提供的 `other` 长度大于每个组时,分组列会返回 `0` 而不是 `np.nan`([GH 39591](https://github.com/pandas-dev/pandas/issues/39591))

+   `ExpandingGroupby.corr()` 和 `ExpandingGroupby.cov()` 中的 Bug,当提供的 `other` 长度大于每个组时,会返回 `1` 而不是 `np.nan`([GH 39591](https://github.com/pandas-dev/pandas/issues/39591))

+   `DataFrameGroupBy.mean()`、`SeriesGroupBy.mean()`、`DataFrameGroupBy.median()`、`SeriesGroupBy.median()` 和 `DataFrame.pivot_table()` 中的 Bug,未传播元数据([GH 28283](https://github.com/pandas-dev/pandas/issues/28283))

+   `Series.rolling()` 和 `DataFrame.rolling()` 中的 Bug,在窗口是偏移量且日期按降序排列时,未正确计算窗口边界([GH 40002](https://github.com/pandas-dev/pandas/issues/40002))

+   `Series.groupby()` 和 `DataFrame.groupby()` 中的 Bug,在空`Series`或`DataFrame`上直接使用`idxmax`、`idxmin`、`mad`、`min`、`max`、`sum`、`prod`和`skew`方法,或通过`apply`、`aggregate`或`resample`使用时,会丢失索引、列和/或数据类型([GH 26411](https://github.com/pandas-dev/pandas/issues/26411))

+   `DataFrameGroupBy.apply()` 和 `SeriesGroupBy.apply()` 中的 Bug,在`RollingGroupby`对象上使用时,会创建一个 `MultiIndex` 而不是一个 `Index`([GH 39732](https://github.com/pandas-dev/pandas/issues/39732))

+   `DataFrameGroupBy.sample()` 中的 Bug,在指定`weights`且索引为`Int64Index`时会引发错误([GH 39927](https://github.com/pandas-dev/pandas/issues/39927))

+   在`DataFrameGroupBy.aggregate()`和`Resampler.aggregate()`中的一个错误,有时会在传递字典并且缺少列时引发`SpecificationError`,现在将始终引发`KeyError`([GH 40004](https://github.com/pandas-dev/pandas/issues/40004))

+   在`DataFrameGroupBy.sample()`中的一个错误,计算结果之前未应用列选择([GH 39928](https://github.com/pandas-dev/pandas/issues/39928))

+   在调用`__getitem__`时,`ExponentialMovingWindow`中提供`times`会错误地引发`ValueError`的错误([GH 40164](https://github.com/pandas-dev/pandas/issues/40164))

+   在调用`__getitem__`时,`ExponentialMovingWindow`不会保留`com`、`span`、`alpha`或`halflife`属性([GH 40164](https://github.com/pandas-dev/pandas/issues/40164))

+   当使用`adjust=False`指定`times`时,`ExponentialMovingWindow`现在会引发`NotImplementedError`,因为计算不正确([GH 40098](https://github.com/pandas-dev/pandas/issues/40098))

+   在`ExponentialMovingWindowGroupby.mean()`中的一个错误,当`engine='numba'`时,会忽略`times`参数([GH 40951](https://github.com/pandas-dev/pandas/issues/40951))

+   在`ExponentialMovingWindowGroupby.mean()`中的一个错误,当存在多个分组时使用了错误的时间([GH 40951](https://github.com/pandas-dev/pandas/issues/40951))

+   `ExponentialMovingWindowGroupby`中的一个错误,导致非平凡分组的时间向量和数值不同步([GH 40951](https://github.com/pandas-dev/pandas/issues/40951))

+   在`Series.asfreq()`和`DataFrame.asfreq()`中的一个错误,当索引未排序时会丢失行([GH 39805](https://github.com/pandas-dev/pandas/issues/39805))

+   在对`DataFrame`进行聚合函数时,当给定`level`关键字参数时,不遵守`numeric_only`参数的错误([GH 40660](https://github.com/pandas-dev/pandas/issues/40660))

+   在`SeriesGroupBy.aggregate()`中存在的一个 bug,使用用户定义的函数来聚合具有对象类型`Index`的 Series 会导致不正确的`Index`形状([GH 40014](https://github.com/pandas-dev/pandas/issues/40014))

+   在`RollingGroupby`中存在的一个 bug,`groupby`中的`as_index=False`参数被忽略了([GH 39433](https://github.com/pandas-dev/pandas/issues/39433))

+   在`DataFrameGroupBy.any()`、`SeriesGroupBy.any()`、`DataFrameGroupBy.all()`和`SeriesGroupBy.all()`中存在的一个 bug,当在持有`NA`的可空类型列上使用时,即使`skipna=True`也会引发`ValueError`([GH 40585](https://github.com/pandas-dev/pandas/issues/40585))

+   在`DataFrameGroupBy.cummin()`、`SeriesGroupBy.cummin()`、`DataFrameGroupBy.cummax()`和`SeriesGroupBy.cummax()`中存在的一个 bug,会在`int64`实现边界附近不正确地四舍五入整数值([GH 40767](https://github.com/pandas-dev/pandas/issues/40767))

+   在`DataFrameGroupBy.rank()`和`SeriesGroupBy.rank()`中存在的一个 bug,具有可空 dtypes 的情况下不正确地引发`TypeError`([GH 41010](https://github.com/pandas-dev/pandas/issues/41010))

+   在使用`DataFrameGroupBy.cummin()`、`SeriesGroupBy.cummin()`、`DataFrameGroupBy.cummax()` 和 `SeriesGroupBy.cummax()` 时存在一个 bug,当将可为空的数据类型转换为浮点数时,太大而无法往返时,计算结果错误([GH 37493](https://github.com/pandas-dev/pandas/issues/37493))

+   在使用`DataFrame.rolling()`时存在一个 bug,如果计算不是数值稳定的,并且 `min_periods=0` 时,对所有 `NaN` 窗口返回的均值都为零([GH 41053](https://github.com/pandas-dev/pandas/issues/41053))

+   在使用`DataFrame.rolling()`时存在一个 bug,如果计算不是数值稳定的,并且 `min_periods=0` 时,对所有 `NaN` 窗口返回的总和不为零([GH 41053](https://github.com/pandas-dev/pandas/issues/41053))

+   在使用`SeriesGroupBy.agg()`时存在一个 bug,对保持有序的 `CategoricalDtype` 进行聚合时无法保留顺序,导致聚合失败([GH 41147](https://github.com/pandas-dev/pandas/issues/41147))

+   在使用`DataFrameGroupBy.min()`、`SeriesGroupBy.min()`、`DataFrameGroupBy.max()` 和 `SeriesGroupBy.max()` 时存在一个 bug,对多个对象类型列且 `numeric_only=False` 时,错误地引发 `ValueError`([GH 41111](https://github.com/pandas-dev/pandas/issues/41111))

+   `DataFrameGroupBy.rank()` 存在 bug,当 GroupBy 对象的 `axis=0` 并且 `rank` 方法的关键字 `axis=1` 时([GH 41320](https://github.com/pandas-dev/pandas/issues/41320))

+   `DataFrameGroupBy.__getitem__()` 存在 bug,当列不唯一时,错误返回一个格式不正确的 `SeriesGroupBy` 而不是 `DataFrameGroupBy`([GH 41427](https://github.com/pandas-dev/pandas/issues/41427))

+   `DataFrameGroupBy.transform()` 中存在 bug,当列不唯一时,错误地引发 `AttributeError`([GH 41427](https://github.com/pandas-dev/pandas/issues/41427))

+   `Resampler.apply()` 中存在 bug,当列不唯一时,错误地丢弃了重复的列([GH 41445](https://github.com/pandas-dev/pandas/issues/41445))

+   `Series.groupby()` 的聚合操作错误地返回空的 `Series` 而不是在其 dtype 无效的聚合操作上引发 `TypeError`,例如,使用 `datetime64[ns]` dtype 的 `.prod`([GH 41342](https://github.com/pandas-dev/pandas/issues/41342))

+   `DataFrameGroupBy` 的聚合操作在没有有效列时错误地未能删除该聚合的无效 dtype 的列([GH 41291](https://github.com/pandas-dev/pandas/issues/41291))

+   `DataFrame.rolling.__iter__()` 中存在 bug,未将 `on` 分配给结果对象的索引([GH 40373](https://github.com/pandas-dev/pandas/issues/40373))

+   `DataFrameGroupBy.transform()` 和 `DataFrameGroupBy.agg()` 中存在 bug,使用 `engine="numba"` 时,`*args` 与用户传递的函数一起被缓存([GH 41647](https://github.com/pandas-dev/pandas/issues/41647))

+   `DataFrameGroupBy` 方法 `agg`、`transform`、`sum`、`bfill`、`ffill`、`pad`、`pct_change`、`shift`、`ohlc` 丢失了 `.columns.names`([GH 41497](https://github.com/pandas-dev/pandas/issues/41497))

### 重塑

+   `merge()` 在部分索引上执行内连接并且 `right_index=True` 时,当索引之间没有重叠时,引发错误([GH 33814](https://github.com/pandas-dev/pandas/issues/33814))

+   在缺少级别的情况下,`DataFrame.unstack()`中的错误导致索引名称不正确([GH 37510](https://github.com/pandas-dev/pandas/issues/37510))

+   在`left_index=True`和`right_on`规范下,`merge_asof()`传播正确的索引而不是左索引([GH 33463](https://github.com/pandas-dev/pandas/issues/33463))

+   当一个或两个索引只有一个级别时,具有`MultiIndex`的 DataFrame 在`DataFrame.join()`上返回错误结果([GH 36909](https://github.com/pandas-dev/pandas/issues/36909))

+   在非数值合并列的情况下,`merge_asof()`现在会引发`ValueError`而不是晦涩的`TypeError`([GH 29130](https://github.com/pandas-dev/pandas/issues/29130))

+   当 DataFrame 具有至少一个维度具有非按字母顺序排序的`Categorical`类别的`MultiIndex`时,`DataFrame.join()`中的错误未正确分配值([GH 38502](https://github.com/pandas-dev/pandas/issues/38502))

+   `Series.value_counts()`和`Series.mode()`现在以原始顺序返回一致的键([GH 12679](https://github.com/pandas-dev/pandas/issues/12679),[GH 11227](https://github.com/pandas-dev/pandas/issues/11227)和[GH 39007](https://github.com/pandas-dev/pandas/issues/39007))

+   `DataFrame.stack()`中的错误未正确处理`MultiIndex`列中的`NaN`([GH 39481](https://github.com/pandas-dev/pandas/issues/39481))

+   当参数`func`为字符串,`axis=1`,且不支持轴参数时,`DataFrame.apply()`中的错误会导致结果不正确;现在会引发`ValueError`([GH 39211](https://github.com/pandas-dev/pandas/issues/39211))

+   在`ignore_index=True`时,`DataFrame.sort_values()`在按列排序后未正确重塑索引([GH 39464](https://github.com/pandas-dev/pandas/issues/39464))

+   `DataFrame.append()`中的错误,在`ExtensionDtype`数据类型的组合中返回不正确的数据类型([GH 39454](https://github.com/pandas-dev/pandas/issues/39454))

+   `DataFrame.append()`中的错误,在`datetime64`和`timedelta64`数据类型的组合中返回不正确的数据类型([GH 39574](https://github.com/pandas-dev/pandas/issues/39574))

+   `DataFrame.append()`中的错误,在带有`MultiIndex`的`DataFrame`中,追加一个`Index`不是`MultiIndex`的`Series`时([GH 41707](https://github.com/pandas-dev/pandas/issues/41707))

+   `DataFrame.pivot_table()`中的错误,在空 DataFrame 上操作时返回一个单个值的`MultiIndex`([GH 13483](https://github.com/pandas-dev/pandas/issues/13483))

+   `Index`现在可以传递给[`numpy.all()`](https://numpy.org/doc/stable/reference/generated/numpy.all.html#numpy.all "(在 NumPy v1.26 中)")函数([GH 40180](https://github.com/pandas-dev/pandas/issues/40180))

+   `DataFrame.stack()`中的错误,在`MultiIndex`中不保留`CategoricalDtype`([GH 36991](https://github.com/pandas-dev/pandas/issues/36991))

+   `to_datetime()`中的错误,在输入序列包含不可哈希项时引发错误([GH 39756](https://github.com/pandas-dev/pandas/issues/39756))

+   `Series.explode()`中的错误,在`ignore_index`为`True`且值为标量��保留索引([GH 40487](https://github.com/pandas-dev/pandas/issues/40487))

+   `to_datetime()`中的错误,在`Series`包含`None`和`NaT`且元素超过 50 个时引发`ValueError`([GH 39882](https://github.com/pandas-dev/pandas/issues/39882))

+   当包含时区感知的日期时间对象的对象 dtype 值不正确地引发 `TypeError` 时,`Series.unstack()` 和 `DataFrame.unstack()` 中的 bug([GH 41875](https://github.com/pandas-dev/pandas/issues/41875))

+   在 `DataFrame.melt()` 中,当 `DataFrame` 有用作 `value_vars` 的重复列时抛出 `InvalidIndexError` 的 bug([GH 41951](https://github.com/pandas-dev/pandas/issues/41951))

### Sparse

+   在 `DataFrame.sparse.to_coo()` 中,当列是一个没有 `0` 的数值 `Index` 时抛出 `KeyError` 的 bug([GH 18414](https://github.com/pandas-dev/pandas/issues/18414))

+   当 `copy=False` 时,`SparseArray.astype()` 从整数 dtype 转换为浮点 dtype 时产生不正确结果的 bug([GH 34456](https://github.com/pandas-dev/pandas/issues/34456))

+   `SparseArray.max()` 和 `SparseArray.min()` 始终返回空结果的 bug([GH 40921](https://github.com/pandas-dev/pandas/issues/40921))

### ExtensionArray

+   在 `DataFrame.where()` 中,当 `other` 是一个带有 `ExtensionDtype` 的 Series 时出现的 bug([GH 38729](https://github.com/pandas-dev/pandas/issues/38729))

+   修复了当底层数据为 `ExtensionArray` 时 `Series.idxmax()`、`Series.idxmin()`、`Series.argmax()` 和 `Series.argmin()` 会失败的 bug([GH 32749](https://github.com/pandas-dev/pandas/issues/32749)、[GH 33719](https://github.com/pandas-dev/pandas/issues/33719)、[GH 36566](https://github.com/pandas-dev/pandas/issues/36566))

+   修复了 `PandasExtensionDtype` 的子类的一些属性被错误地缓存的 bug([GH 40329](https://github.com/pandas-dev/pandas/issues/40329))

+   在 `DataFrame.mask()` 中,使用 `ExtensionDtype` 遮盖 DataFrame 时引发 `ValueError` 的 bug([GH 40941](https://github.com/pandas-dev/pandas/issues/40941))

### Styler

+   `Styler` 中的 `subset` 参数在某些有效的 MultiIndex 切片上引发错误([GH 33562](https://github.com/pandas-dev/pandas/issues/33562))

+   `Styler` 渲染的 HTML 输出已进行微小更改,以支持 w3 的良好代码标准([GH 39626](https://github.com/pandas-dev/pandas/issues/39626))

+   在 `Styler` 中,渲染的 HTML 缺少某些标题单元格的列类标识符([GH 39716](https://github.com/pandas-dev/pandas/issues/39716))

+   在 `Styler.background_gradient()` 中存在错误,文本颜色未正确确定([GH 39888](https://github.com/pandas-dev/pandas/issues/39888))

+   在 `Styler.set_table_styles()` 中存在错误,`table_styles` 参数中 CSS 选择器的多个元素未正确添加([GH 34061](https://github.com/pandas-dev/pandas/issues/34061))

+   在 Jupyter 中复制时,`Styler` 存在错误,导致顶部左侧单元格丢失并且标题对齐不正确([GH 12147](https://github.com/pandas-dev/pandas/issues/12147))

+   在 `Styler.where` 中存在错误,`kwargs` 未传递到适用的可调用函数中([GH 40845](https://github.com/pandas-dev/pandas/issues/40845))

+   `Styler` 中的错误导致 CSS 在多次渲染时重复出现([GH 39395](https://github.com/pandas-dev/pandas/issues/39395), [GH 40334](https://github.com/pandas-dev/pandas/issues/40334))

### 其他

+   `inspect.getmembers(Series)` 不再引发 `AbstractMethodError`([GH 38782](https://github.com/pandas-dev/pandas/issues/38782))

+   在 `Series.where()` 中存在错误,数值类型且 `other=None` 时未转换为 `nan`([GH 39761](https://github.com/pandas-dev/pandas/issues/39761))

+   修复了当属性具有未识别的 NA 类型时,`assert_series_equal()`、`assert_frame_equal()`、`assert_index_equal()` 和 `assert_extension_array_equal()` 不正确地引发异常的问题([GH 39461](https://github.com/pandas-dev/pandas/issues/39461))

+   修复了 `assert_index_equal()` 在使用 `exact=True` 时未能在比较 `CategoricalIndex` 实例与 `Int64Index` 和 `RangeIndex` 类别时引发错误的问题([GH 41263](https://github.com/pandas-dev/pandas/issues/41263))

+   修复了 `DataFrame.equals()`、`Series.equals()` 和 `Index.equals()` 在包含 `np.datetime64("NaT")` 或 `np.timedelta64("NaT")` 的对象 dtype 时的问题([GH 39650](https://github.com/pandas-dev/pandas/issues/39650))

+   修复了 `show_versions()` 中控制台 JSON 输出不是正确的 JSON 的问题([GH 39701](https://github.com/pandas-dev/pandas/issues/39701))

+   当使用 [xlc](https://www.ibm.com/products/xl-cpp-compiler-zos) 时,pandas 现在可以在 z/OS 上编译了([GH 35826](https://github.com/pandas-dev/pandas/issues/35826))

+   修复了当输入对象类型为 `DataFrame` 时,`pandas.util.hash_pandas_object()` 未能识别 `hash_key`、`encoding` 和 `categorize` 的问题([GH 41404](https://github.com/pandas-dev/pandas/issues/41404))  ## 贡献者

总共有 251 人为这个版本贡献了补丁。名字旁边带有“+”的人是第一次贡献补丁的。

+   Abhishek R +

+   Ada Draginda

+   Adam J. Stewart

+   Adam Turner +

+   Aidan Feldman +

+   Ajitesh Singh +

+   Akshat Jain +

+   Albert Villanova del Moral

+   Alexandre Prince-Levasseur +

+   Andrew Hawyrluk +

+   Andrew Wieteska

+   AnglinaBhambra +

+   Ankush Dua +

+   Anna Daglis

+   Ashlan Parker +

+   Ashwani +

+   Avinash Pancham

+   Ayushman Kumar +

+   BeanNan

+   Benoît Vinot

+   Bharat Raghunathan

+   Bijay Regmi +

+   Bobin Mathew +

+   Bogdan Pilyavets +

+   Brian Hulette +

+   Brian Sun +

+   Brock +

+   Bryan Cutler

+   Caleb +

+   Calvin Ho +

+   Chathura Widanage +

+   Chinmay Rane +

+   Chris Lynch

+   Chris Withers

+   Christos Petropoulos

+   Corentin Girard +

+   DaPy15 +

+   Damodara Puddu +

+   Daniel Hrisca

+   Daniel Saxton

+   DanielFEvans

+   Dare Adewumi +

+   Dave Willmer

+   David Schlachter +

+   David-dmh +

+   Deepang Raval +

+   Doris Lee +

+   Dr. Jan-Philip Gehrcke +

+   DriesS +

+   Dylan Percy

+   Erfan Nariman

+   Eric Leung

+   EricLeer +

+   Eve

+   Fangchen Li

+   Felix Divo

+   Florian Jetter

+   Fred Reiss

+   GFJ138 +

+   Gaurav Sheni +

+   Geoffrey B. Eisenbarth +

+   Gesa Stupperich +

+   Griffin Ansel +

+   Gustavo C. Maciel +

+   Heidi +

+   Henry +

+   Hung-Yi Wu +

+   Ian Ozsvald +

+   Irv Lustig

+   Isaac Chung +

+   Isaac Virshup

+   JHM Darbyshire (MBP) +

+   JHM Darbyshire (iMac) +

+   Jack Liu +

+   James Lamb +

+   Jeet Parekh

+   Jeff Reback

+   Jiezheng2018 +

+   Jody Klymak

+   Johan Kåhrström +

+   John McGuigan

+   Joris Van den Bossche

+   Jose

+   JoseNavy

+   Josh Dimarsky

+   Josh Friedlander

+   Joshua Klein +

+   Julia Signell

+   Julian Schnitzler +

+   Kaiqi Dong

+   Kasim Panjri +

+   Katie Smith +

+   Kelly +

+   Kenil +

+   Keppler, Kyle +

+   Kevin Sheppard

+   Khor Chean Wei +

+   Kiley Hewitt +

+   Larry Wong +

+   Lightyears +

+   Lucas Holtz +

+   Lucas Rodés-Guirao

+   Lucky Sivagurunathan +

+   Luis Pinto

+   Maciej Kos +

+   Marc Garcia

+   Marco Edward Gorelli +

+   Marco Gorelli

+   MarcoGorelli +

+   Mark Graham

+   Martin Dengler +

+   Martin Grigorov +

+   Marty Rudolf +

+   Matt Roeschke

+   Matthew Roeschke

+   Matthew Zeitlin

+   Max Bolingbroke

+   Maxim Ivanov

+   Maxim Kupfer +

+   Mayur +

+   MeeseeksMachine

+   Micael Jarniac

+   Michael Hsieh +

+   Michel de Ruiter +

+   Mike Roberts +

+   Miroslav Šedivý

+   Mohammad Jafar Mashhadi

+   Morisa Manzella +

+   Mortada Mehyar

+   Muktan +

+   Naveen Agrawal +

+   Noah

+   Nofar Mishraki +

+   Oleh Kozynets

+   Olga Matoula +

+   Oli +

+   Omar Afifi

+   Omer Ozarslan +

+   Owen Lamont +

+   Ozan Öğreden +

+   Pandas 开发团队

+   Paolo Lammens

+   Parfait Gasana +

+   Patrick Hoefler

+   Paul McCarthy +

+   Paulo S. Costa +

+   Pav A

+   Peter

+   Pradyumna Rahul +

+   Punitvara +

+   QP Hou +

+   Rahul Chauhan

+   Rahul Sathanapalli

+   Richard Shadrach

+   Robert Bradshaw

+   Robin to Roxel

+   Rohit Gupta

+   Sam Purkis +

+   Samuel GIFFARD +

+   Sean M. Law +

+   Shahar Naveh +

+   ShaharNaveh +

+   Shiv Gupta +

+   Shrey Dixit +

+   Shudong Yang +

+   Simon Boehm +

+   Simon Hawkins

+   Sioned Baker +

+   Stefan Mejlgaard +

+   Steven Pitman +

+   Steven Schaerer +

+   Stéphane Guillou +

+   TLouf +

+   Tegar D Pratama +

+   Terji Petersen

+   Theodoros Nikolaou +

+   Thomas Dickson

+   Thomas Li

+   Thomas Smith

+   Thomas Yu +

+   ThomasBlauthQC +

+   Tim Hoffmann

+   Tom Augspurger

+   Torsten Wörtwein

+   Tyler Reddy

+   UrielMaD

+   Uwe L. Korn

+   Venaturum +

+   VirosaLi

+   Vladimir Podolski

+   Vyom Pathak +

+   WANG Aiyong

+   Waltteri Koskinen +

+   Wenjun Si +

+   William Ayd

+   Yeshwanth N +

+   Yuanhao Geng

+   Zito Relova +

+   aflah02 +

+   arredond +

+   attack68

+   cdknox +

+   chinggg +

+   fathomer +

+   ftrihardjo +

+   github-actions[bot] +

+   gunjan-solanki +

+   guru kiran

+   hasan-yaman

+   i-aki-y +

+   jbrockmendel

+   jmholzer +

+   jordi-crespo +

+   jotasi +

+   jreback

+   juliansmidek +

+   kylekeppler

+   lrepiton +

+   lucasrodes

+   maroth96 +

+   mikeronayne +

+   mlondschien

+   moink +

+   morrme

+   mschmookler +

+   mzeitlin11

+   na2 +

+   nofarmishraki +

+   partev

+   patrick

+   ptype

+   realead

+   rhshadrach

+   rlukevie +

+   rosagold +

+   saucoide +

+   sdementen +

+   shawnbrown

+   sstiijn +

+   stphnlyd +

+   sukriti1 +

+   taytzehao

+   theOehrly +

+   theodorju +

+   thordisstella +

+   tonyyyyip +

+   tsinggggg +

+   tushushu +

+   vangorade +

+   vladu +

+   wertha +  ## 增强功能

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

当从 fsspec 未处理的远程 URL(例如 HTTP 和 HTTPS)读取时,将使用传递给 `storage_options` 的字典创建包含在请求中的标头。这可用于控制 User-Agent 标头或发送其他自定义标头 ([GH 36688](https://github.com/pandas-dev/pandas/issues/36688))。例如:

```py
In [1]: headers = {"User-Agent": "pandas"}
In [2]: df = pd.read_csv(
 ...:    "https://download.bls.gov/pub/time.series/cu/cu.item",
 ...:    sep="\t",
 ...:    storage_options=headers
 ...: ) 
```  ### 读取和写入 XML 文档

我们添加了对 [XML](https://www.w3.org/standards/xml/core) 文档的读取和渲染浅层版本的 I/O 支持,使用 `read_xml()` 和 `DataFrame.to_xml()`。使用 [lxml](https://lxml.de) 作为解析器,同时支持 XPath 1.0 和 XSLT 1.0。 ([GH 27554](https://github.com/pandas-dev/pandas/issues/27554))

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

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

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

欲知更多,请参阅 IO 工具用户指南中的 Writing XML。 ### Styler 增强功能

我们在 Styler 上进行了一些重点开发。另请参阅已修订和改进的 Styler 文档 (GH 39720, GH 39317, GH 40493).

  • 方法 Styler.set_table_styles() 现在可以接受更自然的 CSS 语言作为参数,例如 'color:red;' 而不是 [('color', 'red')] (GH 39563)
  • 方法 Styler.highlight_null()Styler.highlight_min()Styler.highlight_max() 现在允许自定义 CSS 高亮,而不是默认的背景着色 (GH 40242)
  • Styler.apply()现在接受在axis=None时返回ndarray的函数,使其与axis=0axis=1的行为保持一致(GH 39359
  • 当通过Styler.apply()Styler.applymap()提供格式不正确的 CSS 时,现在在渲染时会引发错误(GH 39660
  • Styler.format()现在接受关键字参数escape以进行可选的 HTML 和 LaTeX 转义(GH 40388GH 41619
  • Styler.background_gradient()现在具有参数gmap,用于提供特定的渐变映射以进行着色(GH 22727
  • Styler.clear()现在还会清除Styler.hidden_indexStyler.hidden_columnsGH 40484
  • 添加了方法Styler.highlight_between()GH 39821
  • 添加了方法Styler.highlight_quantile()GH 40926)
  • 添加了方法Styler.text_gradient()GH 41098
  • 添加了方法Styler.set_tooltips()以允许悬停提示;这可以用于增强交互式显示(GH 21266GH 40284
  • 新增了参数 precision 给方法Styler.format(),用于控制浮点数的显示(GH 40134
  • Styler 渲染的 HTML 输出现在遵循w3 HTML 样式指南GH 39626
  • Styler 类的许多特性现在部分或完全可以在具有非唯一索引或列的 DataFrame 上使用(GH 41143
  • 通过对索引或列的独立稀疏化,通过使用新的样式选项,可以更好地控制显示,这些选项也可以通过option_context() 使用(GH 41142
  • 新增了选项 styler.render.max_elements,以避免样式化大型 DataFrame 时浏览器过载(GH 40712
  • 新增了方法Styler.to_latex()GH 21673GH 42320),该方法还允许一些有限的 CSS 转换(GH 40731
  • 新增了方法Styler.to_html()GH 13379
  • 新增了方法Styler.set_sticky(),使索引和列标题在滚动 HTML 框架中永久可见(GH 29072) ### DataFrame 构造函数遵循 copy=False

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

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

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

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

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

In [4]: arr[0] = 0

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

当不传递 copy 时,默认行为将保持不变,即将进行复制。 ### PyArrow 支持的字符串数据类型

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

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

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

警告

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

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

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

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

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

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

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

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

常规的字符串访问方法有效。在适当的情况下,Series 或 DataFrame 的列的返回类型也将具有字符串 dtype。

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

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

返回整数的字符串访问方法将返回一个带有 Int64Dtype 的值

In [13]: s.str.count("a")
Out[13]: 
0       1
1    <NA>
2       0
dtype: Int64 
```  ### 居中的日期时间滚动窗口

在具有类似日期时间索引的 DataFrame 和 Series 对象上执行滚动计算时,现在可以使用居中的日期时间窗口([GH 38780](https://github.com/pandas-dev/pandas/issues/38780))。例如:

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

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

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

+   `DataFrame.rolling()`、`Series.rolling()`、`DataFrame.expanding()` 和 `Series.expanding()` 现在支持 `method` 参数,其中包含一个 `'table'` 选项,可以在整个 `DataFrame` 上执行窗口操作。请参阅窗口概述以了解性能和功能上的优势([GH 15095](https://github.com/pandas-dev/pandas/issues/15095)、[GH 38995](https://github.com/pandas-dev/pandas/issues/38995))

+   `ExponentialMovingWindow` 现在支持一个 `online` 方法,可以以在线方式执行 `mean` 计算。请参阅窗口概述([GH 41673](https://github.com/pandas-dev/pandas/issues/41673))

+   添加了 `MultiIndex.dtypes()`([GH 37062](https://github.com/pandas-dev/pandas/issues/37062))

+   在 `DataFrame.resample()` 的 `origin` 参数中添加了 `end` 和 `end_day` 选项 ([GH 37804](https://github.com/pandas-dev/pandas/issues/37804))

+   在 `read_csv()` 和 `engine="c"` 中,当 `usecols` 和 `names` 不匹配时改进了错误消息 ([GH 29042](https://github.com/pandas-dev/pandas/issues/29042))

+   在 窗口方法 中传递无效的 `win_type` 参数时,改进了错误消息的一致性 ([GH 15969](https://github.com/pandas-dev/pandas/issues/15969))

+   `read_sql_query()` 现在接受一个 `dtype` 参数,根据用户输入从 SQL 数据库中转换列式数据 ([GH 10285](https://github.com/pandas-dev/pandas/issues/10285))

+   当未指定 `usecols` 时,`read_csv()` 如果标题或给定名称的长度与数据长度不匹配,现在会引发 `ParserWarning` ([GH 21768](https://github.com/pandas-dev/pandas/issues/21768))

+   在使用 `DataFrame.to_sql()` 时,从 pandas 到 SQLAlchemy 的整数类型映射得到了改进 ([GH 35076](https://github.com/pandas-dev/pandas/issues/35076))

+   `to_numeric()` 现在支持将可空的 `ExtensionDtype` 对象进行降级 ([GH 33013](https://github.com/pandas-dev/pandas/issues/33013))

+   在 `MultiIndex.set_names` 和 `MultiIndex.rename` 中添加了对类似字典的名称的支持 ([GH 20421](https://github.com/pandas-dev/pandas/issues/20421))

+   `read_excel()` 现在可以自动检测 .xlsb 文件和旧的 .xls 文件 ([GH 35416](https://github.com/pandas-dev/pandas/issues/35416), [GH 41225](https://github.com/pandas-dev/pandas/issues/41225))

+   `ExcelWriter` 现在接受一个 `if_sheet_exists` 参数,在写入到现有工作表时控制追加模式的行为 ([GH 40230](https://github.com/pandas-dev/pandas/issues/40230))

+   `Rolling.sum()`, `Expanding.sum()`, `Rolling.mean()`, `Expanding.mean()`, `ExponentialMovingWindow.mean()`, `Rolling.median()`, `Expanding.median()`, `Rolling.max()`, `Expanding.max()`, `Rolling.min()`, 和 `Expanding.min()` 现在支持使用 `engine` 关键字进行 [Numba](http://numba.pydata.org/) 执行([GH 38895](https://github.com/pandas-dev/pandas/issues/38895), [GH 41267](https://github.com/pandas-dev/pandas/issues/41267))

+   `DataFrame.apply()` 现在可以接受 NumPy 的一元运算符作为字符串,例如 `df.apply("sqrt")`,这对于 `Series.apply()` 已经是这种情况了([GH 39116](https://github.com/pandas-dev/pandas/issues/39116))

+   `DataFrame.apply()` 现在可以接受非可调用的 DataFrame 属性作为字符串,例如 `df.apply("size")`,这对于 `Series.apply()` 已经是这种情况了([GH 39116](https://github.com/pandas-dev/pandas/issues/39116))

+   `DataFrame.applymap()` 现在可以接受关键字参数传递给用户提供的 `func`([GH 39987](https://github.com/pandas-dev/pandas/issues/39987))

+   现在不允许将 `DataFrame` 索引器传递给 `iloc` 以供 `Series.__getitem__()` 和 `DataFrame.__getitem__()` 使用([GH 39004](https://github.com/pandas-dev/pandas/issues/39004))

+   `Series.apply()` 现在可以接受类似列表或字典的参数,例如 `ser.apply(np.array(["sum", "mean"]))`,这对于 `DataFrame.apply()` 已经是这样了([GH 39140](https://github.com/pandas-dev/pandas/issues/39140))

+   `DataFrame.plot.scatter()` 现在可以接受一个分类列作为参数 `c`([GH 12380](https://github.com/pandas-dev/pandas/issues/12380), [GH 31357](https://github.com/pandas-dev/pandas/issues/31357))

+   当 Series 具有 `MultiIndex` 并且索引器的维度过多时,现在 `Series.loc()` 会提供有用的错误消息([GH 35349](https://github.com/pandas-dev/pandas/issues/35349))

+   `read_stata()` 现在支持从压缩文件中读取数据([GH 26599](https://github.com/pandas-dev/pandas/issues/26599))

+   添加了对带有负号的 `ISO 8601` 类似时间戳的解析支持到 `Timedelta`([GH 37172](https://github.com/pandas-dev/pandas/issues/37172))

+   在 `FloatingArray` 中添加了对一元运算符的支持([GH 38749](https://github.com/pandas-dev/pandas/issues/38749))

+   现在可以通过直接传递 `range` 对象来构造 `RangeIndex`,例如 `pd.RangeIndex(range(3))`([GH 12067](https://github.com/pandas-dev/pandas/issues/12067))

+   `Series.round()` 和 `DataFrame.round()` 现在可以处理可空整数和浮点数数据类型([GH 38844](https://github.com/pandas-dev/pandas/issues/38844))

+   `read_csv()` 和 `read_json()` 提供参数 `encoding_errors` 以控制如何处理编码错误([GH 39450](https://github.com/pandas-dev/pandas/issues/39450))

+   `DataFrameGroupBy.any()`, `SeriesGroupBy.any()`, `DataFrameGroupBy.all()`, 和 `SeriesGroupBy.all()` 使用 Kleene 逻辑处理可空数据类型([GH 37506](https://github.com/pandas-dev/pandas/issues/37506))

+   `DataFrameGroupBy.any()`, `SeriesGroupBy.any()`, `DataFrameGroupBy.all()`, 和 `SeriesGroupBy.all()` 对于包含可空数据类型的列返回 `BooleanDtype`([GH 33449](https://github.com/pandas-dev/pandas/issues/33449))

+   `DataFrameGroupBy.any()`, `SeriesGroupBy.any()`, `DataFrameGroupBy.all()`, 和 `SeriesGroupBy.all()` 在包含 `pd.NA` 的 `object` 数据中即使 `skipna=True` 也会引发异常([GH 37501](https://github.com/pandas-dev/pandas/issues/37501))

+   `DataFrameGroupBy.rank()` 和 `SeriesGroupBy.rank()` 现在支持 object-dtype 数据 ([GH 38278](https://github.com/pandas-dev/pandas/issues/38278))

+   使用 `data` 参数构造 `DataFrame` 或 `Series`,其为 Python 可迭代对象但*不是*由 NumPy `ndarray` 组成的 NumPy 标量时,现在会导致 dtype 具有最大 NumPy 标量的精度;当 `data` 是 NumPy `ndarray` 时,情况已经是这样了 ([GH 40908](https://github.com/pandas-dev/pandas/issues/40908))

+   向 `pivot_table()` 添加关键字 `sort`,以允许结果不进行排序 ([GH 39143](https://github.com/pandas-dev/pandas/issues/39143))

+   向 `DataFrame.value_counts()` 添加关键字 `dropna`,以允许计算包含 `NA` 值的行数 ([GH 41325](https://github.com/pandas-dev/pandas/issues/41325))

+   `Series.replace()` 现在在可能的情况下将结果转换为 `PeriodDtype` 而不是 `object` dtype ([GH 41526](https://github.com/pandas-dev/pandas/issues/41526))

+   在 `Rolling`、`Expanding` 和 `ExponentialMovingWindow` 的 `corr` 和 `cov` 方法中,当 `other` 不是 `DataFrame` 或 `Series` 时,改进了错误信息的显示 ([GH 41741](https://github.com/pandas-dev/pandas/issues/41741))

+   `Series.between()` 现在可以接受 `left` 或 `right` 作为 `inclusive` 参数的参数,以仅包含左边界或右边界 ([GH 40245](https://github.com/pandas-dev/pandas/issues/40245))

+   `DataFrame.explode()` 现在支持同时展开多列。其 `column` 参数现在也接受一个字符串列表或元组,以同时在多列上进行展开 ([GH 39240](https://github.com/pandas-dev/pandas/issues/39240))

+   现在,`DataFrame.sample()`接受`ignore_index`参数,在抽样后重置索引,类似于`DataFrame.drop_duplicates()`和`DataFrame.sort_values()`([GH 38581](https://github.com/pandas-dev/pandas/issues/38581))。 ### 读取 csv 或 json 文件时自定义 HTTP(s) 标头

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

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

读写 XML 文档

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

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

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

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

更多信息,请参阅 IO 工具中的用户指南中的编写 XML 部分。

Styler 增强

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

  • 方法Styler.set_table_styles()现在可以接受更自然的 CSS 语言作为参数,例如'color:red;',而不是[('color', 'red')]GH 39563
  • 方法Styler.highlight_null()Styler.highlight_min()Styler.highlight_max() 现在允许自定义 CSS 高亮,而不是默认的背景颜色(GH 40242)
  • Styler.apply() 现在接受返回 ndarray 的函数,当 axis=None 时,使其与 axis=0axis=1 的行为保持一致(GH 39359)
  • 当通过Styler.apply()Styler.applymap()提供格式不正确的 CSS 时,渲染时会引发错误(GH 39660)
  • Styler.format() 现在接受关键字参数 escape,用于可选的 HTML 和 LaTeX 转义(GH 40388, GH 41619)
  • Styler.background_gradient() 现在增加了参数 gmap,以提供特定的渐变映射进行着色(GH 22727)
  • Styler.clear() 现在还会清除 Styler.hidden_indexStyler.hidden_columnsGH 40484)
  • 添加了方法 Styler.highlight_between()GH 39821)
  • 添加了方法 Styler.highlight_quantile()GH 40926)
  • 添加了方法Styler.text_gradient()GH 41098
  • 添加了方法Styler.set_tooltips(),以允许悬停提示;这可以用于增强交互式显示(GH 21266, GH 40284
  • 添加了参数 precision 到方法Styler.format(),以控制浮点数的显示(GH 40134
  • Styler 渲染的 HTML 输出现在遵循w3 HTML Style GuideGH 39626
  • 现在Styler 类的许多功能现在部分或完全可用于具有非唯一索引或列的 DataFrame(GH 41143
  • 通过分别稀疏化索引或列,可以通过新的 styler 选项更好地控制显示,这些选项也可以通过option_context()使用(GH 41142
  • 添加了选项 styler.render.max_elements,以避免在样式化大型数据帧时浏览器超载(GH 40712
  • 添加了方法Styler.to_latex()GH 21673, GH 42320),该方法还允许进行一些有限的 CSS 转换(GH 40731
  • 添加了方法Styler.to_html()GH 13379
  • 添加了方法 Styler.set_sticky(),以使索引和列标题在滚动 HTML 框架中永久可见(GH 29072)。

DataFrame 构造函数遵循 copy=False 与字典

当将字典传递给 DataFramecopy=False 时,将不再进行复制(GH 32960)。

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

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

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

df["A"] 仍然是 arr 的视图:

In [4]: arr[0] = 0

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

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

使用 PyArrow 支持的字符串数据类型

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

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

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

警告

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

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

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

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

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

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

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

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

常规字符串访问器方法有效。在适当的情况下,DataFrame 的 Series 或列的返回类型也将具有字符串 dtype。

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

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

返回整数的字符串访问器方法将返回具有 Int64Dtype 的值。

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

居中的类似日期时间的滚动窗口

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

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

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

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

其他增强功能

  • DataFrame.rolling(), Series.rolling(), DataFrame.expanding(), 和 Series.expanding() 现在支持一个带有 'table' 选项的 method 参数,该选项在整个 DataFrame 上执行窗口操作。查看 Window Overview 以了解性能和功能上的好处 (GH 15095, GH 38995)

  • ExponentialMovingWindow 现在支持一种 online 方法,可以以在线方式进行 mean 计算。查看 Window Overview (GH 41673)

  • 添加了 MultiIndex.dtypes() (GH 37062)

  • DataFrame.resample() 中为 origin 参数添加了 endend_day 选项 (GH 37804)

  • read_csv() 中,当 usecolsnames 不匹配时,改进了错误消息,且 engine="c" (GH 29042)

  • 在 Window methods 中传递无效的 win_type 参数时,改进了错误消息的一致性 (GH 15969)

  • read_sql_query() 现在接受一个 dtype 参数,根据用户输入对来自 SQL 数据库的列数据进行转换 (GH 10285)

  • usecols 未指定时��如果头部或给定名称的长度与数据长度不匹配,read_csv() 现在会引发 ParserWarning (GH 21768)

  • 在使用 DataFrame.to_sql() 时,改进了从 pandas 到 SQLAlchemy 的整数类型映射 (GH 35076)

  • to_numeric()现在支持可空ExtensionDtype对象的降级转换(GH 33013)

  • MultiIndex.set_namesMultiIndex.rename中添加了对类似字典的名称的支持(GH 20421

  • read_excel()现在可以自动检测 .xlsb 文件和旧版 .xls 文件(GH 35416, GH 41225

  • ExcelWriter现在接受一个if_sheet_exists参数,用于控制在写入现有工作表时附加模式的行为(GH 40230

  • Rolling.sum()Expanding.sum()Rolling.mean()Expanding.mean()ExponentialMovingWindow.mean()Rolling.median()Expanding.median()Rolling.max()Expanding.max()Rolling.min()Expanding.min()现在支持Numba执行,使用engine关键字(GH 38895GH 41267)

  • DataFrame.apply()现在可以接受 NumPy 一元运算符作为字符串,例如df.apply("sqrt"),这在Series.apply()中已经存在(GH 39116)

  • DataFrame.apply()现在可以接受非可调用的 DataFrame 属性作为字符串,例如df.apply("size"),这在Series.apply()中已经存在(GH 39116)

  • DataFrame.applymap()现在可以接受 kwargs 传递给用户提供的funcGH 39987)

  • 现在不允许将DataFrame索引器传递给iloc用于Series.__getitem__()DataFrame.__getitem__()GH 39004)

  • Series.apply()现在可以接受类似列表或字典的参数,而不是列表或字典,例如ser.apply(np.array(["sum", "mean"])),这在DataFrame.apply()中已经存在(GH 39140)

  • DataFrame.plot.scatter()现在可以接受分类列作为参数cGH 12380, GH 31357)

  • Series.loc()现在在 Series 具有MultiIndex且索引器维度过多时会引发有用的错误消息(GH 35349)

  • read_stata()现在支持从压缩文件中读取数据(GH 26599)

  • 添加了对带有负号的ISO 8601-like 时间戳的解析支持到Timedelta中(GH 37172)

  • FloatingArray中添加了对一元运算符的支持(GH 38749)

  • RangeIndex现在可以通过直接传递range对象来��造,例如pd.RangeIndex(range(3))GH 12067)

  • Series.round()DataFrame.round()现在可以处理可空整数和浮点数数据类型(GH 38844)

  • read_csv()read_json() 提供了参数 encoding_errors 来控制如何处理编码错误 (GH 39450)

  • DataFrameGroupBy.any(), SeriesGroupBy.any(), DataFrameGroupBy.all(), 和 SeriesGroupBy.all() 使用 Kleene 逻辑与可空数据类型 (GH 37506)

  • DataFrameGroupBy.any(), SeriesGroupBy.any(), DataFrameGroupBy.all(), 和 SeriesGroupBy.all() 返回一个 BooleanDtype 对于具有可空数据类型的列 (GH 33449)

  • DataFrameGroupBy.any(), SeriesGroupBy.any(), DataFrameGroupBy.all(), 和 SeriesGroupBy.all() 即使 skipna=True 时引发 object 数据包含 pd.NA (GH 37501)

  • DataFrameGroupBy.rank()SeriesGroupBy.rank() 现在支持对象 dtype 数据(GH 38278)

  • 使用 Python 可迭代对象构造DataFrameSeries时,如果data参数不是由 NumPy ndarray组成的 NumPy 标量,dtype 将具有 NumPy 标量的最大精度;当data是 NumPy ndarray时已经是这种情况(GH 40908)

  • pivot_table()中添加关键字sort,以允许结果不排序(GH 39143)

  • DataFrame.value_counts()中添加关键字dropna,以允许计算包含NA值的行数(GH 41325)

  • Series.replace() 现在将结果尽可能转换为PeriodDtype,而不是object dtype(GH 41526)

  • other不是DataFrameSeries时,在RollingExpandingExponentialMovingWindowcorrcov方法中改进了错误消息(GH 41741)

  • Series.between() 现在可以接受leftright作为inclusive参数的参数,以仅包括左边界或右边界(GH 40245)

  • DataFrame.explode() 现在支持同时爆炸多列。其column参数现在也接受一个 str 或元组列表,以同时在多列上爆炸(GH 39240)

  • DataFrame.sample() 现在接受 ignore_index 参数以在抽样后重置索引,类似于 DataFrame.drop_duplicates()DataFrame.sort_values() (GH 38581)

显著的错误修复

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

Categorical.unique 现在始终保持与原始相同的 dtype

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

例如,给定:

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

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

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

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

先前的行为

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

新的行为

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

In [22]: original.dtype == unique.dtype
Out[22]: True 
```  ### 在 `DataFrame.combine_first()` 中保留 dtype

`DataFrame.combine_first()` 现在会保留 dtype ([GH 7509](https://github.com/pandas-dev/pandas/issues/7509))

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

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

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

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

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

先前的行为

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

新的行为

In [28]: combined.dtypes
Out[28]: 
A    float64
B      int64
C    float64
dtype: object 
```  ### Groupby 方法 agg 和 transform 不再更改可调用函数的返回 dtype

以前的方法 `DataFrameGroupBy.aggregate()`,`SeriesGroupBy.aggregate()`,`DataFrameGroupBy.transform()` 和 `SeriesGroupBy.transform()` 在参数 `func` 是可调用时可能会转换结果的 dtype,可能导致不希望的结果([GH 21240](https://github.com/pandas-dev/pandas/issues/21240))。如果结果是数值型并且将其转换回输入 dtype 不会更改任何值(通过 `np.allclose` 衡量),则会发生转换。现在不再发生此类转换。

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

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

先前的行为

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

新的行为

In [31]: df.groupby('key').agg(lambda x: x.sum())
Out[31]: 
 a  b
key 
1    1  2 
```  ### `DataFrameGroupBy.mean()`, `DataFrameGroupBy.median()`, 和 `GDataFrameGroupBy.var()`, `SeriesGroupBy.mean()`, `SeriesGroupBy.median()`, 和 `SeriesGroupBy.var()` 的 `float` 结果

以前,这些方法可能会根据输入值产生不同的 dtype。现在,这些方法将始终返回浮点 dtype。 ([GH 41137](https://github.com/pandas-dev/pandas/issues/41137))

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

以前的行为

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

新行为

In [33]: df.groupby(df.index).mean()
Out[33]: 
 a    b    c
0  1.0  1.0  1.0 
```  ### 尝试在使用 `loc` 和 `iloc` 设置值时进行原位操作

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

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

In [35]: values = df.values

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

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

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

以前的行为

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

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

新行为

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

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

In [40]: np.shares_memory(df["A"], values)
Out[40]: True 
```  ### 在设置 `frame[keys] = values` 时永不原地操作

当使用 `frame[keys] = values` 设置多列时,新数组将替换这些键的预先存在的数组,这些键将*不*被覆盖 ([GH 39510](https://github.com/pandas-dev/pandas/issues/39510))。因此,列将保留 `values` 的 dtype(s),不会转换为现有数组的 dtype(s)。

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

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

在旧行为中,5 被转换为 float64 并插入到现有数组中作为 df 的支撑:

以前的行为

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

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

新行为

In [43]: df.dtypes
Out[43]: 
A    int64
dtype: object 
```  ### 设置布尔系列时的一致转换

使用 `dtype=bool` 的 `Series` 中设置非布尔值现在一致地转换为 `dtype=object` ([GH 38709](https://github.com/pandas-dev/pandas/issues/38709))

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

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

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

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

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

以前的行为

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

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

新行为

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

In [2]:ser2
Out [2]:
0    True
1     2.0
dtype: object 
```  ### DataFrameGroupBy.rolling 和 SeriesGroupBy.rolling 不再在值中返回 grouped-by 列

group-by 列现在将从 `groupby.rolling` 操作的结果中删除 ([GH 32262](https://github.com/pandas-dev/pandas/issues/32262))

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

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

以前的行为

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

新行为

In [46]: df.groupby("A").rolling(2).sum()
Out[46]: 
 B
A 
1 0  NaN
 1  1.0
2 2  NaN
3 3  NaN 
```  ### 移除滚动方差和标准差的人为截断

`Rolling.std()` 和 `Rolling.var()` 现在不会人为地将小于 `~1e-8` 和 `~1e-15` 的结果截断为零 ([GH 37051](https://github.com/pandas-dev/pandas/issues/37051), [GH 40448](https://github.com/pandas-dev/pandas/issues/40448), [GH 39872](https://github.com/pandas-dev/pandas/issues/39872))。

但是,当对较大值进行滚动操作时,结果中可能存在浮点数伪像。

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

In [48]: s.rolling(3).var()
Out[48]: 
0         NaN
1         NaN
2    1.333333
3    0.000000
dtype: float64 
```  ### DataFrameGroupBy.rolling 和 SeriesGroupBy.rolling 在具有 MultiIndex 的结果中不再删除级别

`DataFrameGroupBy.rolling()` 和 `SeriesGroupBy.rolling()` 现在不会在结果中删除具有 `MultiIndex` 的 `DataFrame` 的级别。这可能导致结果中的 `MultiIndex` 中级别的看似重复,但此更改恢复了版本 1.1.3 中存在的行为 ([GH 38787](https://github.com/pandas-dev/pandas/issues/38787), [GH 38523](https://github.com/pandas-dev/pandas/issues/38523))。

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

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

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

之前的行为

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

新的行为

In [52]: df.groupby('label1').rolling(1).sum()
Out[52]: 
 a    b
label1 label1 label2 
idx1   idx1   idx2    1.0  2.0 
```  ### `Categorical.unique` 现在始终保持与原始数据类型相同

以前,当使用分类数据调用 `Categorical.unique()` 时,新数组中的未使用的类别会被移除,使得新数组的数据类型与原始数据类型不同 ([GH 18291](https://github.com/pandas-dev/pandas/issues/18291))

举例说明,给定:

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

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

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

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

之前的行为

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

新的行为

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

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

DataFrame.combine_first() 中保留数据类型

DataFrame.combine_first() 现在会保留数据类型 (GH 7509)

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

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

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

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

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

之前的行为

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

新的行为

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

Groupby 方法 agg 和 transform 不再改变可调用对象的返回数据类型

以前,当参数 func 可调用时,方法 DataFrameGroupBy.aggregate()SeriesGroupBy.aggregate()DataFrameGroupBy.transform()SeriesGroupBy.transform() 可能会转换结果的 dtype,可能导致不良结果 (GH 21240)。如果结果是数值型并且将其转换回输入 dtype 不会改变任何值(由 np.allclose 测量),则会发生转换。现在不会发生这种转换。

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

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

以前的行为

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

新的行为

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

DataFrameGroupBy.mean()DataFrameGroupBy.median()GDataFrameGroupBy.var() 的结果为 floatSeriesGroupBy.mean()SeriesGroupBy.median()SeriesGroupBy.var() 的结果为 float

以前,这些方法可能会根据输入值的不同而产生不同的 dtype。现在,这些方法将始终返回 float 类型。(GH 41137)

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

以前的行为

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

新的行为

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

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

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

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

In [35]: values = df.values

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

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

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

以前的行为

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

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

新的行为

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

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

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

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

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

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

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

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

以前的行为

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

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

新行为

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

设置到布尔 Series 中的一致转换

将非布尔值设置到 dtype=boolSeries 中现在一致地转换为 dtype=object (GH 38709)

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

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

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

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

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

以前的行为

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

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

新行为

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

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

DataFrameGroupBy.rolling 和 SeriesGroupBy.rolling 不再在值中返回按组分组的列

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

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

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

以前的行为

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

新行为

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

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

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

然而,在滚动到较大值时,结果中现在可能存在浮点数伪影。

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

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

DataFrameGroupBy.rolling 和 SeriesGroupBy.rolling 在结果中不再删除具有 MultiIndex 的级别

DataFrameGroupBy.rolling()SeriesGroupBy.rolling() 现在不再在结果中删除 DataFrame 中具有 MultiIndex 的级别。 这可能导致结果 MultiIndex 中级别的重复,但此更改恢复了版本 1.1.3 中存在的行为 (GH 38787, GH 38523)。

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

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

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

以前的行为

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

新行为

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

不向后兼容的 API 更改

增加了依赖项的最低版本

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

最低版本 必需 已更改
numpy 1.17.3 X X
pytz 2017.3 X
python-dateutil 2.7.3 X
bottleneck 1.2.1
numexpr 2.7.0 X
pytest (dev) 6.0 X
mypy (dev) 0.812 X
setuptools 38.6.0 X

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

Package Minimum Version Changed
beautifulsoup4 4.6.0
fastparquet 0.4.0 X
fsspec 0.7.4
gcsfs 0.6.0
lxml 4.3.0
matplotlib 2.2.3
numba 0.46.0
openpyxl 3.0.0 X
pyarrow 0.17.0 X
pymysql 0.8.1 X
pytables 3.5.1
s3fs 0.4.0
scipy 1.2.0
sqlalchemy 1.3.0 X
tabulate 0.8.7 X
xarray 0.12.0
xlrd 1.2.0
xlsxwriter 1.0.2
xlwt 1.3.0
pandas-gbq 0.12.0

有关更多信息,请参见 Dependencies 和 Optional dependencies ### 其他 API 更改

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

  • 访问DataFrame上的_constructor_expanddimSeries上的_constructor_sliced现在会引发AttributeError。以前会引发NotImplementedErrorGH 38782

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

  • PeriodIndex字符串表示中删除了冗余的freqGH 41653

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

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

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

  • 不再在 wheel 或源分发中包含 .pptx.pdf 格式的文档。(GH 30741) ### 增加依赖项的最低版本

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

Package Minimum Version Required Changed
numpy 1.17.3 X X
pytz 2017.3 X
python-dateutil 2.7.3 X
bottleneck 1.2.1
numexpr 2.7.0 X
pytest (dev) 6.0 X
mypy (dev) 0.812 X
setuptools 38.6.0 X

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

Package Minimum Version Changed
beautifulsoup4 4.6.0
fastparquet 0.4.0 X
fsspec 0.7.4
gcsfs 0.6.0
lxml 4.3.0
matplotlib 2.2.3
numba 0.46.0
openpyxl 3.0.0 X
pyarrow 0.17.0 X
pymysql 0.8.1 X
pytables 3.5.1
s3fs 0.4.0
scipy 1.2.0
sqlalchemy 1.3.0 X
tabulate 0.8.7 X
xarray 0.12.0
xlrd 1.2.0
xlsxwriter 1.0.2
xlwt 1.3.0
pandas-gbq 0.12.0

更多信息请参见依赖项和可选依赖项。

其他 API 变更

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

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

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

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

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

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

  • Styler.from_custom_template() 现在有两个新参数用于模板名称,并删除了旧的 name,因为引入了模板继承以便更好地解析 (GH 42053)。也需要修改 Styler 属性的子类。

构建

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

弃用

在 DataFrame 缩减和 DataFrameGroupBy 操作中弃用删除无用列

在带有 numeric_only=None(默认值)的 DataFrame 上调用缩减(例如 .min.max.sum),对于缩减引发 TypeError 的列会被默默地忽略并从结果中删除。

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

例如:

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

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

旧行为:

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

未来行为:

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

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

同样,在应用函数到DataFrameGroupBy时,当前对函数引发TypeError的列会被静默地忽略并从结果中删除。

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

例如:

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

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

旧的行为

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

未来的行为

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

In [6]: gb[["A"]].prod(numeric_only=False)
Out[6]:
 A
1   2
2  12 
```  ### 其他废弃

+   废弃了允许标量传递给`Categorical`构造函数 ([GH 38433](https://github.com/pandas-dev/pandas/issues/38433))

+   废弃了在不传递类似列表数据的情况下构造`CategoricalIndex` ([GH 38944](https://github.com/pandas-dev/pandas/issues/38944))

+   废弃了在`Index`构造函数中允许子类特定关键字参数的用法,直接使用具体的子类代替([GH 14093](https://github.com/pandas-dev/pandas/issues/14093),[GH 21311](https://github.com/pandas-dev/pandas/issues/21311),[GH 22315](https://github.com/pandas-dev/pandas/issues/22315),[GH 26974](https://github.com/pandas-dev/pandas/issues/26974))

+   废弃了 datetimelike (`timedelta64[ns]`, `datetime64[ns]`, `Datetime64TZDtype`, `PeriodDtype`) 的`astype()`方法用于转换为整数 dtype,改用`values.view(...)`代替 ([GH 38544](https://github.com/pandas-dev/pandas/issues/38544))。这个废弃在 pandas 1.4.0 中被撤销了。

+   废弃了`MultiIndex.is_lexsorted()`和`MultiIndex.lexsort_depth()`,改用`MultiIndex.is_monotonic_increasing()`代替 ([GH 32259](https://github.com/pandas-dev/pandas/issues/32259))

+   在`Series.where()`,`Series.mask()`,`DataFrame.where()`,`DataFrame.mask()`中废弃了关键字`try_cast`,如果需要,手动转换结果 ([GH 38836](https://github.com/pandas-dev/pandas/issues/38836))

+   废弃了使用`datetime.date`对象比较`Timestamp`对象。例如,不要使用`ts <= mydate`,而要使用`ts <= pd.Timestamp(mydate)`或`ts.date() <= mydate` ([GH 36131](https://github.com/pandas-dev/pandas/issues/36131))

+   废弃了`Rolling.win_type`返回`"freq"` ([GH 38963](https://github.com/pandas-dev/pandas/issues/38963))

+   废弃了`Rolling.is_datetimelike` ([GH 38963](https://github.com/pandas-dev/pandas/issues/38963))

+   弃用`Series.__setitem__()`和`DataFrame.__setitem__()`的`DataFrame`索引器([GH 39004](https://github.com/pandas-dev/pandas/issues/39004))

+   弃用`ExponentialMovingWindow.vol()`([GH 39220](https://github.com/pandas-dev/pandas/issues/39220))

+   使用`.astype`在`datetime64[ns]` dtype 和`DatetimeTZDtype`之间进行转换已被弃用,并将在未来版本中引发错误,应改用`obj.tz_localize`或`obj.dt.tz_localize`([GH 38622](https://github.com/pandas-dev/pandas/issues/38622))

+   当作为`DataFrame.unstack()`、`DataFrame.shift()`、`Series.shift()`和`DataFrame.reindex()`中的`fill_value`时,不再将`datetime.date`对象转换为`datetime64`,而是应传递`pd.Timestamp(dateobj)`([GH 39767](https://github.com/pandas-dev/pandas/issues/39767))

+   弃用`Styler.set_na_rep()`和`Styler.set_precision()`,而使用具有`na_rep`和`precision`作为现有和新输入参数的`Styler.format()`([GH 40134](https://github.com/pandas-dev/pandas/issues/40134), [GH 40425](https://github.com/pandas-dev/pandas/issues/40425))

+   弃用`Styler.where()`,建议使用具有`Styler.applymap()`的替代方案([GH 40821](https://github.com/pandas-dev/pandas/issues/40821))

+   在`Series.transform()`和`DataFrame.transform()`中,当`func`类似于列表或字典并引发除`TypeError`之外的任何异常时,不再允许部分失败;未来版本中引发除`TypeError`之外的任何异常的`func`将引发错误([GH 40211](https://github.com/pandas-dev/pandas/issues/40211))

+   在`read_csv()`和`read_table()`中,不再支持参数`error_bad_lines`和`warn_bad_lines`,而是支持参数`on_bad_lines`([GH 15122](https://github.com/pandas-dev/pandas/issues/15122))

+   弃用了在 `DataFrame` 构造函数中支持 `np.ma.mrecords.MaskedRecords`,请改用 `{name: data[name] for name in data.dtype.names}` ([GH 40363](https://github.com/pandas-dev/pandas/issues/40363))

+   弃用了在不同层次级别上使用 `merge()`、`DataFrame.merge()` 和 `DataFrame.join()` ([GH 34862](https://github.com/pandas-dev/pandas/issues/34862))

+   弃用了在 `ExcelWriter` 中使用 `**kwargs`;改用关键字参数 `engine_kwargs` ([GH 40430](https://github.com/pandas-dev/pandas/issues/40430))

+   弃用了对 `DataFrame` 和 `Series` 聚合的 `level` 关键字;改用 groupby 代替 ([GH 39983](https://github.com/pandas-dev/pandas/issues/39983))

+   弃用了 `Categorical.remove_categories()`、`Categorical.add_categories()`、`Categorical.reorder_categories()`、`Categorical.rename_categories()`、`Categorical.set_categories()` 的 `inplace` 参数,并将在将来的版本中移除 ([GH 37643](https://github.com/pandas-dev/pandas/issues/37643))

+   弃用了 `merge()` 在通过 `suffixes` 关键字产生重复列和已存在列时的行为 ([GH 22818](https://github.com/pandas-dev/pandas/issues/22818))

+   弃用了设置 `Categorical._codes`,请使用所需代码创建新的 `Categorical` ([GH 40606](https://github.com/pandas-dev/pandas/issues/40606))

+   弃用了 `read_excel()` 和 `ExcelFile.parse()` 中的 `convert_float` 可选参数 ([GH 41127](https://github.com/pandas-dev/pandas/issues/41127))

+   `DatetimeIndex.union()` 的混合时区行为已经被弃用;在将来的版本中,两者将被转换为 UTC 而不是对象类型 ([GH 39328](https://github.com/pandas-dev/pandas/issues/39328))

+   弃用了使用 `engine="c"` 的 `read_csv()` 中超出范围索引的 `usecols` ([GH 25623](https://github.com/pandas-dev/pandas/issues/25623))

+   在 `DataFrame` 构造函数中,特殊对待首个元素为分类的列表的已弃用行为;改为传递 `pd.DataFrame({col: categorical, ...})` 代替 ([GH 38845](https://github.com/pandas-dev/pandas/issues/38845))

+   当传递了 `dtype` 并且数据无法转换为该 dtype 时,`DataFrame` 构造函数的已弃用行为。在将来的版本中,这将引发而不是被静默忽略 ([GH 24435](https://github.com/pandas-dev/pandas/issues/24435))

+   已弃用 `Timestamp.freq` 属性。对于使用它的属性(`is_month_start`、`is_month_end`、`is_quarter_start`、`is_quarter_end`、`is_year_start`、`is_year_end`),当你有一个 `freq` 时,使用例如 `freq.is_month_start(ts)` ([GH 15146](https://github.com/pandas-dev/pandas/issues/15146))

+   使用 `DatetimeTZDtype` 数据和 `datetime64[ns]` dtype 构造 `Series` 或 `DataFrame` 的已弃用行为。改用 `Series(data).dt.tz_localize(None)` 代替 ([GH 41555](https://github.com/pandas-dev/pandas/issues/41555), [GH 33401](https://github.com/pandas-dev/pandas/issues/33401))

+   当大整数值与小整数 dtype 静默溢出时,`Series` 构造的已弃用行为;改用 `Series(data).astype(dtype)` 代替 ([GH 41734](https://github.com/pandas-dev/pandas/issues/41734))

+   当浮点数据与整数 dtype 转换时即使有损失,`DataFrame` 构造的已弃用行为;在将来的版本中,这将保持浮点型,与 `Series` 的行为相匹配 ([GH 41770](https://github.com/pandas-dev/pandas/issues/41770))

+   在传递包含字符串数据且没有传递 `dtype` 的情况下,`Series` 构造函数中已弃用对 `timedelta64[ns]`、`datetime64[ns]` 或 `DatetimeTZDtype` dtypes 的推断行为 ([GH 33558](https://github.com/pandas-dev/pandas/issues/33558))

+   在将来的版本中,使用 `datetime64[ns]` 数据和 `DatetimeTZDtype` 构造 `Series` 或 `DataFrame` 时,将把数据视为墙上时间而不是 UTC 时间(与 DatetimeIndex 行为匹配)。要将数据视为 UTC 时间,请使用 `pd.Series(data).dt.tz_localize("UTC").dt.tz_convert(dtype.tz)` 或 `pd.Series(data.view("int64"), dtype=dtype)` ([GH 33401](https://github.com/pandas-dev/pandas/issues/33401))

+   废弃将列表作为 `key` 传递给 `DataFrame.xs()` 和 `Series.xs()` ([GH 41760](https://github.com/pandas-dev/pandas/issues/41760))

+   废弃布尔类型参数 `inclusive` 在 `Series.between()` 中,标准参数值为 `{"left", "right", "neither", "both"}`([GH 40628](https://github.com/pandas-dev/pandas/issues/40628))

+   废弃将参数作为位置参数传递给以下所有函数,但有特殊情况已注明([GH 41485](https://github.com/pandas-dev/pandas/issues/41485))

    +   `concat()` (除了 `objs`)

    +   `read_csv()` (除了 `filepath_or_buffer`)

    +   `read_table()` (除了 `filepath_or_buffer`)

    +   `DataFrame.clip()` 和 `Series.clip()` (除了 `upper` 和 `lower`)

    +   `DataFrame.drop_duplicates()` (除了 `subset`), `Series.drop_duplicates()`, `Index.drop_duplicates()` 和 `MultiIndex.drop_duplicates()`

    +   `DataFrame.drop()` (除了 `labels`) 和 `Series.drop()`

    +   `DataFrame.dropna()` 和 `Series.dropna()`

    +   `DataFrame.ffill()`, `Series.ffill()`, `DataFrame.bfill()` 和 `Series.bfill()`

    +   `DataFrame.fillna()` 和 `Series.fillna()` (除了 `value`)

    +   `DataFrame.interpolate()` 和 `Series.interpolate()` (除了 `method`)

    +   `DataFrame.mask()` 和 `Series.mask()` (除了 `cond` 和 `other`)

    +   `DataFrame.reset_index()` (除了 `level`)和 `Series.reset_index()`

    +   `DataFrame.set_axis()` 和 `Series.set_axis()` (除了 `labels`)

    +   `DataFrame.set_index()` (除了 `keys`)

    +   `DataFrame.sort_index()` 和 `Series.sort_index()`

    +   `DataFrame.sort_values()` (除了 `by`)和 `Series.sort_values()`

    +   `DataFrame.where()` 和 `Series.where()` (除了 `cond` 和 `other`)

    +   `Index.set_names()` 和 `MultiIndex.set_names()` (除了 `names`)

    +   `MultiIndex.codes()` (除了 `codes`)

    +   `MultiIndex.set_levels()` (除了 `levels`)

    +   `Resampler.interpolate()` (除了 `method`)### 在 DataFrame 缩减和 DataFrameGroupBy 操作中弃用删除无关紧要的列

在对带有`numeric_only=None`(默认值)的`DataFrame`进行缩减(例如`.min`、`.max`、`.sum`)时,如果缩减引发`TypeError`的列会被静默忽略并从结果中删除。

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

例如:

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

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

旧行为

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

未来行为

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

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

类似地,在对DataFrameGroupBy应用函数时,函数引发TypeError的列目前会被静默忽略并从结果中删除。

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

例如:

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

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

旧行为

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

未来行为

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

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

其他弃用

  • 弃用允许标量传递给Categorical构造函数(GH 38433)

  • 弃用在构造CategoricalIndex时不传递类似列表的数据(GH 38944)

  • 弃用在Index构造函数中允许特定子类关键字参数,直接使用特定子类代替(GH 14093GH 21311GH 22315GH 26974)

  • 弃用了将 datetimelike(timedelta64[ns]datetime64[ns]Datetime64TZDtypePeriodDtype)转换为整数数据类型的astype()方法,改用values.view(...)代替(GH 38544)。此弃用在 pandas 1.4.0 中被撤销。

  • 弃用MultiIndex.is_lexsorted()MultiIndex.lexsort_depth(),改用MultiIndex.is_monotonic_increasing()代替(GH 32259)

  • Series.where()Series.mask()DataFrame.where()DataFrame.mask()中弃用关键字try_cast;如果需要,手动转换结果(GH 38836)

  • 弃用对Timestamp对象与datetime.date对象的比较。例如,不要使用ts <= mydate,而要使用ts <= pd.Timestamp(mydate)ts.date() <= mydateGH 36131)

  • 弃用Rolling.win_type返回"freq"GH 38963)

  • 弃用Rolling.is_datetimelikeGH 38963)

  • 弃用DataFrame索引器,改用Series.__setitem__()DataFrame.__setitem__()GH 39004)

  • 弃用ExponentialMovingWindow.vol()GH 39220)

  • 使用.astypedatetime64[ns]类型和DatetimeTZDtype之间转换已被弃用,并将在将来的版本中引发,改用obj.tz_localizeobj.dt.tz_localize代替(GH 38622)

  • 弃用将datetime.date对象转换为datetime64时作为fill_valueDataFrame.unstack()DataFrame.shift()Series.shift()DataFrame.reindex()中的强制转换,应传递pd.Timestamp(dateobj)代替(GH 39767)

  • 弃用Styler.set_na_rep()Styler.set_precision(),建议改用Styler.format(),其中na_repprecision分别作为现有和新的输入参数(GH 40134, GH 40425)

  • 弃用Styler.where(),建议改用Styler.applymap()的另一种形式(GH 40821)

  • 弃用在Series.transform()DataFrame.transform()中允许部分失败的功能,当func类似于列表或字典且引发除TypeError之外的任何异常时;func引发除TypeError之外的异常将在将来的版本中引发(GH 40211)

  • read_csv()read_table() 中弃用了 error_bad_lineswarn_bad_lines 参数,而采用 on_bad_lines 参数 (GH 15122)

  • DataFrame 构造函数中弃用了对 np.ma.mrecords.MaskedRecords 的支持,请改用 {name: data[name] for name in data.dtype.names} (GH 40363)

  • 弃用了在不同级别上使用 merge()DataFrame.merge()DataFrame.join() 的行为 (GH 34862)

  • ExcelWriter 中弃用了对 **kwargs 的使用;请使用关键字参数 engine_kwargs 代替 (GH 40430)

  • DataFrameSeries 聚合中弃用了 level 关键字参数;请使用 groupby 代替 (GH 39983)

  • 弃用了 Categorical.remove_categories()Categorical.add_categories()Categorical.reorder_categories()Categorical.rename_categories()Categorical.set_categories() 中的 inplace 参数,并将在将来的版本中移除 (GH 37643)

  • merge() 中弃用了通过 suffixes 关键字产生重复列的行为,以及已经存在的列 (GH 22818)

  • 弃用了设置 Categorical._codes 的行为,请创建一个新的 Categorical 并使用所需的代码 (GH 40606)

  • read_excel()ExcelFile.parse() 中弃用了 convert_float 可选参数 (GH 41127)

  • 弃用了 DatetimeIndex.union() 在混合时区的行为;在将来的版本中,两者都将被转换为 UTC 而不是对象 dtype (GH 39328)

  • 对于使用 engine="c"read_csv(),废弃了使用超出界限的索引进行 usecols 的用法 (GH 25623)

  • DataFrame 构造函数中,废弃了对第一个元素为分类的列表的特殊处理;改为使用 pd.DataFrame({col: categorical, ...}) 代替 (GH 38845)

  • 当传递 dtype 并且数据无法转换为该 dtype 时,DataFrame 构造函数的行为废弃。在将来版本中,这将引发异常而不是被静默忽略 (GH 24435)

  • 废弃了 Timestamp.freq 属性。对于使用它的属性(is_month_startis_month_endis_quarter_startis_quarter_endis_year_startis_year_end),当你有一个 freq 时,使用例如 freq.is_month_start(ts) (GH 15146)

  • 废弃了使用 DatetimeTZDtype 数据和 datetime64[ns] dtype 构造 SeriesDataFrame 的行为。使用 Series(data).dt.tz_localize(None) 代替 (GH 41555, GH 33401)

  • 对于大整数值和小整数 dtype 导致静默溢出的 Series 构造行为废弃;改用 Series(data).astype(dtype) 代替 (GH 41734)

  • 当浮点数据和整数 dtype 被强制转换时,即使有损失,DataFrame 构造行为废弃;在将来版本中,这将保持浮点,与 Series 的行为相匹配 (GH 41770)

  • 当传递包含字符串的数据并且没有传递 dtype 时,在 Series 构造中不再推断 timedelta64[ns]datetime64[ns]DatetimeTZDtype dtypes (GH 33558) 废弃。

  • 在将来的版本中,使用datetime64[ns]数据和DatetimeTZDtype构造SeriesDataFrame将会将数据视为壁钟时间而不是 UTC 时间(匹配 DatetimeIndex 行为)。若要将数据视为 UTC 时间,请使用pd.Series(data).dt.tz_localize("UTC").dt.tz_convert(dtype.tz)pd.Series(data.view("int64"), dtype=dtype)GH 33401

  • 弃用了将列表作为key传递给DataFrame.xs()Series.xs()的布尔参数(GH 41760

  • 弃用了在Series.between()中使用布尔参数inclusive来作为标准参数值的{"left", "right", "neither", "both"}GH 40628

  • 对于以下所有情况,弃用了作为位置参数传递的参数,除了特殊说明的情况(GH 41485):

    • concat()(除了objs

    • read_csv()(除了filepath_or_buffer

    • read_table()(除了filepath_or_buffer

    • DataFrame.clip()Series.clip()(除了upperlower

    • DataFrame.drop_duplicates()(除了subset参数),Series.drop_duplicates()Index.drop_duplicates()MultiIndex.drop_duplicates()

    • DataFrame.drop()(除了labels)和 Series.drop()

    • DataFrame.dropna()Series.dropna()

    • DataFrame.ffill()Series.ffill()DataFrame.bfill()Series.bfill()

    • DataFrame.fillna()Series.fillna()(除了 value

    • DataFrame.interpolate()Series.interpolate()(除了 method

    • DataFrame.mask()Series.mask()(除了 condother

    • DataFrame.reset_index()(除了 level)和 Series.reset_index()

    • DataFrame.set_axis()Series.set_axis()(除了 labels

    • DataFrame.set_index()(除了 keys

    • DataFrame.sort_index()Series.sort_index()

    • DataFrame.sort_values()(除了 by)和 Series.sort_values()

    • DataFrame.where()Series.where()(除了 condother

    • Index.set_names()MultiIndex.set_names()(除了 names

    • MultiIndex.codes()(除了 codes

    • MultiIndex.set_levels()(除了 levels

    • Resampler.interpolate()(除了 method

性能改进

  • 对于 IntervalIndex.isin(),性能有所提高(GH 38353

  • 对于可空数据类型,Series.mean() 的性能有所提高(GH 34814

  • 对于可空数据类型,Series.isin() 的性能有所提高(GH 38340

  • 对于可空浮点数和可空整数数据类型,DataFrame.fillna() 在使用 method="pad"method="backfill" 时性能有所提高(GH 39953

  • 对于 method=kendallDataFrame.corr() 的性能有所提高(GH 28329

  • 对于 method=spearmanDataFrame.corr() 的性能有所提高(GH 40956, GH 41885

  • Rolling.corr()Rolling.cov() 的性能有所提高(GH 39388

  • 对于 RollingGroupby.corr()ExpandingGroupby.corr()ExpandingGroupby.corr()ExpandingGroupby.cov(),性能有所提高(GH 39591

  • 对于对象数据类型,unique() 的性能有所提高(GH 37615

  • 对于基本情况(包括分隔符),json_normalize() 的性能有所提高(GH 40035, GH 15621

  • 对于 ExpandingGroupby 聚合方法,性能有所提高(GH 39664

  • Styler中的性能改进,渲染时间减少超过 50%,现在与DataFrame.to_html()相匹配(GH 39972 GH 39952, GH 40425

  • 方法Styler.set_td_classes()现在与Styler.apply()Styler.applymap()一样高效,有些情况下甚至更高效(GH 40453

  • ExponentialMovingWindow.mean()中的性能改进,使用timesGH 39784

  • 在需要 Python 回退实现时的DataFrameGroupBy.apply()SeriesGroupBy.apply()中的性能改进(GH 40176)

  • 将 PyArrow 布尔数组转换为 pandas 可空布尔数组的性能改进(GH 41051

  • 用于连接具有类型CategoricalDtype数据的性能改进(GH 40193

  • 使用可空数据类型时,DataFrameGroupBy.cummin()SeriesGroupBy.cummin()DataFrameGroupBy.cummax()SeriesGroupBy.cummax()的性能提升(GH 37493

  • 使用 nan 值时,Series.nunique()的性能提升(GH 40865

  • 使用DatetimeTZDtype时,DataFrame.transpose()Series.unstack()的性能提升(GH 40149

  • 在延迟加载入口点时,Series.plot()DataFrame.plot()的性能提升(GH 41492

Bug 修复

分类

  • 当传递标量数据时,CategoricalIndex错误地未引发TypeErrorGH 38614

  • 当传递给CategoricalIndex.reindexIndex不是分类的,但其所有值都是类别中的标签时,出现的错误(GH 28690

  • 从对象数据类型数组构造Categorical时出现的错误,无法通过astype正确地往返转换为date对象(GH 38552

  • ndarrayCategoricalDtype构造DataFrame时出现的错误(GH 38857

  • 在将分类值设置到DataFrame中的对象数据类型列中存在错误(GH 39136)

  • DataFrame.reindex()中存在的错误,在新索引包含重复项且旧索引是CategoricalIndex时引发IndexErrorGH 38906)

  • 在使用类似元组的类别填充Categorical.fillna()时,当使用非类别元组进行填充时引发NotImplementedError而不是ValueErrorGH 41914)

日期时间类

  • DataFrameSeries构造函数有时会从Timestamp(或Timedeltadata中删除纳秒,其dtype=datetime64[ns](或timedelta64[ns])(GH 38032)

  • 在具有一个月偏移量的DataFrame.first()Series.first()中存在错误,当第一天是月底时返回不正确的结果(GH 29623)

  • 在构建具有不匹配的datetime64数据和timedelta64数据类型或反之的DataFrameSeries时存在错误,未能引发TypeErrorGH 38575, GH 38764, GH 38792)

  • 在使用超出datetime64[ns]数据类型范围的datetime对象或超出timedelta64[ns]数据类型范围的timedelta对象构建SeriesDataFrame时存在错误(GH 38792, GH 38965)

  • DatetimeIndex.intersection()DatetimeIndex.symmetric_difference()PeriodIndex.intersection()PeriodIndex.symmetric_difference()中存在错误,当与CategoricalIndex操作时,始终返回对象 dtype(GH 38741

  • DatetimeIndex.intersection()中存在错误,使用非 Tick 频率和n != 1时会给出不正确的结果(GH 42104

  • Series.where()中存在错误,将datetime64值错误地转换为int64GH 37682

  • Categorical中存在错误,将datetime对象错误地类型转换为TimestampGH 38878

  • 与纳秒datetime64实现边界外的Timestamp对象和datetime64对象之间比较存在错误(GH 39221

  • Timestamp.round()Timestamp.floor()Timestamp.ceil()中存在错误,对接近Timestamp实现边界的值(GH 39244

  • Timedelta.round()Timedelta.floor()Timedelta.ceil()中存在错误,对接近Timedelta实现边界的值(GH 38964

  • date_range()中存在错误,不正确地创建包含NaTDatetimeIndex,而不是在极端情况下引发OutOfBoundsDatetimeGH 24124

  • infer_freq() 错误地未能推断具有时区且跨越夏令时边界的 DatetimeIndex 的 ‘H’ 频率(GH 39556

  • DatetimeArrayTimedeltaArray 支持的 Series 有时未能将数组的 freq 设置为 NoneGH 41425

时间增量

  • np.timedelta64 对象构建 Timedelta 时,具有超出 timedelta64[ns] 范围的非纳秒单位的对象未能引发错误(GH 38965

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

  • 从仅包含符号而不含数字的输入字符串构建 Timedelta 失败未引发错误(GH 39710

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

时区

  • 不同的 tzinfo 对象表示的 UTC 不被视为等价(GH 39216

  • dateutil.tz.gettz("UTC") 未被识别为其他表示 UTC 的 tzinfo 的等效项(GH 39276

数值

  • DataFrame.quantile()DataFrame.sort_values() 中的错误导致了不正确的后续索引行为(GH 38351

  • DataFrame.sort_values() 中的错误,对于空的 by 引发了 IndexErrorGH 40258

  • include=np.number 时,DataFrame.select_dtypes() 中的 Bug 会删除数值型 ExtensionDtype 列 (GH 35340)

  • DataFrame.mode()Series.mode() 中的 Bug 在空输入时不保持一致的整数 Index (GH 33321)

  • 当 DataFrame 包含 np.inf 时,DataFrame.rank()中的 Bug (GH 32593)

  • 当列持有不可比较类型且 axis=0 时,DataFrame.rank()中的 Bug 会引发 IndexError (GH 38932)

  • Series.rank()DataFrame.rank()DataFrameGroupBy.rank()SeriesGroupBy.rank() 中的 Bug 将最负的 int64 值视为缺失值 (GH 32859)

  • DataFrame.select_dtypes() 在 Windows 和 Linux 中 include="int" 时表现不同的 Bug (GH 36596)

  • 当传递参数 func="size" 时,DataFrame.apply()DataFrame.agg() 中的 Bug 会对整个 DataFrame 进行操作,而不是行或列 (GH 39934)

  • DataFrame.transform()中的 Bug,在传递字典且缺少列时会引发 SpecificationError,现在会引发 KeyError (GH 40004)

  • DataFrameGroupBy.rank()SeriesGroupBy.rank()pct=True 且连续分组之间存在相等值时给出不正确的结果的 Bug (GH 40518)

  • Series.count() 的 Bug,在 32 位平台上当参数 level=None 时将导致 int32 结果 (GH 40908)

  • SeriesDataFrame 使用 anyall 方法进行归约时,未针对对象数据返回布尔结果的 Bug (GH 12863, GH 35450, GH 27709)

  • Series.clip() 存在 Bug,如果 Series 包含 NA 值并且具有可空 int 或 float 类型的数据类型,则会失败 (GH 40851)

  • UInt64Index.where()UInt64Index.putmask() 中的 Bug,如果 othernp.int64 类型,则错误地引发 TypeError (GH 41974)

  • DataFrame.agg() 中的 Bug,在提供的聚合函数的顺序中未对聚合的轴进行排序,当一个或多个聚合函数未能产生结果时 (GH 33634)

  • DataFrame.clip() 存在 Bug,未将缺失值解释为无阈值 (GH 40420)

转换

  • Series.to_dict()orient='records' 模式下的 Bug,现在返回 Python 本机类型 (GH 25969)

  • Series.view()Index.view() 在转换为日期时间类型(datetime64[ns]datetime64[ns, tz]timedelta64period)时的 Bug (GH 39788)

  • 从空的np.recarray创建DataFrame时,未保留原始的数据类型(GH 40121

  • frozenset构建DataFrame时,未能引发TypeErrorGH 40163

  • 构建Index时忽略传递的dtype,当数据无法转换为该 dtype 时会默默地忽略(GH 21311

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

  • 在调用factorize()时出现的 bug,当给定一个数值型 NumPy dtype 低于 int64、uint64 和 float64 的数组时,唯一值不保持其原始 dtype(GH 41132

  • 使用包含ExtensionDtypecopy=True的字典构建DataFrame时出现 bug,无法复制数组类对象(GH 38939

  • 在将Float64DType作为输入时,qcut()引发错误(GH 40730

  • 使用datetime64[ns]数据和dtype=object构建DataFrameSeries时,结果是datetime对象而不是Timestamp对象(GH 41599

  • 使用timedelta64[ns]数据和dtype=object构建DataFrameSeries时,结果是np.timedelta64对象而不是Timedelta对象(GH 41599

  • 当给定二维对象数据类型为np.ndarrayPeriodInterval对象时,DataFrame构造存在错误,无法转换为PeriodDtypeIntervalDtype,分别(GH 41812

  • 从列表和PandasDtype构造Series时存在错误(GH 39357

  • 从不适合于int64数据类型边界的range对象创建Series时存在错误(GH 30173

  • 从具有全部元组键和需要重新索引的Indexdict创建Series时存在错误(GH 41707

  • infer_dtype()存在错误,无法识别 Series、Index 或具有 Period 数据类型的数组(GH 23553

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

  • 在对空 DataFrame 调用DataFrame.convert_dtypes()时,存在错误,错误地引发了ValueErrorGH 40393

字符串

  • pyarrow.ChunkedArray转换为StringArray时存在错误,原始数据没有分块(GH 41040

  • 当使用StringDType数据时,Series.replace()DataFrame.replace()忽略了regex=True的替换项(GH 41333GH 35977

  • 当使用StringArray时,Series.str.extract()存在一个错误,返回一个空DataFrame的对象 dtype(GH 41441

  • 内联代码中Series.str.replace()存在一个错误,当regex=False时,case参数被忽略了(GH 41602

区间

  • 当与CategoricalIndex一起操作时,IntervalIndex.intersection()IntervalIndex.symmetric_difference()始终返回对象 dtype(GH 38653GH 38741

  • 当至少一个Index对象中存在其他对象中存在的重复项时,IntervalIndex.intersection()返回重复项(GH 38743

  • 当与其他不兼容 dtype 的IntervalIndex一起操作时,IntervalIndex.union()IntervalIndex.intersection()IntervalIndex.difference()IntervalIndex.symmetric_difference()现在会转换为适当的 dtype 而不是引发TypeErrorGH 39267

  • 当与其他不兼容 dtype 的PeriodIndex一起操作时,PeriodIndex.union()PeriodIndex.intersection()PeriodIndex.symmetric_difference()PeriodIndex.difference()现在会转换为对象 dtype 而不是引发IncompatibleFrequencyGH 39306

  • 当存在 NA 值时,IntervalIndex.is_monotonic()IntervalIndex.get_loc()IntervalIndex.get_indexer_for()IntervalIndex.__contains__()存在一个错误(GH 41831

索引

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

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

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

  • Series.loc() 中的错误,在使用布尔列表进行筛选并且要设置的值为较低维度的列表时,引发ValueErrorGH 20438)

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

  • DataFrame.__setitem__() 中的错误,在将多个值设置为重复列时引发ValueErrorGH 15695)

  • DataFrame.loc()Series.loc()DataFrame.__getitem__()Series.__getitem__() 中的错误,对于非单调的 DatetimeIndex 的字符串切片,返回不正确的元素 (GH 33146)

  • DataFrame.reindex()Series.reindex() 在具有时区感知索引时,对于method="ffill"method="bfill"以及指定的tolerance引发TypeErrorGH 38566)

  • DataFrame.reindex() 中的错误,当fill_value需要转换为对象 dtype 时,datetime64[ns]timedelta64[ns]不正确地转换为整数时 (GH 39755)

  • 当使用指定列和非空 DataFrame 值在空 DataFrame 上设置时,DataFrame.__setitem__() 存在错误,会引发 ValueErrorGH 38831

  • 当在具有重复列的 DataFrame 上操作唯一列时,DataFrame.loc.__setitem__() 存在错误,会引发 ValueErrorGH 38521

  • 当设置为字典值时,混合类型存在错误,DataFrame.iloc.__setitem__()DataFrame.loc.__setitem__() 存在错误(GH 38335

  • 当提供布尔生成器时,Series.loc.__setitem__()DataFrame.loc.__setitem__() 存在错误,会引发 KeyErrorGH 39614

  • 当提供生成器时,Series.iloc()DataFrame.iloc() 存在错误,会引发 KeyErrorGH 39614

  • 当右侧是列数不匹配的 DataFrame 时,DataFrame.__setitem__() 不会引发 ValueErrorGH 38604

  • 当使用标量索引器设置 Series 时,Series.__setitem__() 存在错误,会引发 ValueErrorGH 38303

  • 当输入的 DataFrame 只有一行时,DataFrame.loc() 中存在错误,会降低 MultiIndex 的级别(GH 10521

  • 当切片存在现有字符串时,DataFrame.__getitem__()Series.__getitem__() 总是会引发 KeyError,其中 Index 具有毫秒数(GH 33589

  • 当将 timedelta64datetime64 值设置为数值 Series 失败时,存在错误,无法转换为对象 dtype(GH 39086, GH 39619

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

  • datetime64 值设置到具有整数 dtype 的 Series 中时出现 Bug,错误地将 datetime64 值转换为整数 (GH 39266)

  • 当将 np.datetime64("NaT") 设置到具有 Datetime64TZDtypeSeries 中时出现 Bug,错误地将时区无关值视为时区感知值 (GH 39769)

  • Index.get_loc() 中的 Bug 在指定 key=NaN 且指定了 methodNaN 不在 Index 中时未引发 KeyError (GH 39382)

  • 在将 np.datetime64("NaT") 插入到时区感知索引时,DatetimeIndex.insert() 出现 Bug,错误地将时区无关值视为时区感知值 (GH 39769)

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

  • RangeIndex.append() 中的 Bug 在将长度为 1 的单个对象错误地拼接在一起时出现错误 (GH 39401)

  • RangeIndex.astype() 中的 Bug 在转换为 CategoricalIndex 时,类别变成了 Int64Index 而不是 RangeIndex (GH 41263)

  • 在使用布尔索引器时,将 numpy.timedelta64 值设置到对象 dtype 的 Series 中出现 Bug (GH 39488)

  • 使用 atiat 将数值设置为布尔类型 Series 时失败将其转换为对象类型的 Bug(GH 39582)

  • 当尝试用列表设置行片段的值时,DataFrame.__setitem__()DataFrame.iloc.__setitem__() 引发 ValueError 的 Bug(GH 40440)

  • DataFrame.loc() 中,当在 MultiIndex 中未找到键且级别未完全指定时未引发 KeyError 的 Bug(GH 41170)

  • 当在扩展轴的索引中存在重复时,设置扩展时 DataFrame.loc.__setitem__() 错误地引发异常的 Bug(GH 40096)

  • 当至少一个索引列具有浮点数类型并且我们检索标量时,带有 MultiIndexDataFrame.loc.__getitem__() 错误地转换为浮点数的 Bug(GH 41369)

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

  • 在带有 CategoricalIndexSeriesDataFrame 上使用 np.nan 进行索引时错误地引发 KeyError 的 Bug(GH 41933)

  • 带有 ExtensionDtypeSeries.__delitem__() 错误地转换为 ndarray 的 Bug(GH 40386)

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

  • DataFrame.loc() 中如果索引器存在重复,返回的 MultiIndex 顺序错误的 Bug(GH 40978)

  • 在使用DatetimeIndex时,DataFrame.__setitem__()引发TypeError,使用str子类作为列名(GH 37366)

  • 在给定不匹配的freqPeriod时,PeriodIndex.get_loc()未能引发KeyError的错误(GH 41670)

  • 使用UInt64Index和负整数键时,Bug .loc.__getitem__有时引发OverflowError而不是KeyError,在其他情况下,转换为正整数(GH 41777)

  • Index.get_indexer()中的错误,在某些情况下,使用无效的methodlimittolerance参数时未能引发ValueErrorGH 41918)

  • 切片SeriesDataFrame时出现错误,当传递无效字符串时引发ValueError而不是TypeErrorGH 41821)

  • Index构造函数中的错误,有时会悄悄地忽略指定的dtypeGH 38879)

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

缺失

  • Grouper中的错误未能正确传播dropna参数;DataFrameGroupBy.transform()现在可以正确处理dropna=True的缺失值(GH 35612)

  • Bug in isna()Series.isna()Index.isna()DataFrame.isna() 和相应的 notna 函数无法识别 Decimal("NaN") 对象(GH 39409

  • Bug in DataFrame.fillna() 不接受字典作为 downcast 关键字参数(GH 40809

  • Bug in isna() 没有为可空类型返回掩码的副本,导致任何后续的掩码修改都会改变原始数组(GH 40935

  • Bug in DataFrame 使用包含 NaN 和整数 dtype 的浮点数据构造时,会进行强制转换而不是保留 NaNGH 26919

  • Bug in Series.isin()MultiIndex.isin() 中的错误,如果它们在元组中,则没有将所有的 NaN 视为等效的(GH 41836

MultiIndex

  • Bug in DataFrame.drop()MultiIndex 是非唯一的且未提供 level 时引发 TypeErrorGH 36293

  • Bug in MultiIndex.intersection() 在结果中重复 NaNGH 38623

  • Bug in MultiIndex.equals()MultiIndex 包含 NaN 时错误地返回 True,即使它们的顺序不同(GH 38439

  • Bug in MultiIndex.intersection()CategoricalIndex 相交时总是返回空结果(GH 38653

  • Bug in MultiIndex.difference() 在索引包含不可排序条目时错误地引发 TypeErrorGH 41915

  • 在空MultiIndex上使用MultiIndex.reindex()时,仅对特定级别进行索引时引发ValueErrorGH 41170)

  • 在重新索引MultiIndex时,当针对一个平坦的Index进行重新索引时引发TypeErrorGH 41707)

I/O

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

  • Bug in read_csv() 在设置参数decimal并且engine="python"时,无法识别科学计数法(GH 31920)

  • Bug in read_csv()NA值解释为注释时,当NA包含注释字符串时,针对engine="python"进行修复(GH 34002)

  • Bug in read_csv() 在指定了多个标题列和index_col的情况下引发IndexError,但文件没有数据行(GH 38292)

  • Bug in read_csv()engine="python"中不接受usecolsnames长度不同的情况(GH 16469)

  • Bug in read_csv()delimiter=","时返回对象 dtype,同时为engine="python"指定了usecolsparse_datesGH 35873)

  • Bug in read_csv() 在为engine="c"指定namesparse_dates时引发TypeErrorGH 33699)

  • Bug in read_clipboard()DataFrame.to_clipboard() 在 WSL 中无法工作(GH 38527)

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

  • Bug in DataFrame.to_hdf()Series.to_hdf() 在尝试应用于 DataFrameSeries 的子类时引发 KeyErrorGH 33748)

  • Bug in HDFStore.put() 在保存具有非字符串 dtype 的 DataFrame 时引发错误的 TypeErrorGH 34274)

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

  • Bug in read_csv() 在应用千位分隔符到日期列时,当应该解析日期且为 engine="python" 指定了 usecols 时出现问题(GH 39365)

  • Bug in read_excel() 在指定多个标题和索引列时,向前填充 MultiIndex 名称(GH 34673)

  • Bug in read_excel() 未遵守 set_option()GH 34252)

  • Bug in read_csv() 未对可空布尔类型的 true_valuesfalse_values 进行切换(GH 34655)

  • Bug in read_json()orient="split" 时,未保持数值字符串索引(GH 28556)

  • read_sql() 如果 chunksize 不为零且查询未返回结果,则返��空生成器。现在返回一个带有单个空 DataFrame 的生成器(GH 34411)

  • Bug in read_hdf() 在使用 where 参数过滤分类字符串列时返回意外记录(GH 39189)

  • read_sas() 中的 Bug 在 datetimes 为 null 时引发 ValueError (GH 39725)

  • read_excel() 中的 Bug 在单列电子表格中丢弃空值时出现问题 (GH 39808)

  • read_excel() 中的 Bug 在某些文件类型加载尾随空行/列时出现问题 (GH 41167)

  • read_excel() 中的 Bug 在 Excel 文件具有 MultiIndex 标头,后跟两个空行且无索引时引发 AttributeError (GH 40442)

  • read_excel()read_csv()read_table()read_fwf()read_clipboard() 中的 Bug,当 MultiIndex 标头后面没有索引的空白行时,会被删除 (GH 40442)

  • DataFrame.to_string() 中的 Bug 在 index=False 时错位了截断列 (GH 40904)

  • DataFrame.to_string() 中的 Bug 在 index=False 时添加了额外的点并使截断行错位 (GH 40904)

  • read_orc() 中的 Bug 总是引发 AttributeError (GH 40918)

  • read_csv()read_table() 中的 Bug 在定义了 namesprefix 后默默地忽略 prefix,现在会引发 ValueError (GH 39123)

  • read_csv()read_excel() 中的 Bug 在 mangle_dupe_cols 设置为 True 时不尊重重复列名的 dtype (GH 35211)

  • 当定义了 delimitersep 时,read_csv() 中的 Bug 会静默地忽略 sep,现在会引发 ValueError (GH 39823)

  • 当之前调用了 sys.setprofile 时,read_csv()read_table() 中的 Bug 会误解参数 (GH 41069)

  • 当 PyArrow 转换为 pandas 时(例如读取 Parquet 文件)出现带有可空 dtype 的 PyArrow 数组,其数据缓冲区大小不是 dtype 大小的倍数时,会出现 Bug (GH 40896)

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

  • 当从 Excel 文件复制时,read_clipboard() 中的 Bug 会将值错位到错误的列中,如果第一列中有空值的话 (GH 41108)

  • 当尝试将字符串列追加到不兼容的列时,DataFrame.to_hdf()Series.to_hdf() 会引发 TypeError 的 Bug (GH 41897)

期间

  • 对于 Period 对象或者不匹配的 PeriodDtypeIndexSeriesDataFrame 的比较现在与其他不匹配类型的比较行为相同,对于相等返回 False,对于不相等返回 True,对于不等式检查引发 TypeError (GH 39274)

绘图

  • 当传递 2D ax 参数时,plotting.scatter_matrix() 中的 Bug 会引发错误 (GH 16253)

  • 当 Matplotlib 的 constrained_layout 被启用时,防止出现警告 (GH 25261)

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

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

  • DataFrame.plot.box()中的 bug,当选择了 dark_background 主题时,图中的顶帽或最小/最大标记不可见 (GH 40769)

Groupby/resample/rolling

  • DataFrameGroupBy.agg()SeriesGroupBy.agg()中的 bug,对于 PeriodDtype 列,结果被错误地过于激进地转换了类型 (GH 38254)

  • SeriesGroupBy.value_counts()中的 bug,未观察到的分类在分组的分类 Series 中未被计入 (GH 38672)

  • SeriesGroupBy.value_counts()中的 bug,如果 Series 为空,则会引发错误 (GH 39172)

  • GroupBy.indices() 中的 bug 会在组键中存在空值时包含不存在的索引 (GH 9304)

  • DataFrameGroupBy.sum()SeriesGroupBy.sum()中修复了一个 bug,导致精度丢失,现在使用 Kahan 求和方法 (GH 38778)

  • 修复了 DataFrameGroupBy.cumsum()SeriesGroupBy.cumsum()DataFrameGroupBy.mean()SeriesGroupBy.mean() 中的 bug,通过使用 Kahan summation 导致精度丢失(GH 38934

  • Resampler.aggregate()DataFrame.transform() 中的一个 bug,在缺少键的情况下混合数据类型时,会引发 TypeError 而不是 SpecificationErrorGH 39025

  • DataFrameGroupBy.idxmin()DataFrameGroupBy.idxmax() 中的一个 bug,涉及 ExtensionDtype 列(GH 38733

  • Series.resample() 中的一个 bug,在索引是由 NaT 组成的 PeriodIndex 时会引发错误(GH 39227

  • RollingGroupby.corr()ExpandingGroupby.corr() 中的一个 bug,当提供比每个组更长的 other 时,groupby 列会返回 0 而不是 np.nanGH 39591

  • ExpandingGroupby.corr()ExpandingGroupby.cov() 中的一个 bug,当提供比每个组更长的 other 时,会返回 1 而不是 np.nanGH 39591

  • DataFrameGroupBy.mean()SeriesGroupBy.mean()DataFrameGroupBy.median()SeriesGroupBy.median()DataFrame.pivot_table() 中的 Bug,未传播元数据(GH 28283)

  • Series.rolling()DataFrame.rolling() 中的 Bug 在窗口是一个偏移量且日期按降序排列时未正确计算窗口边界(GH 40002)

  • Series.groupby()DataFrame.groupby() 在空 SeriesDataFrame 上的 Bug,直接使用 idxmaxidxminmadminmaxsumprodskew 方法,或通过 applyaggregateresample 使用它们时,会丢失索引、列和/或数据类型(GH 26411)

  • DataFrameGroupBy.apply()SeriesGroupBy.apply() 中的 Bug,在 RollingGroupby 对象上使用时,会创建 MultiIndex 而不是 IndexGH 39732)

  • DataFrameGroupBy.sample() 中的 Bug,在指定 weights 并且索引是 Int64Index 时会引发错误(GH 39927)

  • DataFrameGroupBy.aggregate()Resampler.aggregate() 中的 Bug,当传递一个字典并且列缺失时,有时会引发 SpecificationError;现在总是引发 KeyErrorGH 40004

  • DataFrameGroupBy.sample() 中的 Bug,在计算结果之前未应用列选择(GH 39928

  • ExponentialMovingWindow 中的 Bug,调用 __getitem__ 时,当提供 times 时会错误地引发 ValueErrorGH 40164

  • ExponentialMovingWindow 中的 Bug,调用 __getitem__ 时不会保留 comspanalphahalflife 属性(GH 40164

  • ExponentialMovingWindow 现在在指定 adjust=False 时会引发 NotImplementedError,因为计算不正确(GH 40098

  • ExponentialMovingWindowGroupby.mean() 中的 Bug,当 engine='numba' 时会忽略 times 参数(GH 40951

  • ExponentialMovingWindowGroupby.mean() 中的 Bug,当存在多个分组时使用了错误的时间(GH 40951

  • ExponentialMovingWindowGroupby 中的 Bug,非平凡分组时,时间向量和值会不同步(GH 40951

  • Series.asfreq()DataFrame.asfreq() 中的 Bug,在索引未排序时会丢弃行(GH 39805

  • DataFrame 中聚合函数的 Bug,在给定 level 关键字时不尊重 numeric_only 参数(GH 40660

  • 使用用户定义的函数聚合具有对象类型的 Index 的 Series 导致不正确的 Index 形状的 SeriesGroupBy.aggregate() 的错误(GH 40014

  • RollingGroupbygroupby 中的 as_index=False 参数被忽略的错误(GH 39433

  • 当使用具有 NA 的可空类型列并且即使使用 skipna=True 时,DataFrameGroupBy.any()SeriesGroupBy.any()DataFrameGroupBy.all()SeriesGroupBy.all()ValueError 的错误(GH 40585

  • int64 实现边界附近错误地舍入整数值的 DataFrameGroupBy.cummin()SeriesGroupBy.cummin()DataFrameGroupBy.cummax()SeriesGroupBy.cummax() 的错误(GH 40767

  • 使用具有可空类型的数据错误地引发 TypeErrorDataFrameGroupBy.rank()SeriesGroupBy.rank() 的错误(GH 41010

  • Bug in DataFrameGroupBy.cummin(), SeriesGroupBy.cummin(), DataFrameGroupBy.cummax()SeriesGroupBy.cummax() 在将可空数据类型转换为浮点数时计算错误的结果,导致无法回转(GH 37493)

  • Bug in DataFrame.rolling() 在所有NaN窗口的min_periods=0情况下返回平均值为零且不稳定计算时不为零的和(GH 41053)

  • Bug in DataFrame.rolling() 在所有NaN窗口的min_periods=0情况下返回非零和不稳定计算时不为零的和(GH 41053)

  • Bug in SeriesGroupBy.agg() 在保留有序的CategoricalDtype的有序聚合操作中失败(GH 41147)

  • Bug in DataFrameGroupBy.min(), SeriesGroupBy.min(), DataFrameGroupBy.max()SeriesGroupBy.max() 在具有多个对象数据类型列和numeric_only=False时错误地引发ValueErrorGH 41111)

  • DataFrameGroupBy.rank() 中的 Bug 使用 GroupBy 对象的 axis=0rank 方法的关键字 axis=1 时(GH 41320)

  • DataFrameGroupBy.__getitem__() 中的 Bug 在非唯一列上错误地返回了格式不正确的 SeriesGroupBy 而不是 DataFrameGroupByGH 41427)

  • DataFrameGroupBy.transform() 中的 Bug 在非唯一列上错误地引发 AttributeErrorGH 41427)

  • Resampler.apply() 中的 Bug 在非唯一列上错误地删除了重复的列(GH 41445)

  • Series.groupby() 中的 Bug 聚合错误地返回空的 Series ,而不是在其 dtype 无效的聚合上引发 TypeError ,例如使用 datetime64[ns] dtype 的 .prodGH 41342)

  • DataFrameGroupBy 中的 Bug 聚合在没有有效列时错误地未删除该聚合的无效 dtype 的列(GH 41291)

  • DataFrame.rolling.__iter__() 中的 Bug 其中 on 未分配给结果对象的索引(GH 40373)

  • DataFrameGroupBy.transform()DataFrameGroupBy.agg() 中的 Bug,使用 engine="numba" 时,*args 被缓存了用户传递的函数(GH 41647)

  • DataFrameGroupBy 方法 aggtransformsumbfillffillpadpct_changeshiftohlc 删除了 .columns.namesGH 41497)

重塑

  • merge() 中的 Bug 在执行内连接时引发错误,当索引部分重叠且 right_index=True 时,索引之间没有重叠(GH 33814)

  • 具有缺失级别的 DataFrame.unstack() 导致错误的索引名称(GH 37510)。

  • 当使用 left_index=Trueright_on 规范时,merge_asof() 传播正确的索引而不是左索引的错误(GH 33463)。

  • 当 DataFrame 具有MultiIndex,其中至少一个索引只有一个级别时,DataFrame.join() 返回错误结果的错误(GH 36909)。

  • merge_asof() 在非数字合并列的情况下现在会引发 ValueError,而不是晦涩的 TypeErrorGH 29130)。

  • DataFrame.join() 在 DataFrame 具有MultiIndex,至少一个维度具有非按字母顺序排序的 Categorical 类别时,未正确分配值的错误(GH 38502)。

  • Series.value_counts()Series.mode() 现在以原始顺序返回一致的键(GH 12679, GH 11227GH 39007)。

  • DataFrame.stack() 未正确处理 MultiIndex 列中的 NaN 的错误(GH 39481)。

  • 当参数 func 是字符串、axis=1 且轴参数不受支持时,DataFrame.apply() 会产生错误结果;现在会引发 ValueError 错误(GH 39211)。

  • DataFrame.sort_values() 在使用 ignore_index=True 进行列排序后未正确重新塑造索引的错误(GH 39464)。

  • DataFrame.append()中的 Bug 返回了ExtensionDtype类型的组合时的错误 dtypes(GH 39454)

  • DataFrame.append()中的 Bug 当与 datetime64timedelta64 类型的组合一起使用时返回错误的 dtypes(GH 39574)

  • DataFrame.append()中的 Bug 当与带有 MultiIndexSeries 并且其 Index 不是 MultiIndexDataFrame 追加时返回错误 dtypes(GH 41707)

  • DataFrame.pivot_table()中的 Bug 当对空 DataFrame 操作时返回单个值的 MultiIndexGH 13483)

  • Index现在可以传递给 numpy.all() 函数(GH 40180)

  • DataFrame.stack()中的 Bug 未保留CategoricalDtypeMultiIndex中(GH 36991)

  • to_datetime()中的 Bug 当输入序列包含不可散列项时引发错误(GH 39756)

  • Series.explode()中的 Bug 当ignore_indexTrue且值为标量时保留索引(GH 40487)

  • to_datetime()中的 Bug 当 Series 包含 NoneNaT 并且元素超过 50 个时引发 ValueErrorGH 39882)

  • Series.unstack()DataFrame.unstack() 中包含对象 dtype 值的时区感知日期时间对象,错误地引发 TypeErrorGH 41875

  • DataFrame具有用作value_vars的重复列时引发 InvalidIndexErrorDataFrame.melt() 错误(GH 41951

稀疏

  • 修复了使用不带0的数值 Index 列引发 KeyErrorDataFrame.sparse.to_coo() 错误(GH 18414

  • 修复了SparseArray.astype()copy=False的错误,当从整数 dtype 转换为浮点 dtype 时产生不正确的结果(GH 34456

  • 修复了SparseArray.max()SparseArray.min()中的错误,始终返回空结果(GH 40921

扩展数组

  • 修复了当other是具有ExtensionDtype的 Series 时,DataFrame.where() 中的错误(GH 38729

  • 修复了当底层数据是ExtensionArray时,Series.idxmax()Series.idxmin()Series.argmax()Series.argmin() 失败的错误(GH 32749, GH 33719, GH 36566

  • 修复了某些PandasExtensionDtype子类的属性错误缓存的错误(GH 40329

  • 修复了DataFrame.mask()中的错误,当使用ExtensionDtype屏蔽 DataFrame 时引发 ValueErrorGH 40941

样式化器

  • Bug in Styler 方法中的 subset 参数为某些有效的 MultiIndex 切片引发错误 (GH 33562)

  • Styler 渲染的 HTML 输出已经进行了轻微修改以支持 w3 的优良代码标准 (GH 39626)

  • Bug in Styler 渲染的 HTML 中某些标题单元格缺少列类标识符 (GH 39716)

  • Bug in Styler.background_gradient() 中文本颜色未正确确定 (GH 39888)

  • Bug in Styler.set_table_styles() 中 CSS 选择器中 table_styles 参数的多个元素未正确添加 (GH 34061)

  • Bug in Styler 从 Jupyter 复制时丢失了左上角单元格并且标题错位 (GH 12147)

  • Bug in Styler.where 其中 kwargs 未传递到适用的可调用对象 (GH 40845)

  • Bug in Styler 导致在多次渲染时 CSS 重复出现 (GH 39395, GH 40334)

其他

  • inspect.getmembers(Series) 不再引发 AbstractMethodError (GH 38782)

  • Bug in Series.where() 与数值 dtype 以及 other=None 不转换为 nan (GH 39761)

  • 当属性具有未识别的 NA 类型时,assert_series_equal()assert_frame_equal()assert_index_equal()assert_extension_array_equal() 中的 Bug 错误地引发(GH 39461

  • exact=True时,assert_index_equal() 未在比较CategoricalIndex 实例时,与Int64IndexRangeIndex类别一起引发(GH 41263)时的 Bug

  • 当包含np.datetime64("NaT")np.timedelta64("NaT")的对象数据类型为对象时,DataFrame.equals()Series.equals()Index.equals() 中的 Bug (GH 39650

  • 控制台 JSON 输出不是正确的 JSON 时,show_versions() 中的 Bug(GH 39701

  • 当使用xlc时,pandas 现在可以在 z/OS 上编译(GH 35826

  • 当输入对象类型为DataFrame时,pandas.util.hash_pandas_object() 中的 Bug 未能识别hash_keyencodingcategorizeGH 41404

分类的

  • 当传递标量数据时,CategoricalIndex 中的 Bug 错误地未引发TypeErrorGH 38614

  • 当传递的 Index 不是分类的,但其所有值都是该类别中的标签时,CategoricalIndex.reindex 失败(GH 28690

  • 从对象 dtype 数组的 date 对象构造 Categorical 时,使用 astype 进行正确的往返不正确(GH 38552

  • 在从 ndarray 和 CategoricalDtype 构造 DataFrame 时存在错误(GH 38857

  • 将分类值设置到对象 dtype 列中的 DataFrame 中存在错误(GH 39136

  • 当新索引包含重复项并且旧索引是 CategoricalIndex 时,DataFrame.reindex() 会引发 IndexError(GH 38906

  • 在类似元组的分类填充中,Categorical.fillna() 函数引发 NotImplementedError,而不是在使用非类别元组进行填充时引发 ValueErrorGH 41914

Datetimelike

  • 在 DataFrame 和 Series 构造函数中,有时会从 Timestamp(resp. Timedelta)数据中删除纳秒,其中数据类型为 datetime64[ns](resp. timedelta64[ns])(GH 38032

  • DataFrame.first()Series.first() 在月份偏移为一月时存在错误,当月的第一天为月底时返回错误结果(GH 29623

  • 在使用不匹配的 datetime64 数据和 timedelta64 dtype 或反之的情况下构造 DataFrameSeries 时,未能引发 TypeError 的 Bug (GH 38575, GH 38764, GH 38792)

  • 在使用超出 datetime64[ns] dtype 边界的 datetime 对象或超出 timedelta64[ns] dtype 边界的 timedelta 对象构造 SeriesDataFrame 时存在 Bug (GH 38792, GH 38965)

  • 在与 CategoricalIndex 进行操作时,DatetimeIndex.intersection()DatetimeIndex.symmetric_difference()PeriodIndex.intersection()PeriodIndex.symmetric_difference() 总是返回对象 dtype 的 Bug (GH 38741)

  • 在使用非 Tick 频率且 n != 1 的情况下,DatetimeIndex.intersection() 提供了不正确的结果 (GH 42104)

  • Series.where() 中的 Bug 将 datetime64 值错误地转换为 int64 (GH 37682)

  • 在错误地将 datetime 对象转换为 Timestamp 时,Categorical 存在 Bug (GH 38878)

  • Timestamp 对象与微秒级 datetime64 实现边界之外的 datetime64 对象进行比较时存在 Bug (GH 39221)

  • Timestamp.round()Timestamp.floor()Timestamp.ceil() 在接近 Timestamp 实现边界的值时存在 Bug (GH 39244)

  • Bug 在 Timedelta.round()Timedelta.floor()Timedelta.ceil() 中,对于接近 Timedelta 实现边界的值,存在 Bug (GH 38964)

  • Bug 在 date_range() 中,错误地创建了包含 NaTDatetimeIndex,而不是在极端情况下引发 OutOfBoundsDatetime 异常 (GH 24124)

  • Bug 在 infer_freq() 中,如果 DatetimeIndex 具有时区且跨越 DST 边界,则不正确地未能推断出 'H' 频率 (GH 39556)

  • Bug 在由 DatetimeArrayTimedeltaArray 支持的 Series 中,有时未能将数组的 freq 设置为 None (GH 41425)

Timedelta

  • Bug 在构建 Timedelta 时,来自 np.timedelta64 对象的非纳秒单位超出了 timedelta64[ns] 的边界 (GH 38965)

  • Bug 在构建 TimedeltaIndex 时,错误地接受 np.datetime64("NaT") 对象 (GH 39462)

  • Bug 在构建 Timedelta 时,如果输入字符串只包含符号而没有数字,则未能引发错误 (GH 39710)

  • TimedeltaIndexto_timedelta() 中的 Bug,在传递溢出的非纳秒 timedelta64 数组时未能引发异常,这些数组在转换为 timedelta64[ns] 时会溢出(GH 40008)

时区

  • Bug 在不同的 tzinfo 对象表示 UTC 时未被视为等效 (GH 39216)

  • 在 DataFrame 中含有 axis=0 和列持有无法比较的类型时 DataFrame.rank() 报错 IndexError (GH 38932)

数字

  • DataFrame.quantile(), DataFrame.sort_values() 中的 Bug 导致不正确的后续索引行为 (GH 38351)

  • 在空的 byDataFrame.sort_values() 报错 IndexError (GH 40258)

  • include=np.number 的情况下 DataFrame.select_dtypes() 中的 Bug 会删除数值型 ExtensionDtype 列 (GH 35340)

  • DataFrame.mode()Series.mode() 中存在的 Bug 没有保持一致的整数 Index 用于空输入 (GH 33321)

  • dateutil.tz.gettz("UTC") 未被识别为等价于其他表示 UTC 的 tzinfos 的 Bug (GH 39276)

  • 当 DataFrame 包含 np.infDataFrame.rank() 的 Bug (GH 32593)

  • Series.rank(), DataFrame.rank(), DataFrameGroupBy.rank(), 和 SeriesGroupBy.rank() 在将最负的 int64 值视为缺失时的 Bug (GH 32859)

  • DataFrame.select_dtypes() 中的错误,在 Windows 和 Linux 之间使用 include="int" 时表现不同(GH 36596

  • DataFrame.apply()DataFrame.agg() 中的错误,当传递参数 func="size" 时会在整个 DataFrame 上操作而不是行���列(GH 39934

  • DataFrame.transform() 中的错误,当传递字典且列缺失时会引发 SpecificationError,现在会引发 KeyErrorGH 40004

  • DataFrameGroupBy.rank()SeriesGroupBy.rank()pct=True 和连续组之间存在相等值时给出错误结果的错误(GH 40518

  • Series.count() 中的错误,当参数 level=None 时会在 32 位平台上产生 int32 结果(GH 40908

  • SeriesDataFrame 在使用方法 anyall 进行缩减时,对于对象数据不返回布尔结果的错误(GH 12863GH 35450GH 27709

  • Series.clip() 中的错误,如果 Series 包含 NA 值并且具有可空的整数或浮点数作为数据类型,则会失败(GH 40851

  • UInt64Index.where()UInt64Index.putmask() 中的错误,当 np.int64 类型的 other 不正确地引发 TypeError 时(GH 41974

  • DataFrame.agg() 中的错误,在提供的聚合函数无法产生结果时,不按照所提供的聚合函数顺序对聚合的轴进行排序 (GH 33634)

  • DataFrame.clip() 中,将缺失值解释为无阈值 (GH 40420)

转换

  • 使用orient='records'Series.to_dict() 现在返回 Python 本机类型 (GH 25969)

  • 在转换日期时间型 (datetime64[ns], datetime64[ns, tz], timedelta64, period) 数据类型时,Series.view()Index.view() 出现错误 (GH 39788)

  • 从空的 np.recarray 创建 DataFrame 时,未保留原始数据类型 (GH 40121)

  • 在使用frozenset构建时,DataFrame 未能引发TypeError错误 (GH 40163)

  • 在构建Index 时,当数据无法转换为指定的数据类型时,会默默地忽略传递的 dtype (GH 21311)

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

  • 在使用 factorize() 时,给定的数组是具有低于 int64、uint64 和 float64 的数值 NumPy 数据类型时,唯一值未能保持其原始数据类型 (GH 41132)

  • 使用包含ExtensionDtypecopy=True的数组形式的字典构建 DataFrame 时出现错误,未能进行复制 (GH 38939)

  • 在使用 Float64DType 作为输入时,qcut() 报错 (GH 40730)

  • 在使用datetime64[ns]数据和dtype=object构建DataFrameSeries时存在错误,导致生成datetime对象而不是Timestamp对象(GH 41599)

  • 在使用timedelta64[ns]数据和dtype=object构建DataFrameSeries时存在错误,导致生成np.timedelta64对象而不是Timedelta对象(GH 41599)

  • 在给定两维对象 dtype np.ndarrayPeriodInterval对象构建DataFrame时存在错误,无法强制转换为PeriodDtypeIntervalDtypeGH 41812)

  • 从列表和PandasDtype构建Series时存在错误(GH 39357)

  • 从不适合于int64dtype 边界的range对象构建Series时存在错误(GH 30173)

  • 从具有全部元组键和需要重新索引的Indexdict创建Series时存在错误(GH 41707)

  • infer_dtype()中存在错误,无法识别具有周期(dtype)的 Series、Index 或数组(GH 23553)

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

  • DataFrame.convert_dtypes() 中的错误,当对空 DataFrame 进行调用时错误地引发了 ValueErrorGH 40393)

字符串

  • pyarrow.ChunkedArray 转换为 StringArray 时的错误,当原始数据块为零时(GH 41040)

  • Series.replace()DataFrame.replace() 中的漏洞,忽略了对 StringDType 数据使用 regex=True 进行替换(GH 41333GH 35977)

  • Series.str.extract() 中的漏洞,使用 StringArray 返回空 DataFrame 时返回对象 dtype(GH 41441)

  • Series.str.replace() 中的漏洞,在 regex=False 时忽略了 case 参数的情况(GH 41602)

区间

  • 在与 CategoricalIndex 进行操作时,IntervalIndex.intersection()IntervalIndex.symmetric_difference() 总是返回对象 dtype 的漏洞(GH 38653GH 38741)

  • 在至少一个 Index 对象有重复项且存在于另一个对象中时,IntervalIndex.intersection() 返回重复项的漏洞(GH 38743)

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

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

  • 当存在 NA 值时,IntervalIndex.is_monotonic()IntervalIndex.get_loc()IntervalIndex.get_indexer_for()IntervalIndex.__contains__() 中的 Bug (GH 41831)

索引

  • Index.union()MultiIndex.union() 中的 Bug,在 Index 不单调或 sort 设置为 False 时丢弃重复的 Index 值(GH 36289, GH 31326, GH 40862)

  • 在非唯一时未引发 InvalidIndexErrorCategoricalIndex.get_indexer() 中的 Bug (GH 38372)

  • target 具有 CategoricalDtype 且索引和目标均包含 NA 值时,IntervalIndex.get_indexer() 中的 Bug (GH 41934)

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

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

  • 在将多个值设置为重复列时,DataFrame.__setitem__() 引发 ValueError 的 Bug (GH 15695)

  • 对于非单调的 DatetimeIndex 的字符串切片,DataFrame.loc()Series.loc()DataFrame.__getitem__()Series.__getitem__() 返回不正确的元素的 Bug (GH 33146)

  • DataFrame.reindex()Series.reindex()中的错误,在具有时区意识索引的情况下,对method="ffill"method="bfill"以及指定tolerance时引发TypeErrorGH 38566)

  • DataFrame.reindex()中的错误,在datetime64[ns]timedelta64[ns]需要转换为对象数据类型时,错误地转换为整数,导致fill_value错误(GH 39755)

  • DataFrame.__setitem__()中的错误,在使用指定列和非空DataFrame值设置空DataFrame时引发ValueErrorGH 38831)

  • DataFrame.loc.__setitem__()中的错误,在操作唯一列时,当DataFrame具有重复列时引发ValueErrorGH 38521)

  • DataFrame.iloc.__setitem__()DataFrame.loc.__setitem__()中的错误,在使用字典值设置时,混合数据类型引发ValueErrorGH 38335)

  • Series.loc.__setitem__()DataFrame.loc.__setitem__()中的错误,在提供布尔生成器时引发KeyErrorGH 39614)

  • Series.iloc()DataFrame.iloc()中的错误,在提供生成器时引发KeyErrorGH 39614)

  • DataFrame.__setitem__()中的错误,在右侧为列数不正确的DataFrame时未引发ValueErrorGH 38604)

  • Series.__setitem__()中的错误,在使用标量索引器设置Series时引发ValueErrorGH 38303)

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

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

  • 在将timedelta64datetime64值设置为数值Series时出现的错误,无法将其转换为对象 dtype(GH 39086GH 39619)

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

  • datetime64值设置为具有整数 dtype 的Series中的错误,错误地将 datetime64 值转换为整数(GH 39266)

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

  • key=NaN且指定了methodNaN不在Index中时,Index.get_loc()中的错误未引发KeyErrorGH 39382)

  • 在向具有时区意识的索引中插入np.datetime64("NaT")时,在DatetimeIndex.insert()中的错误,错误地将时区无关的值错误地视为时区感知值(GH 39769)

  • Index.insert()中错误地引发异常,当设置一个无法保存在现有frame.columns中的新列时,或在Series.reset_index()DataFrame.reset_index()中而不是转换为兼容的数据类型时(GH 39068)

  • RangeIndex.append()中的错误,其中长度为 1 的单个对象被错误地连接(GH 39401)

  • RangeIndex.astype()中的错误,当转换为CategoricalIndex时,类别变为Int64Index而不是RangeIndexGH 41263)

  • 在将numpy.timedelta64值设置为对象数据类型Series时出现的错误,使用布尔索引器(GH 39488)

  • 在将数值设置为布尔数据类型Series时使用atiat失败将其转换为对象数据类型的错误(GH 39582)

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

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

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

  • DataFrame.loc.__getitem__()中的错误,当至少一个索引列具有浮点数据类型且我们检索标量时,将MultiIndex转换为浮点数(GH 41369)

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

  • 在带有 CategoricalIndexSeriesDataFrame 上使用 np.nan 进行索引时,出现 np.nan 键时错误地引发 KeyErrorGH 41933)

  • Series.__delitem__() 中的一个 bug 在使用 ExtensionDtype 时错误地转换为 ndarrayGH 40386)

  • DataFrame.at() 中的一个 bug 在传递整数键时返回不正确的结果(GH 41846)

  • DataFrame.loc() 中的一个 bug 在索引器存在重复值时返回顺序错误的 MultiIndexGH 40978)

  • DataFrame.__setitem__() 中的一个 bug 导致在使用 str 子类作为列名并且带有 DatetimeIndex 时引发 TypeErrorGH 37366)

  • PeriodIndex.get_loc() 中的一个 bug 在给定不匹配 freqPeriod 时未能引发 KeyErrorGH 41670)

  • 在使用 UInt64Index 和负整数键时,.loc.__getitem__ 中的一个 bug 在一些情况下引发 OverflowError 而不是 KeyError,在其他情况下则将其包装为正整数(GH 41777)

  • Index.get_indexer() 中的一个 bug 在一些情况下无效的 methodlimittolerance 参数时未能引发 ValueErrorGH 41918)

  • 在使用带有 TimedeltaIndexSeriesDataFrame 进行切片时,传递无效字符串时错误地引发 ValueError 而不是 TypeErrorGH 41821)

  • Index构造函数有时会悄悄地忽略指定的dtypeGH 38879

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

缺失

  • Grouper中的错误未正确传播dropna参数;DataFrameGroupBy.transform()现在正确处理dropna=True的缺失值(GH 35612

  • isna()Series.isna()Index.isna()DataFrame.isna()及相应的notna函数不能识别Decimal("NaN")对象(GH 39409

  • DataFrame.fillna()不接受downcast关键字的字典(GH 40809

  • isna()不为可空类型返回掩码的错误,导致任何后续的掩码修改都会更改原始数组(GH 40935

  • 在包含浮点数据且整数dtype强制转换而不保留NaN的情况下,DataFrame构造中的错误(GH 26919

  • Series.isin()MultiIndex.isin()中的错误,如果它们在元组中,则不将所有的 nan 视为等价的(GH 41836

多级索引

  • MultiIndex不唯一且未提供level时,DataFrame.drop()引发TypeError的错误(GH 36293

  • 在结果中重复 NaN 的 Bug,MultiIndex.intersection() (GH 38623)

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

  • 当与 CategoricalIndex 相交时,MultiIndex.intersection() 中的 Bug 始终返回空结果 (GH 38653)

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

  • 在空的 MultiIndex 上使用 MultiIndex.reindex() 时引发 ValueError,并且仅对特定级别进行索引 (GH 41170)

  • 当重新索引到一个平坦的 Index 时,MultiIndex.reindex() 中的 Bug 引发 TypeError (GH 41707)

I/O

  • display.max_seq_items=1 时,Index.__repr__() 中的 Bug (GH 38415)

  • 如果参数 decimal 被设置且 engine="python" 时,read_csv() 中的 Bug 在科学计数法不被识别 (GH 31920)

  • engine="python" 的情况下,read_csv() 中的 Bug 将 NA 值解释为注释 (GH 34002)

  • 当文件没有数据行时,具有多个标题列且指定了 index_col 时,read_csv() 中的 Bug 引发 IndexError (GH 38292)

  • read_csv() 中的 Bug 在 engine="python" 下不接受与 names 不同长度的 usecols (GH 16469)

  • engine="python" 的情况下,当 delimiter="," 且指定了 usecolsparse_dates 时,read_csv() 返回对象 dtype (GH 35873)

  • 修复了 read_csv()engine="c" 模式下指定了 namesparse_dates 时引发 TypeError 的 bug (GH 33699)

  • 修复了在 WSL 中 read_clipboard()DataFrame.to_clipboard() 不工作的 bug (GH 38527)

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

  • 修复了 DataFrame.to_hdf()Series.to_hdf() 在尝试应用于 DataFrameSeries 的子类时引发 KeyError 的 bug (GH 33748)

  • 修复了 HDFStore.put() 在保存具有非字符串 dtype 的 DataFrame 时引发错误的 TypeError 的 bug (GH 34274)

  • 修复了 json_normalize() 导致生成器对象的第一个元素不包含在返回的 DataFrame 中的 bug (GH 35923)

  • 修复了 read_csv()engine="python" 模式下对日期列应用千位分隔符时,应该解析日期列而 usecols 已指定的 bug (GH 39365)

  • 修复了 read_excel() 在指定了多个标题和索引列时,前向填充 MultiIndex 名称的 bug (GH 34673)

  • 修复了 read_excel() 不尊重 set_option() 的 bug (GH 34252)

  • 对于可空布尔数据类型,read_csv()不会切换true_valuesfalse_values (GH 34655)

  • orient="split"时,read_json()不会保持数字字符串索引 (GH 28556)

  • 如果chunksize不为零且查询结果为空,则read_sql()会返回一个空生成器。现在返回一个包含单个空 DataFrame 的生成器 (GH 34411)

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

  • datetimes为空时,read_sas()会引发ValueError (GH 39725)

  • 在从单列电子表格中读取时,read_excel()会删除空值 (GH 39808)

  • 对于某些文件类型,read_excel()会加载尾随的空行/列 (GH 41167)

  • 当 Excel 文件具有MultiIndex标题后跟两个空行且没有索引时,read_excel()会引发AttributeError (GH 40442)

  • read_excel()read_csv()read_table()read_fwf()read_clipboard()中存在的一个问题是,当MultiIndex标题后面没有索引且有一个空白行时,该空白行将被删除 (GH 40442)

  • index=False时,DataFrame.to_string()会错误地放置截断列 (GH 40904)

  • Bug in DataFrame.to_string()index=False时,添加额外的点并使截断行错位(GH 40904)

  • Bug in read_orc() 总是引发AttributeError错误(GH 40918)

  • Bug in read_csv()read_table() 如果定义了namesprefix,则会静默忽略prefix,现在会引发ValueError错误(GH 39123)

  • Bug in read_csv()read_excel()mangle_dupe_cols设置为True时,不尊重重复列名的 dtype(GH 35211)

  • Bug in read_csv() 如果定义了delimitersep,则会静默忽略sep,现在会引发ValueError错误(GH 39823)

  • Bug in read_csv()read_table() 在之前调用sys.setprofile时误解参数(GH 41069)

  • 从 PyArrow 转换为 pandas 时出现错误(例如用于读取 Parquet 文件),其中包含可空数据类型和 PyArrow 数组,其数据缓冲区大小不是 dtype 大小的倍数(GH 40896)

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

  • Bug in read_clipboard() 从 Excel 文件复制时,如果第一列有空值,则将值移到错误的列中(GH 41108)

  • Bug in DataFrame.to_hdf()Series.to_hdf() 尝试将字符串列追加到不兼容的列时引发TypeError错误(GH 41897)

Period

  • Period 对象或 IndexSeriesDataFrame 的比较现在与其他不匹配的 PeriodDtype 类型的比较行为一致,对于相等返回 False,对于不相等返回 True,对于不等式检查引发 TypeErrorGH 39274

绘图

  • 修复了当传递了 2D ax 参数时,plotting.scatter_matrix() 中的错误(GH 16253

  • 当启用 Matplotlib 的 constrained_layout 时,防止出现警告(GH 25261

  • 修复了 DataFrame.plot() 中的错误,在重复调用该函数并且某些调用使用了 yerr 而其他调用没有时,在图例中显示了错误的颜色(GH 39522

  • 修复了 DataFrame.plot() 中的错误,在重复调用该函数并且某些调用使用了 secondary_y 而其他调用使用了 legend=False 时,在图例中显示了错误的颜色(GH 40044

  • 修复了当选择 dark_background 主题时,DataFrame.plot.box() 中的错误,图中的上下界或最小/最大标记不可见(GH 40769

分组/重采样/滚动

  • 修复了 DataFrameGroupBy.agg()SeriesGroupBy.agg() 中的错误,对于 PeriodDtype 列错误地过于激进地进行了结果转换(GH 38254

  • 修复了 SeriesGroupBy.value_counts() 中的错误,对于分组的分类序列中未观察到的类别没有计数(GH 38672

  • 在空 Series 上引发错误的SeriesGroupBy.value_counts()中存在一个错误(GH 39172

  • 在存在空值的分组键中,GroupBy.indices()中将包含不存在的索引(GH 9304

  • 通过现在使用 Kahan 求和解决了DataFrameGroupBy.sum()SeriesGroupBy.sum()中存在的精度损失的错误(GH 38778

  • 通过使用 Kahan 求和解决了DataFrameGroupBy.cumsum()SeriesGroupBy.cumsum()DataFrameGroupBy.mean()SeriesGroupBy.mean()中存在的精度损失的错误(GH 38934

  • Resampler.aggregate()DataFrame.transform()中存在一个错误,当缺少键的混合数据类型时,抛出TypeError而不是SpecificationErrorGH 39025

  • 在具有ExtensionDtype列的DataFrameGroupBy.idxmin()DataFrameGroupBy.idxmax()中存在一个错误(GH 38733

  • Series.resample()中的错误会在索引是由NaT组成的PeriodIndex时引发错误(GH 39227

  • RollingGroupby.corr()ExpandingGroupby.corr()中的错误,当提供比每个组更长的other时,组别列会返回0而不是np.nanGH 39591

  • ExpandingGroupby.corr()ExpandingGroupby.cov()中的错误,当提供比每个组更长的other时,会返回1而不是np.nanGH 39591

  • DataFrameGroupBy.mean()SeriesGroupBy.mean()DataFrameGroupBy.median()SeriesGroupBy.median()DataFrame.pivot_table()中的错误,未传播元数据(GH 28283

  • Series.rolling()DataFrame.rolling()中的错误,当窗口是一个偏移量且日期是降序时,未正确计算窗口边界(GH 40002)

  • 在空的SeriesDataFrame上使用Series.groupby()DataFrame.groupby()时,直接使用idxmaxidxminmadminmaxsumprodskew方法,或通过applyaggregateresample使用它们时,会丢失索引、列和/或数据类型(GH 26411

  • RollingGroupby对象上使用DataFrameGroupBy.apply()SeriesGroupBy.apply()时,存在一个错误,会创建一个MultiIndex而不是一个IndexGH 39732

  • weights被指定且索引为Int64Index时,DataFrameGroupBy.sample()存在一个错误,会引发错误(GH 39927

  • 在传递字典并且缺少列时,DataFrameGroupBy.aggregate()Resampler.aggregate()有时会引发SpecificationError,现在将始终引发KeyErrorGH 40004

  • 在计算结果之前,DataFrameGroupBy.sample()存在一个错误,不会应用列选择(GH 39928

  • 在调用__getitem__时,ExponentialMovingWindow存在一个错误,当提供times时会不正确地引发ValueErrorGH 40164

  • 在调用__getitem__时,ExponentialMovingWindow存在一个错误,会丢失comspanalphahalflife属性(GH 40164

  • 现在,在使用adjust=False指定times时,ExponentialMovingWindow会抛出NotImplementedError,因为计算不正确(GH 40098

  • engine='numba'时,ExponentialMovingWindowGroupby.mean()存在一个错误,会忽略times参数(GH 40951

  • 在存在多个分组时,ExponentialMovingWindowGroupby.mean()存在一个错误,会使用错误的timesGH 40951

  • ExponentialMovingWindowGroupby中存在一个 bug,对于非平凡组,时间向量和值会不同步(GH 40951)

  • Series.asfreq()DataFrame.asfreq()中存在一个 bug,在索引未排序时会丢弃行(GH 39805)

  • DataFrame的聚合函数中存在一个 bug,在给定level关键字时不尊重numeric_only参数(GH 40660)

  • SeriesGroupBy.aggregate()中存在一个 bug,使用用户定义的函数来聚合具有对象类型Index的 Series 会导致不正确的Index形状(GH 40014)

  • RollingGroupby中存在一个 bug,groupby中的as_index=False参数被忽略(GH 39433)

  • DataFrameGroupBy.any()SeriesGroupBy.any()DataFrameGroupBy.all()SeriesGroupBy.all()中存在一个 bug,当使用可空类型列并且即使skipna=True时,会引发ValueErrorGH 40585)

  • Bug in DataFrameGroupBy.cummin(), SeriesGroupBy.cummin(), DataFrameGroupBy.cummax() and SeriesGroupBy.cummax() incorrectly rounding integer values near the int64 implementations bounds (GH 40767)

  • Bug in DataFrameGroupBy.rank() and SeriesGroupBy.rank() with nullable dtypes incorrectly raising a TypeError (GH 41010)

  • Bug in DataFrameGroupBy.cummin(), SeriesGroupBy.cummin(), DataFrameGroupBy.cummax() and SeriesGroupBy.cummax() computing wrong result with nullable data types too large to roundtrip when casting to float (GH 37493)

  • Bug in DataFrame.rolling() returning mean zero for all NaN window with min_periods=0 if calculation is not numerical stable (GH 41053)

  • Bug in DataFrame.rolling() returning sum not zero for all NaN window with min_periods=0 if calculation is not numerical stable (GH 41053)

  • SeriesGroupBy.agg()中的错误,未能保留有序的CategoricalDtype 在保持顺序的聚合操作中(GH 41147

  • DataFrameGroupBy.min()SeriesGroupBy.min()DataFrameGroupBy.max()SeriesGroupBy.max() 中的错误,多个对象类型列和 numeric_only=False 错误地引发了ValueErrorGH 41111

  • DataFrameGroupBy.rank()中的错误,与 GroupBy 对象的 axis=0rank 方法的关键字 axis=1 相关(GH 41320

  • DataFrameGroupBy.__getitem__()中的错误,非唯一列错误地返回了格式错误的SeriesGroupBy 而不是 DataFrameGroupByGH 41427

  • DataFrameGroupBy.transform()中的错误,非唯一列错误地引发了AttributeErrorGH 41427

  • Resampler.apply()中的错误,非唯一列错误地丢弃了重复的列(GH 41445

  • Series.groupby()中的错误,聚合错误地返回空的Series 而不是对其 dtype 无效的聚合操作引发TypeError,例如,.proddatetime64[ns] dtype(GH 41342

  • 当没有有效列时,DataFrameGroupBy聚合错误地未删除那些聚合的无效数据类型的列导致错误(GH 41291

  • DataFrame.rolling.__iter__()中存在的错误,其中on未分配给结果对象的索引(GH 40373

  • 在使用engine="numba"时,DataFrameGroupBy.transform()DataFrameGroupBy.agg()*args与用户传递的函数一起被缓存的错误(GH 41647

  • DataFrameGroupBy方法aggtransformsumbfillffillpadpct_changeshiftohlc中删除了.columns.names的错误(GH 41497)

重塑

  • 在使用部分索引和right_index=True执行内部连接时,merge()在索引之间没有重叠时引发错误的错误(GH 33814

  • DataFrame.unstack()中存在的缺失级别导致索引名称不正确的错误(GH 37510

  • 在使用left_index=Trueright_on规范时,merge_asof()中传播正确的索引而不是左索引的错误(GH 33463

  • 在具有MultiIndex的 DataFrame 上进行DataFrame.join()时,当其中一个索引只有一个级别时返回错误的结果(GH 36909

  • merge_asof()现在在非数值合并列的情况下引发ValueError而不是晦涩的TypeErrorGH 29130

  • 当 DataFrame 具有MultiIndex且至少一个维度具有非按字母顺序排序的类别时,DataFrame.join()中未正确分配值的错误(GH 38502

  • Series.value_counts()Series.mode() 现在以原始顺序返回一致的键(GH 12679, GH 11227GH 39007)

  • DataFrame.stack() 中的 Bug 在 MultiIndex 列中未正确处理 NaNGH 39481)

  • DataFrame.apply() 中的 Bug 当参数 func 为字符串且 axis 不受支持时,会给出不正确的结果;现在会引发 ValueErrorGH 39211)

  • DataFrame.sort_values() 中的 Bug 在在列排序时,当 ignore_index=True 时未正确重塑索引(GH 39464)

  • DataFrame.append() 中的 Bug 在组合 ExtensionDtype dtypes 时返回不正确的 dtypes(GH 39454)

  • DataFrame.append() 中的 Bug 在 datetime64timedelta64 dtypes 的组合使用时返回不正确的 dtypes(GH 39574)

  • DataFrame.append() 中的 Bug 当使用具有 MultiIndexDataFrame 并且附加一个不是 MultiIndexSeries 时(GH 41707)

  • DataFrame.pivot_table() 中的 Bug 当对空 DataFrame 进行操作时,返回单个值的 MultiIndexGH 13483)

  • Index现在可以传递给numpy.all()函数(GH 40180)

  • DataFrame.stack()存在错误,在MultiIndex中不会保留CategoricalDtypeGH 36991)

  • to_datetime()存在错误,当输入序列包含不可哈希项时会引发错误(GH 39756)

  • Series.explode()存在错误,在 ignore_index 设置为 True 且值为标量时会保留索引(GH 40487)

  • to_datetime()存在错误,当Series包含NoneNaT并且元素超过 50 个时会引发ValueErrorGH 39882)

  • Series.unstack()DataFrame.unstack()中存在错误,包含时区感知的日期时间对象的对象 dtype 值会错误地引发TypeErrorGH 41875)

  • DataFrame.melt()存在错误,在作为 value_vars 使用的重复列的DataFrame中会引发 InvalidIndexErrorGH 41951)

稀疏

  • DataFrame.sparse.to_coo()存在错误,在列为数值型Index且没有0时会引发KeyErrorGH 18414)

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

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

ExtensionArray

  • other是具有ExtensionDtype的 Series 时,DataFrame.where()中的一个错误(GH 38729)

  • 修复了Series.idxmax()Series.idxmin()Series.argmax()Series.argmin()在基础数据为ExtensionArray时失败的错误(GH 32749, GH 33719, GH 36566)

  • 修复了PandasExtensionDtype的子类的一些属性被错误地缓存的错误(GH 40329)

  • DataFrame.mask()中的一个错误,使用ExtensionDtype对 DataFrame 进行掩码会引发ValueErrorGH 40941)

Styler

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

  • Styler的渲染 HTML 输出已经进行了轻微修改以支持 w3 良好的代码标准(GH 39626)

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

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

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

  • 在从 Jupyter 复制时,存在 Styler 的错误,顶部左侧单元格丢失且标题错位 (GH 12147)

  • Styler.where 中存在错误,未将 kwargs 传递给适用的可调用函数 (GH 40845)

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

其他

  • inspect.getmembers(Series) 不再引发 AbstractMethodError (GH 38782)

  • 在数值类型和 other=None 的情况下,Series.where() 存在错误,未将其转换为 nan (GH 39761)

  • 在属性具有未识别 NA 类型时,assert_series_equal()assert_frame_equal()assert_index_equal()assert_extension_array_equal() 错误地引发异常 (GH 39461)

  • 在使用 exact=True 时,assert_index_equal() 存在错误,当比较 CategoricalIndex 实例与 Int64IndexRangeIndex 类别时未引发异常 (GH 41263)

  • 在包含 np.datetime64("NaT")np.timedelta64("NaT") 的对象类型中,DataFrame.equals()Series.equals()Index.equals() 存在错误 (GH 39650)

  • show_versions()中存在一个错误,控制台 JSON 输出不是正确的 JSON 格式(GH 39701)。

  • 现在,当使用xlcGH 35826)时,pandas 现在可以在 z/OS 上编译。

  • pandas.util.hash_pandas_object()中存在一个错误,当输入对象类型为DataFrame时,无法识别hash_keyencodingcategorizeGH 41404)。

贡献者

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

  • Abhishek R +

  • Ada Draginda

  • Adam J. Stewart

  • Adam Turner +

  • Aidan Feldman +

  • Ajitesh Singh +

  • Akshat Jain +

  • Albert Villanova del Moral

  • Alexandre Prince-Levasseur +

  • Andrew Hawyrluk +

  • Andrew Wieteska

  • AnglinaBhambra +

  • Ankush Dua +

  • Anna Daglis

  • Ashlan Parker +

  • Ashwani +

  • Avinash Pancham

  • Ayushman Kumar +

  • BeanNan

  • Benoît Vinot

  • Bharat Raghunathan

  • Bijay Regmi +

  • Bobin Mathew +

  • Bogdan Pilyavets +

  • Brian Hulette +

  • Brian Sun +

  • Brock +

  • Bryan Cutler

  • Caleb +

  • Calvin Ho +

  • Chathura Widanage +

  • Chinmay Rane +

  • Chris Lynch

  • Chris Withers

  • Christos Petropoulos

  • Corentin Girard +

  • DaPy15 +

  • Damodara Puddu +

  • Daniel Hrisca

  • Daniel Saxton

  • DanielFEvans

  • Dare Adewumi +

  • Dave Willmer

  • David Schlachter +

  • David-dmh +

  • Deepang Raval +

  • Doris Lee +

  • Dr. Jan-Philip Gehrcke +

  • DriesS +

  • Dylan Percy

  • Erfan Nariman

  • Eric Leung

  • EricLeer +

  • Eve

  • Fangchen Li

  • Felix Divo

  • Florian Jetter

  • Fred Reiss

  • GFJ138 +

  • Gaurav Sheni +

  • Geoffrey B. Eisenbarth +

  • Gesa Stupperich +

  • Griffin Ansel +

  • Gustavo C. Maciel +

  • Heidi +

  • Henry +

  • Hung-Yi Wu +

  • Ian Ozsvald +

  • Irv Lustig

  • Isaac Chung +

  • Isaac Virshup

  • JHM Darbyshire (MBP) +

  • JHM Darbyshire (iMac) +

  • Jack Liu +

  • James Lamb +

  • Jeet Parekh

  • Jeff Reback

  • Jiezheng2018 +

  • Jody Klymak

  • Johan Kåhrström +

  • John McGuigan

  • Joris Van den Bossche

  • Jose

  • JoseNavy

  • Josh Dimarsky

  • Josh Friedlander

  • Joshua Klein +

  • Julia Signell

  • Julian Schnitzler +

  • Kaiqi Dong

  • Kasim Panjri +

  • Katie Smith +

  • Kelly +

  • Kenil +

  • Keppler, Kyle +

  • Kevin Sheppard

  • Khor Chean Wei +

  • Kiley Hewitt +

  • Larry Wong +

  • Lightyears +

  • Lucas Holtz +

  • Lucas Rodés-Guirao

  • Lucky Sivagurunathan +

  • Luis Pinto

  • Maciej Kos +

  • Marc Garcia

  • Marco Edward Gorelli +

  • Marco Gorelli

  • MarcoGorelli +

  • Mark Graham

  • Martin Dengler +

  • Martin Grigorov +

  • Marty Rudolf +

  • Matt Roeschke

  • Matthew Roeschke

  • Matthew Zeitlin

  • Max Bolingbroke

  • Maxim Ivanov

  • Maxim Kupfer +

  • Mayur +

  • MeeseeksMachine

  • Micael Jarniac

  • Michael Hsieh +

  • Michel de Ruiter +

  • Mike Roberts +

  • Miroslav Šedivý

  • Mohammad Jafar Mashhadi

  • Morisa Manzella +

  • Mortada Mehyar

  • Muktan +

  • Naveen Agrawal +

  • Noah

  • Nofar Mishraki +

  • Oleh Kozynets

  • Olga Matoula +

  • Oli +

  • Omar Afifi

  • Omer Ozarslan +

  • Owen Lamont +

  • Ozan Öğreden +

  • Pandas 开发团队

  • Paolo Lammens

  • Parfait Gasana +

  • Patrick Hoefler

  • Paul McCarthy +

  • Paulo S. Costa +

  • Pav A

  • Peter

  • Pradyumna Rahul +

  • Punitvara +

  • QP Hou +

  • Rahul Chauhan

  • Rahul Sathanapalli

  • Richard Shadrach

  • Robert Bradshaw

  • Robin to Roxel

  • Rohit Gupta

  • Sam Purkis +

  • Samuel GIFFARD +

  • Sean M. Law +

  • Shahar Naveh +

  • ShaharNaveh +

  • Shiv Gupta +

  • Shrey Dixit +

  • Shudong Yang +

  • Simon Boehm +

  • Simon Hawkins

  • Sioned Baker +

  • Stefan Mejlgaard +

  • Steven Pitman +

  • Steven Schaerer +

  • Stéphane Guillou +

  • TLouf +

  • Tegar D Pratama +

  • Terji Petersen

  • Theodoros Nikolaou +

  • Thomas Dickson

  • Thomas Li

  • Thomas Smith

  • Thomas Yu +

  • ThomasBlauthQC +

  • Tim Hoffmann

  • Tom Augspurger

  • Torsten Wörtwein

  • Tyler Reddy

  • UrielMaD

  • Uwe L. Korn

  • Venaturum +

  • VirosaLi

  • Vladimir Podolskiy

  • Vyom Pathak +

  • WANG Aiyong

  • Waltteri Koskinen +

  • Wenjun Si +

  • William Ayd

  • Yeshwanth N +

  • Yuanhao Geng

  • Zito Relova +

  • aflah02 +

  • arredond +

  • attack68

  • cdknox +

  • chinggg +

  • fathomer +

  • ftrihardjo +

  • github-actions[bot] +

  • gunjan-solanki +

  • guru kiran

  • hasan-yaman

  • i-aki-y +

  • jbrockmendel

  • jmholzer +

  • jordi-crespo +

  • jotasi +

  • jreback

  • juliansmidek +

  • kylekeppler

  • lrepiton +

  • lucasrodes

  • maroth96 +

  • mikeronayne +

  • mlondschien

  • moink +

  • morrme

  • mschmookler +

  • mzeitlin11

  • na2 +

  • nofarmishraki +

  • partev

  • patrick

  • ptype

  • realead

  • rhshadrach

  • rlukevie +

  • rosagold +

  • saucoide +

  • sdementen +

  • shawnbrown

  • sstiijn +

  • stphnlyd +

  • sukriti1 +

  • taytzehao

  • theOehrly +

  • theodorju +

  • thordisstella +

  • tonyyyyip +

  • tsinggggg +

  • tushushu +

  • vangorade +

  • vladu +

  • wertha +

posted @ 2024-06-26 10:34  绝不原创的飞龙  阅读(4)  评论(0编辑  收藏  举报