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

Pandas 2.2 中文文档(四十四)

原文:pandas.pydata.org/docs/

1.4.4 中的新功能(2022 年 8 月 31 日)

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

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

修复的回归

  • 修复了在具有MultiIndexDataFrameDataFrame.fillna()不起作用的回归(GH 47649)

  • 修复了从DataFrame中获取 NULL objects 导致分段违规的回归。这些 NULL 值是由 numpy.empty_like() 创建的(GH 46848)

  • 修复了在排序期间concat()在已经排序的情况下仍然实现Index的回归(GH 47501)

  • 修复了在处理具有自定义属性的全 NaN ExtensionArrays 时concat()merge()的回归(GH 47762)

  • 修复了在 Index 对象上调用位运算 numpy ufuncs(例如,np.bitwise_and)时的回归(GH 46769)

  • 修复了在使用datetime64 IntervalIndex 作为区间时cut()的回归(GH 46218)

  • 修复了在include="number"DataFrame.select_dtypes()中包括BooleanDtype的回归(GH 46870)

  • 修复了在使用NamedTuple进行索引时DataFrame.loc()引发错误的回归(GH 48124)

  • 修复了在设置值后DataFrame.loc()未正确更新缓存的回归(GH 47867)

  • 修复了在某些情况下,DataFrame.loc()中未对齐索引时的回归问题,当设置DataFrame时(GH 47578)。

  • 修复了在DataFrame.loc()中设置长度为 1 的数组值为 DataFrame 中的单个值时的回归问题(GH 46268)。

  • 修复了在使用具有DateOffset对象作为其freqDatetimeIndex进行切片时的回归问题,使用DataFrame.loc()进行切片(GH 46671)。

  • 修复了将None或非字符串值设置为string类型 Series 中的回归问题,使用掩码(GH 47628)。

  • 修复了通过 Series __setitem__(使用链式赋值)更新 DataFrame 列时未就地更新列值并且使用了过多内存的回归问题(GH 47172)。

  • 修复了在DataFrame.select_dtypes()中返回原始 DataFrame 的视图的回归问题(GH 48090)。

  • 修复了在使用自定义索引子类(例如,在 xarray 中使用)时,使用reset_index()Index.insert()的回归问题(GH 47071)。

  • 修复了在intersection()中的回归问题,当DatetimeIndex具有跨越夏令时的日期时(GH 46702)。

  • 修复了在传递具有多级名称的Series时,在merge()中抛出错误的回归问题(GH 47946)。

  • 修复了DataFrame.eval()中的回归问题,在更新 inplace 时创建副本(GH 47449)

  • 修复了使用SparseDtypeDataFrame.iloc()中获取行时引发的回归问题(GH 46406) ## Bug 修复

  • 当在read_csv()中将参数(除了filepath_or_buffer)作为位置参数传递时引发的FutureWarning现在在正确的堆栈级别上引发(GH 47385)

  • DataFrame.to_sql()中的错误,当method是一个不返回intcallable时会引发TypeErrorGH 46891)

  • DataFrameGroupBy.value_counts()中的错误,subset没有效果(GH 46383)

  • 使用DataFrame.loc()获取值时出现的错误,使用键列表导致内部不一致,可能导致frame.at[x, y]frame[y].loc[x]之间的断开连接(GH 22372)

  • Series.dt.strftime()访问器返回一个浮点数而不是对象 dtype Series 用于全为 NaT 的输入,这也会导致一个虚假的弃用警告(GH 45858) ## 其他

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

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

  • Jeff Reback

  • Joris Van den Bossche

  • Marco Edward Gorelli

  • Matthew Roeschke

  • MeeseeksMachine

  • Nima Sarang +

  • Pandas 开发团队

  • Patrick Hoefler

  • Simon Hawkins

  • Tobias Pitters

  • Xingrong Chen +

  • jbrockmendel ## 修复的回归问题

  • 修复了在具有 MultiIndexDataFrame 上不起作用的回归,DataFrame.fillna()GH 47649

  • 修复了从 DataFrame 中提取 NULL objects 导致分段错误的回归。这些 NULL 值是由 numpy.empty_like() 创建的(GH 46848

  • 修复了在排序期间实现 Index 的回归,即使 Index 已经排序(GH 47501

  • 修复了在 concat()merge() 处理所有 NaN ExtensionArrays 时的回归,具有自定义属性(GH 47762

  • 修复了在 Index 对象上调用位运算 numpy ufuncs(例如,np.bitwise_and)时的回归(GH 46769

  • 修复了使用 datetime64 IntervalIndex 作为区间时 cut() 的回归(GH 46218

  • 修复了在 DataFrame.select_dtypes() 中的回归,其中 include="number" 包括 BooleanDtypeGH 46870

  • 修复了在使用 NamedTuple 索引时 DataFrame.loc() 抛出错误的回归(GH 48124

  • 修复了在设置值后,DataFrame.loc() 没有正确更新缓存的回归(GH 47867

  • 修复了在某些情况下设置 DataFrame 时未对齐索引的回归,DataFrame.loc()GH 47578

  • 修复了在DataFrame.loc()中将长度为 1 的数组样式值设置为 DataFrame 中单个值的回归问题 (GH 46268)

  • 修复了在使用DatetimeIndexDataFrame.loc()进行切片时,其freqDateOffset对象的回归问题 (GH 46671)

  • 修复了使用掩码将None或非字符串值设置为string类型 Series 时的回归问题 (GH 47628)

  • 修复了通过 Series __setitem__(使用链式赋值)更新 DataFrame 列时不会就地更新列值并且使用了过多内存的回归问题 (GH 47172)

  • 修复了DataFrame.select_dtypes()中的回归问题,返回了原始 DataFrame 的视图(GH 48090)

  • 修复了在reset_index()Index.insert()中使用自定义索引子类(例如,在 xarray 中使用)时的回归问题 (GH 47071)

  • 修复了当DatetimeIndex的日期跨越夏令时时intersection()的回归问题 (GH 46702)

  • 修复了merge()中传递具有多级名称的Series时抛出错误的回归问题 (GH 47946)

  • 修复了DataFrame.eval()在更新 inplace 时创建副本的回归问题 (GH 47449)

  • 修复了使用 DataFrame.iloc() 时的回归问题,当使用 SparseDtype 获取行时会引发错误 (GH 46406)

Bug 修复

  • read_csv() 中将位置参数(除了 filepath_or_buffer)传递时,现在会在正确的堆栈级别引发 FutureWarning 警告 (GH 47385)

  • method 是一个不返回 int 的可调用对象时,在 DataFrame.to_sql() 中存在错误,会引发 TypeError (GH 46891)

  • DataFrameGroupBy.value_counts()subset 参数无效的错误已修复 (GH 46383)

  • 使用 DataFrame.loc() 获取值时存在错误,使用一个键列表导致内部不一致,可能导致 frame.at[x, y]frame[y].loc[x] 之间的断开 (GH 22372)

  • Series.dt.strftime() 访问器返回的是 float 而不是对象类型的 Series,对于全是 NaT 的输入,这也会引发一个错误的弃用警告 (GH 45858)

其他

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

贡献者

总共有 12 人为这个版本贡献了补丁。带有 “+” 标记的人第一次贡献了补丁。

  • Jeff Reback

  • Joris Van den Bossche

  • Marco Edward Gorelli

  • Matthew Roeschke

  • MeeseeksMachine

  • Nima Sarang +

  • Pandas 开发团队

  • Patrick Hoefler

  • Simon Hawkins

  • Tobias Pitters

  • Xingrong Chen +

  • jbrockmendel

1.4.3 新特性(2022 年 6 月 23 日)

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

这些是 pandas 1.4.3 中的更改。详见发布说明以获取包括 pandas 其他版本的完整更新日志。

concat 与空或全 NA 的 DataFrame 列的行为

在版本 1.4.0 中的行为更改,停止忽略 concat() 中具有 float 或对象 dtype 的空或全 NA 列的数据类型(在 concat 中忽略 dtypes 与空或全 NA 列)已被撤销 (GH 45637)。 ## 修复的回归

  • 修复了 DataFrame.replace() 中的回归,当替换值显式为 None 时,当传递给 to_replace 的字典时,即使没有值需要替换,也会将其他列转换为对象 dtype (GH 46634)

  • 修复了 DataFrame.to_csv() 中的回归,在 DataFrame 包含扩展 dtype 分类列时引发错误 (GH 46297, GH 46812)

  • 修复了 MultiIndexdtypes 属性的表示中的回归 (GH 46900)

  • 修复了当使用 DataFrame.loc() 设置值时的回归,更新 RangeIndex 时,当索引被设置为新列且列后来被更新时 (GH 47128)

  • 修复了 DataFrame.fillna()DataFrame.update() 中的回归,当 inplace 更新时创建副本 (GH 47188)

  • 修复了 DataFrame.nsmallest() 中的回归,当排序列有 np.nan 值时导致错误的结果 (GH 46589)

  • 修复了在read_fwf()中,当使用widths指定了usecols时引发ValueError的回归问题 (GH 46580)

  • 修复了在concat()中,对于混合列名不排序的回归问题 (GH 47127)

  • 修复了当索引是MultiIndex时,Groupby.transform()Groupby.agg()engine="numba"时失败的回归问题 (GH 46867)

  • 修复了在Index操作中,对于相同对象进行NaN比较的回归问题 (GH 47105)

  • 修复了在Styler.to_latex()Styler.to_html()中,bufencoding组合时失败的回归问题 (GH 47053)

  • 修复了read_csv()中的回归问题,当index_col=False时,将第一行识别为索引名称,而header=None时 (GH 46955)

  • 修复了在使用列表或字典以及axis=1时,DataFrameGroupBy.agg()中的回归问题会导致不正确结果的问题;现在会引发NotImplementedError (GH 46995)

  • 修复了在DataFrame.resample()DataFrame.rolling()中,当使用列表或字典以及axis=1时,会引发一个不直观的错误消息;现在会引发NotImplementedError (GH 46904)

  • 修复了在testing.assert_index_equal()中,当check_order=FalseIndex具有扩展或对象 dtype 时,出现的回归问题 (GH 47207)

  • 修复了read_excel()在某些输入表格上将整数返回为浮点数的回归问题(GH 46988

  • 修复了DataFrame.shift()中的回归问题,当axiscolumnsfill_value不存在时,freq被忽略(GH 47039

  • 修复了DataFrame.to_json()中的回归问题,当使用index参数为PeriodIndex类型创建DataFrame时,会导致分段违规(GH 46683) ## Bug fixes

  • pandas.eval()DataFrame.eval()DataFrame.query()中存在的 bug,当传递空的local_dictglobal_dict时被视为传递NoneGH 47084

  • 大多数 I/O 方法在关闭文件句柄时不再抑制OSErrorValueErrorGH 47136

  • 改进了在传递无效的orient参数时由DataFrame.from_dict()引发的错误消息(GH 47450) ## 其他

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

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

  • Alex-Blade +

  • Andrew Hawyrluk

  • JHM Darbyshire

  • Jeff Reback

  • Joris Van den Bossche

  • Marc Garcia

  • Marco Edward Gorelli

  • Matthew Roeschke

  • MeeseeksMachine

  • Pandas 开发团队

  • Patrick Hoefler

  • Richard Shadrach

  • Robert de Vries

  • Simon Hawkins

  • Thomas Li

  • Tim Swast

  • Wenjun Si

  • Yuanhao Geng ## concat与空白或全为 NA 的 DataFrame 列的行为

在版本 1.4.0 中停止忽略concat()中空白或全为 NA 列的浮点或对象数据类型的行为更改(忽略 concat 中空白或全为 NA 列的数据类型)已被撤销(GH 45637)。

修复的回归问题

  • 修复了当将替换值明确设置为None时,通过字典传递给to_replace时,DataFrame.replace()的回归问题,即使没有要替换的值,也会将其他列转换为对象 dtype(GH 46634)

  • 修复了当DataFrame包含扩展 dtype 分类列时,DataFrame.to_csv()引发错误的回归问题(GH 46297, GH 46812)

  • 修复了MultiIndexdtypes属性表示中的回归问题(GH 46900)

  • 修复了在将索引设置为新列并在之后更新列时,使用DataFrame.loc()设置值时的回归问题,更新RangeIndex时(GH 47128)

  • 修复了在更新时创建副本的DataFrame.fillna()DataFrame.update()的回归问题(GH 47188)

  • 修复了当排序列具有np.nan值时,DataFrame.nsmallest()导致错误结果的回归问题(GH 46589)

  • 修复了当widthsusecols一起指定时,read_fwf()引发ValueError的回归问题(GH 46580)

  • 修复了concat()在混合列名情况下未对列进行排序的回归问题(GH 47127)

  • 修复了当索引为MultiIndex时,使用engine="numba"Groupby.transform()Groupby.agg()失败的回归问题(GH 46867)

  • 修复了在Index操作中进行NaN比较时,相同对象进行比较的回归问题(GH 47105)

  • 修复了在bufencoding组合时,Styler.to_latex()Styler.to_html()buf失败的回归问题(GH 47053)

  • 修复了当index_col=False时,read_csv() 将第一行识别为索引名称时的回归问题,当header=None时(GH 46955)

  • 修复了在使用列表或字典以及axis=1时,DataFrameGroupBy.agg() 会给出不正确结果的回归问题;现在会引发NotImplementedErrorGH 46995)

  • 修复了在使用列表或字典以及axis=1时,DataFrame.resample()DataFrame.rolling() 会引发难以理解的错误消息的回归问题;现在会引发NotImplementedErrorGH 46904)

  • 修复了当check_order=False时,testing.assert_index_equal()Index 具有扩展或对象 dtype 时的回归问题(GH 47207)

  • 修复了在某些输入表中,read_excel() 将整数返回为浮点数的回归问题(GH 46988)

  • 修复了在axiscolumnsfill_value不存在时,DataFrame.shift() 的回归问题,忽略了freqGH 47039)

  • 修复了在使用PeriodIndex 类型的index参数创建 DataFrame 时,DataFrame.to_json() 导致分段违规的回归问题(GH 46683)

Bug 修复

  • pandas.eval()DataFrame.eval()DataFrame.query()中存在的 bug,传递空的local_dictglobal_dict被视为传递NoneGH 47084

  • 大多数 I/O 方法在关闭文件句柄时不再抑制OSErrorValueErrorGH 47136

  • 改进DataFrame.from_dict()在传递无效的orient参数时引发的错误消息(GH 47450

其他

  • 编译 pandas 所需的 Cython 的最低版本现在是0.29.30GH 41935

贡献者

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

  • Alex-Blade +

  • Andrew Hawyrluk

  • JHM Darbyshire

  • Jeff Reback

  • Joris Van den Bossche

  • Marc Garcia

  • Marco Edward Gorelli

  • Matthew Roeschke

  • MeeseeksMachine

  • Pandas 开发团队

  • Patrick Hoefler

  • Richard Shadrach

  • Robert de Vries

  • Simon Hawkins

  • Thomas Li

  • Tim Swast

  • Wenjun Si

  • Yuanhao Geng

1.4.2 版的新特性(2022 年 4 月 2 日)

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

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

修复的回归问题

  • 修复了当Index具有扩展数据类型且存在重复时,在DataFrame.drop()Series.drop()中的回归问题 (GH 45860)

  • 修复了在给定engine="c"的情况下,read_csv()中当输入文件无效时终止 Python 进程的回归问题 (GH 45957)

  • 修复了在具有inplace=True的情况下,对DataFrame列调用Series.fillna()时的内存性能回归问题 (GH 46149)

  • Styler.to_excel()提供了另一种解决方案,以解决基于更严格的 CSS 验证而导致的自定义 Excel 格式传递的回归问题。 示例可在Styler.format()的文档中找到 (GH 46152)

  • 修复了当替换值也是替换目标时的DataFrame.replace()中的回归问题 (GH 46306)

  • 修复了将替换值明确传递为字典中的to_replace时,当替换值显式为None时的DataFrame.replace()中的回归问题 (GH 45601, GH 45836)

  • 修复了使用DataFrame.loc()设置值时的回归问题,如果在之前DataFrame为空,则丢失MultiIndex名称 (GH 46317)

  • 修复了使用 Styler() 渲染布尔数据类型列时的回归问题(GH 46384

  • 修复了 Groupby.rolling() 中的回归问题,当频率窗口导致每个组内的日期时间单调增时,会引发 ValueErrorGH 46061) ## Bug 修复

  • 修复了一些情况,针对定义了 _constructor 属性为通用可调用对象的子类(GH 46018

  • 修复了在 Styler.to_latex() 中给定扩展格式的 column_format 时的“longtable”格式问题(GH 46037

  • 修复了在 Styler.format() 中使用 hyperlinks="html" 时,当网址包含冒号或其他特殊字符时的错误渲染问题(GH 46389

  • window 是频率且滚动轴中存在 NaT 时,改进了 Rolling 中的错误消息(GH 46087) ## 贡献者

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

  • Daniel Schmidt

  • JHM Darbyshire

  • Jonas Haag

  • Jordan Hicks +

  • Joris Van den Bossche

  • Kian Eliasi +

  • Luke Manley

  • Marco Edward Gorelli

  • Matthew Roeschke

  • MeeseeksMachine

  • Pandas 开发团队

  • Patrick Hoefler

  • Richard Shadrach

  • Simon Hawkins

  • jbrockmendel ## 修复的回归

  • 修复了在 DataFrame.drop()Series.drop() 中,当 Index 具有扩展数据类型且存在重复值时的回归问题(GH 45860

  • 修复了在 read_csv() 中使用 engine="c" 时,当给定无效文件输入时杀死 Python 进程的回归问题(GH 45957

  • 修复了在调用带有 inplace=TrueDataFrame 列的 Series.fillna() 时内存性能回归的问题(GH 46149

  • 提供了在 Styler.to_excel() 中传递自定义 Excel 格式的替代解决方案,这是基于更严格的 CSS 验证导致的回归。在 Styler.format() 的文档中提供了示例(GH 46152

  • 修复了在替换值也是替换目标时,在 DataFrame.replace() 中的回归问题(GH 46306

  • 修复了当将替换值明确设置为 None 时,在字典传递给 to_replace 时的 DataFrame.replace() 中的回归问题(GH 45601GH 45836

  • 修复了使用 DataFrame.loc() 设置值时的回归问题,在 DataFrame 在之前为空时丢失 MultiIndex 名称(GH 46317

  • 修复了使用 Styler() 渲染布尔数据类型列时的回归问题(GH 46384

  • 修复了带有频率窗口的 Groupby.rolling() 中的回归问题,即使每个组内的日期时间是单调的也会引发 ValueErrorGH 46061

Bug 修复

  • 修复了为定义它们的 _constructor 属性为通用可调用对象的子类的某些情况(GH 46018

  • 修复了在 Styler.to_latex() 中给定扩展格式的 column_format 时的“longtable”格式化问题(GH 46037

  • 修复了当 url 包含冒号或其他特殊字符时,在 Styler.format() 中使用 hyperlinks="html" 时的渲染错误(GH 46389

  • window 是频率且滚动轴中存在 NaT 时,改进了 Rolling 中的错误消息(GH 46087

贡献者

共有 15 人为此版本提交了补丁。带有“+”符号的人第一次贡献了补丁。

  • Daniel Schmidt

  • JHM Darbyshire

  • Jonas Haag

  • Jordan Hicks +

  • Joris Van den Bossche

  • Kian Eliasi +

  • Luke Manley

  • Marco Edward Gorelli

  • Matthew Roeschke

  • MeeseeksMachine

  • Pandas 开发团队

  • Patrick Hoefler

  • Richard Shadrach

  • Simon Hawkins

  • jbrockmendel

1.4.1 的新功能(2022 年 2 月 12 日)

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

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

修复的回归

  • inplace=TruePeriodDtype以及不兼容的other导致公共 dtype 而不是引发的情况下,Series.mask() 中的回归(GH 45546

  • assert_frame_equal() 中的回归不尊重check_flags=FalseGH 45554

  • 在使用DataFrame.loc() 对具有一个级别的MultiIndex 进行索引(获取值)时引发ValueError的回归(GH 45779

  • downcast=False时,Series.fillna() 中的回归不正确地向下转换object dtype(GH 45603

  • 在评估分类Series时,api.types.is_bool_dtype() 中的回归引发了AttributeErrorGH 45615

  • 在设置值时导致后续查找中不正确传播的回归,DataFrame.iat()GH 45684

  • DataFrame在之前为空时,使用DataFrame.loc() 设置值时丢失Index名称的回归(GH 45621

  • 在具有重叠的IntervalIndex的情况下,使用join() 中的回归引发了InvalidIndexErrorGH 45661

  • 使用Series.loc()设置值时出现回归,索引器全为False且右侧为Series时引发错误 (GH 45778)

  • 在具有非sqlite3.Connection实例的 DBAPI2 连接中使用read_sql()时出现的回归,错误地要求安装 SQLAlchemy (GH 45660)

  • 在使用整数参数且没有关键字的情况下构造DateOffset时的回归行为(例如pd.DateOffset(n))将表现为datetime.timedelta(days=0) (GH 45643, GH 45890) ## Bug 修复

  • 修复了在 Python 3.10 中在DataFrame.to_json()中转储 tz-aware datetimes 时的段错误 (GH 42130)

  • 停止在具有稀疏列的DataFrame.sort_values()中发出不必要的FutureWarning (GH 45618)

  • 修复了在DataFrame.rolling()Series.rolling()中的窗口聚合跳过未使用元素的问题 (GH 45647)

  • 修复了Styler中的内置突出显示器对具有可空数据类型的NA的响应性问题 (GH 45804)

  • 修复了在apply()中使用axis=1时引发错误ValueError的错误 (GH 45912) ## 其他

  • DataFrame.corr()method=pearson的性能提速还原,以修复精度回归 (GH 45640, GH 42761) ## 贡献者

共有 19 人为此版本贡献了补丁。名字旁边带有“+”符号的人第一次贡献了补丁。

  • Adam Bowden +

  • JHM Darbyshire

  • Johannes Mueller

  • John Zangwill

  • Jonas Haag

  • Matthew Roeschke

  • MeeseeksMachine

  • Pandas 开发团队

  • Patrick Hoefler

  • Robbie Palmer +

  • Simon Hawkins

  • Thomas Li

  • Tyler Reddy

  • eshirvana +

  • gesoos +

  • hasan-yaman

  • jbrockmendel

  • partev

  • rtpsw + ## 固定回归

  • Series.mask()中出现回归,使用inplace=TruePeriodDtype以及不兼容的other时,将强制转换为公共 dtype 而不是引发异常(GH 45546

  • assert_frame_equal()中出现回归,不遵守check_flags=FalseGH 45554

  • DataFrame.loc()中出现回归,在具有一个级别的MultiIndex上进行索引(获取值)时引发ValueErrorGH 45779

  • Series.fillna()中,使用downcast=False时,错误地将object dtype 向下转换(GH 45603

  • api.types.is_bool_dtype()中出现回归,在评估分类Series时引发AttributeErrorGH 45615

  • DataFrame.iat()中出现回归,设置值导致在后续查找中无法正确传播(GH 45684

  • 在使用DataFrame.loc()设置值时出现回归,如果在此之前DataFrame为空,则会丢失Index名称(GH 45621

  • join()中出现回归,与重叠的IntervalIndex一起引发InvalidIndexErrorGH 45661

  • 在使用Series.loc()设置值时出现回归,当所有False索引器和右侧的Series一起引发异常时(GH 45778

  • 在具有非sqlite3.Connection实例的 DBAPI2 连接中的read_sql()中的回归错误地要求安装 SQLAlchemy (GH 45660)

  • 在使用整数参数构造时DateOffset中的回归(例如pd.DateOffset(n))会像datetime.timedelta(days=0)一样行为(GH 45643, GH 45890)

Bug 修复

  • 修复了在 Python 3.10 中在DataFrame.to_json()中转储 tz-aware datetimes 时的段错误 (GH 42130)

  • 在具有稀疏列的DataFrame.sort_values()中停止发出不必要的FutureWarningGH 45618)

  • 修复了DataFrame.rolling()Series.rolling()中的窗口聚合以跳过未使用元素的问题 (GH 45647)

  • 修复了Styler中内置高亮器对具有可空数据类型的NA的响应性问题 (GH 45804)

  • 使用axis=1apply()中引发错误的ValueError的 Bug 修复 (GH 45912)

其他

  • method=pearsonDataFrame.corr()的性能加速还原以修复精度回归问题 (GH 45640, GH 42761)

贡献者

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

  • Adam Bowden +

  • JHM Darbyshire

  • Johannes Mueller

  • John Zangwill

  • Jonas Haag

  • Matthew Roeschke

  • MeeseeksMachine

  • Pandas 开发团队

  • Patrick Hoefler

  • Robbie Palmer +

  • Simon Hawkins

  • Thomas Li

  • Tyler Reddy

  • eshirvana +

  • gesoos +

  • hasan-yaman

  • jbrockmendel

  • partev

  • rtpsw +

版本 1.4.0 的新功能(2022 年 1 月 22 日)

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

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

增强功能

改进的警告消息

以前,警告消息可能指向 pandas 库中的行。运行脚本 setting_with_copy_warning.py

import pandas as pd

df = pd.DataFrame({'a': [1, 2, 3]})
df[:2].loc[:, 'a'] = 5 

使用 pandas 1.3 的结果为:

.../site-packages/pandas/core/indexing.py:1951: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame. 

这使得很难确定警告是从哪里生成的。现在 pandas 将检查调用堆栈,报告首次在 pandas 库外产生警告的代码行。以上脚本的输出现在是:

setting_with_copy_warning.py:4: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame. 
```  ### 索引可以容纳任意的 ExtensionArrays

到目前为止,将自定义的 `ExtensionArray` 传递给 `pd.Index` 将会将数组转换为 `object` 数据类型。现在 `Index` 可以直接容纳任意的 ExtensionArrays([GH 43930](https://github.com/pandas-dev/pandas/issues/43930))。

*之前的行为*:

```py
In [1]: arr = pd.array([1, 2, pd.NA])

In [2]: idx = pd.Index(arr) 

在旧的行为中,idx 将是 object 数据类型:

之前的行为

In [1]: idx
Out[1]: Index([1, 2, <NA>], dtype='object') 

有了新的行为,我们保留了原始数据类型:

新行为

In [3]: idx
Out[3]: Index([1, 2, <NA>], dtype='Int64') 

一个例外是 SparseArray,它将继续在 pandas 2.0 之前转换为 numpy 数据类型。到那时,它将保留与其他 ExtensionArrays 相同的数据类型。### 样式化器

在 1.4.0 版本中,Styler 已经进一步发展。已经进行了以下一般增强:

  • 已添加索引的样式和格式,包括 Styler.apply_index()Styler.applymap_index()Styler.format_index()。这些方法的签名与已用于样式化和格式化数据值的方法相同,并且适用于 HTML、LaTeX 和 Excel 格式(GH 41893GH 43101GH 41993GH 41995
  • 新的方法 Styler.hide() 废弃了 Styler.hide_index()Styler.hide_columns()GH 43758)。
  • Styler.hide() 方法新增了关键字参数 levelnames(隐式地也适用于已弃用的方法 Styler.hide_index()Styler.hide_columns()),用于额外控制 MultiIndexes 和 Index 名称的可见性(GH 25475, GH 43404, GH 43346)
  • Styler.export()Styler.use() 已更新,以处理从 v1.2.0 和 v1.3.0 添加的所有功能(GH 40675)
  • pd.options.styler 类别下的全局选项已扩展,以配置默认的 Styler 属性,涉及格式化、编码以及 HTML 和 LaTeX 渲染。请注意,以前 Styler 依赖于 display.html.use_mathjax,现在已被 styler.html.mathjax 取代(GH 41395)
  • 验证某些关键字参数,例如 captionGH 43368)
  • 下面记录了各种 bug 修复

此外,HTML 特定渲染还有特定的增强功能:

  • Styler.bar() 引入了额外的参数以控制对齐和显示(GH 26070, GH 36419),还验证了输入参数 widthheight 的有效性(GH 42511)
  • Styler.to_html() 引入了关键字参数 sparse_indexsparse_columnsbold_headerscaptionmax_rowsmax_columnsGH 41946, GH 43149, GH 42972)
  • Styler.to_html() 为了提高性能,省略了隐藏表元素的 CSSStyle 规则(GH 43619)
  • 可以直接指定自定义 CSS 类,而无需字符串替换 (GH 43686)
  • 通过新的hyperlinks格式关键字参数自动渲染超链接的能力 (GH 45058)

还有一些特定于 LaTeX 的增强功能:

  • Styler.to_latex()引入了关键字参数environment,通过一个单独的 jinja2 模板也允许指定特定的“longtable”条目 (GH 41866)
  • 可以在 LaTeX 中进行简单稀疏化,而无需包含 multirow 包 (GH 43369)
  • 通过关键字参数为MultiIndex行稀疏化添加了cline支持 (GH 45138) ### 基于 pyarrow 的新 CSV 引擎进行多线程 CSV 读取

pandas.read_csv()现在接受engine="pyarrow"(至少需要pyarrow 1.0.1)作为参数,允许在安装了 pyarrow 的多核机器上更快地解析 csv。更多信息请参见 I/O 文档。 (GH 23697, GH 43706)

RollingExpanding添加了rank函数。新函数支持DataFrame.rank()methodascendingpct标志。method参数支持minmaxaverage排名方法。示例:

In [4]: s = pd.Series([1, 4, 2, 3, 5, 3])

In [5]: s.rolling(3).rank()
Out[5]: 
0    NaN
1    NaN
2    2.0
3    2.0
4    3.0
5    1.5
dtype: float64

In [6]: s.rolling(3).rank(method="max")
Out[6]: 
0    NaN
1    NaN
2    2.0
3    2.0
4    3.0
5    2.0
dtype: float64 
```  ### 按位置对分组进行索引

现在可以指定相对于每个组末尾的位置范围。

对于`DataFrameGroupBy.head()`、`SeriesGroupBy.head()`、`DataFrameGroupBy.tail()`和`SeriesGroupBy.tail()`的负参数现在可以正确地工作,并分别导致相对于每个组的末尾和开始的范围。以前,负参数返回空框架。

```py
In [7]: df = pd.DataFrame([["g", "g0"], ["g", "g1"], ["g", "g2"], ["g", "g3"],
 ...:                   ["h", "h0"], ["h", "h1"]], columns=["A", "B"])
 ...: 

In [8]: df.groupby("A").head(-1)
Out[8]: 
 A   B
0  g  g0
1  g  g1
2  g  g2
4  h  h0 

DataFrameGroupBy.nth()SeriesGroupBy.nth() 现在支持整数和切片的列表或切片。

In [9]: df.groupby("A").nth(slice(1, -1))
Out[9]: 
 A   B
1  g  g1
2  g  g2

In [10]: df.groupby("A").nth([slice(None, 1), slice(-1, None)])
Out[10]: 
 A   B
0  g  g0
3  g  g3
4  h  h0
5  h  h1 

DataFrameGroupBy.nth()SeriesGroupBy.nth() 现在支持索引表示法。

In [11]: df.groupby("A").nth[1, -1]
Out[11]: 
 A   B
1  g  g1
3  g  g3
5  h  h1

In [12]: df.groupby("A").nth[1:-1]
Out[12]: 
 A   B
1  g  g1
2  g  g2

In [13]: df.groupby("A").nth[:1, -1:]
Out[13]: 
 A   B
0  g  g0
3  g  g3
4  h  h0
5  h  h1 
```  ### `DataFrame.from_dict` 和 `DataFrame.to_dict` 现在新增了 `'tight'` 选项

现在可以使用新的 `'tight'` 字典格式来保存 `MultiIndex` 条目和名称,该格式可以通过 `DataFrame.from_dict()` 和 `DataFrame.to_dict()` 方法,并且可以与标准的 `json` 库一起使用,以产生紧凑的 `DataFrame` 对象表示形式 ([GH 4889](https://github.com/pandas-dev/pandas/issues/4889)).

```py
In [14]: df = pd.DataFrame.from_records(
 ....:    [[1, 3], [2, 4]],
 ....:    index=pd.MultiIndex.from_tuples([("a", "b"), ("a", "c")],
 ....:                                    names=["n1", "n2"]),
 ....:    columns=pd.MultiIndex.from_tuples([("x", 1), ("y", 2)],
 ....:                                      names=["z1", "z2"]),
 ....: )
 ....: 

In [15]: df
Out[15]: 
z1     x  y
z2     1  2
n1 n2 
a  b   1  3
 c   2  4

In [16]: df.to_dict(orient='tight')
Out[16]: 
{'index': [('a', 'b'), ('a', 'c')],
 'columns': [('x', 1), ('y', 2)],
 'data': [[1, 3], [2, 4]],
 'index_names': ['n1', 'n2'],
 'column_names': ['z1', 'z2']} 
```  ### 其他增强

+   当所有对象的 `attrs` 相同时,`concat()` 将保留 `attrs`,当它们不同时,将丢弃 `attrs` ([GH 41828](https://github.com/pandas-dev/pandas/issues/41828))

+   使用 `as_index=False` 的 `DataFrameGroupBy` 操作现在可以正确地保留正在分组的列的 `ExtensionDtype` dtypes ([GH 41373](https://github.com/pandas-dev/pandas/issues/41373))

+   在 `DataFrame.plot.hist()` 和 `DataFrame.plot.box()` 中新增了对 `by` 参数赋值的支持 ([GH 15079](https://github.com/pandas-dev/pandas/issues/15079))

+   `Series.sample()`,`DataFrame.sample()`,`DataFrameGroupBy.sample()` 和 `SeriesGroupBy.sample()` 现在接受 `np.random.Generator` 作为 `random_state` 的输入。使用生成器性能更佳,特别是在 `replace=False` 时 ([GH 38100](https://github.com/pandas-dev/pandas/issues/38100))

+   `Series.ewm()` 和 `DataFrame.ewm()` 现在支持 `method` 参数,并且增加了 `'table'` 选项,该选项可以在整个 `DataFrame` 上执行窗口操作。参见 窗口概述 以了解性能和功能上的优势 ([GH 42273](https://github.com/pandas-dev/pandas/issues/42273))

+   `DataFrameGroupBy.cummin()`,`SeriesGroupBy.cummin()`,`DataFrameGroupBy.cummax()` 和 `SeriesGroupBy.cummax()` 现在支持参数 `skipna` ([GH 34047](https://github.com/pandas-dev/pandas/issues/34047))

+   `read_table()` 现在支持参数 `storage_options` ([GH 39167](https://github.com/pandas-dev/pandas/issues/39167))

+   `DataFrame.to_stata()` 和 `StataWriter()` 现在接受关键字参数 `value_labels`,用于保存非分类列的标签 ([GH 38454](https://github.com/pandas-dev/pandas/issues/38454))

+   依赖于基于哈希表算法的方法,例如`DataFrameGroupBy.value_counts()`、`DataFrameGroupBy.count()`和`factorize()`,忽略了复数的虚部([GH 17927](https://github.com/pandas-dev/pandas/issues/17927))

+   添加了 Python 3.9 中引入的`Series.str.removeprefix()`和`Series.str.removesuffix()`,用于从字符串类型的`Series`中移除前缀/后缀([GH 36944](https://github.com/pandas-dev/pandas/issues/36944))

+   使用`DataFrame.to_csv()`、`DataFrame.to_html()`、`DataFrame.to_excel()`、`DataFrame.to_feather()`、`DataFrame.to_parquet()`、`DataFrame.to_stata()`、`DataFrame.to_json()`、`DataFrame.to_pickle()`和`DataFrame.to_xml()`尝试写入缺失的父目录时,现在明确提到缺失的父目录,对应的`Series`方法也是如此([GH 24306](https://github.com/pandas-dev/pandas/issues/24306))

+   使用`.loc`和`.iloc`进行索引现在支持`Ellipsis`([GH 37750](https://github.com/pandas-dev/pandas/issues/37750))

+   `IntegerArray.all()`、`IntegerArray.any()`、`FloatingArray.any()`和`FloatingArray.all()`使用 Kleene 逻辑([GH 41967](https://github.com/pandas-dev/pandas/issues/41967))

+   在`DataFrame.to_stata()`、`StataWriter`、`StataWriter117`和`StataWriterUTF8`中增加了对可空布尔值和整数类型的支持([GH 40855](https://github.com/pandas-dev/pandas/issues/40855))

+   `DataFrame.__pos__()` 和 `DataFrame.__neg__()` 现在保留 `ExtensionDtype` 类型([GH 43883](https://github.com/pandas-dev/pandas/issues/43883))

+   当无法导入可选依赖项时引发的错误现在包含原始异常,以便更容易进行调查([GH 43882](https://github.com/pandas-dev/pandas/issues/43882))

+   添加了 `ExponentialMovingWindow.sum()`([GH 13297](https://github.com/pandas-dev/pandas/issues/13297))

+   `Series.str.split()` 现在支持 `regex` 参数,明确指定模式是否为正则表达式。默认为 `None`([GH 43563](https://github.com/pandas-dev/pandas/issues/43563), [GH 32835](https://github.com/pandas-dev/pandas/issues/32835), [GH 25549](https://github.com/pandas-dev/pandas/issues/25549))

+   `DataFrame.dropna()` 现在接受单个标签作为 `subset`,以及类似数组的对象([GH 41021](https://github.com/pandas-dev/pandas/issues/41021))

+   添加了 `DataFrameGroupBy.value_counts()`([GH 43564](https://github.com/pandas-dev/pandas/issues/43564))

+   `read_csv()` 现在在 `engine="python"` 时接受 `callable` 函数作为 `on_bad_lines`,用于自定义处理错误行([GH 5686](https://github.com/pandas-dev/pandas/issues/5686))

+   `ExcelWriter` 参数 `if_sheet_exists="overlay"` 选项已添加([GH 40231](https://github.com/pandas-dev/pandas/issues/40231))

+   `read_excel()` 现在接受 `decimal` 参数,允许用户在将字符串列解析为数值时指定小数点([GH 14403](https://github.com/pandas-dev/pandas/issues/14403))

+   `DataFrameGroupBy.mean()`、`SeriesGroupBy.mean()`、`DataFrameGroupBy.std()`、`SeriesGroupBy.std()`、`DataFrameGroupBy.var()`、`SeriesGroupBy.var()`、`DataFrameGroupBy.sum()` 和 `SeriesGroupBy.sum()` 现在支持使用 `engine` 关键字进行 [Numba](http://numba.pydata.org/) 执行([GH 43731](https://github.com/pandas-dev/pandas/issues/43731)、[GH 44862](https://github.com/pandas-dev/pandas/issues/44862)、[GH 44939](https://github.com/pandas-dev/pandas/issues/44939))

+   `Timestamp.isoformat()` 现在处理基础 `datetime` 类的 `timespec` 参数([GH 26131](https://github.com/pandas-dev/pandas/issues/26131))

+   `NaT.to_numpy()` 现在会尊重 `dtype` 参数,因此可以返回 `np.timedelta64`([GH 44460](https://github.com/pandas-dev/pandas/issues/44460))

+   新选项 `display.max_dir_items` 可自定义添加到 `Dataframe.__dir__()` 的列数,并建议用于制表补全([GH 37996](https://github.com/pandas-dev/pandas/issues/37996))

+   将“Juneteenth National Independence Day”添加到 `USFederalHolidayCalendar`([GH 44574](https://github.com/pandas-dev/pandas/issues/44574))

+   `Rolling.var()`、`Expanding.var()`、`Rolling.std()` 和 `Expanding.std()` 现在支持 [Numba](http://numba.pydata.org/) 执行,使用 `engine` 关键字([GH 44461](https://github.com/pandas-dev/pandas/issues/44461))

+   添加了 `Series.info()`,以兼容 `DataFrame.info()` ([GH 5167](https://github.com/pandas-dev/pandas/issues/5167))

+   实现了 `IntervalArray.min()` 和 `IntervalArray.max()`,因此 `min` 和 `max` 现在适用于带有 `IntervalDtype` 的 `IntervalIndex`、`Series` 和 `DataFrame` ([GH 44746](https://github.com/pandas-dev/pandas/issues/44746))

+   `UInt64Index.map()` 现在尽可能保留 `dtype`([GH 44609](https://github.com/pandas-dev/pandas/issues/44609))

+   `read_json()` 现在可以解析无符号长长整型数 ([GH 26068](https://github.com/pandas-dev/pandas/issues/26068))

+   当索引器传递标量时,`DataFrame.take()` 现在会引发 `TypeError` ([GH 42875](https://github.com/pandas-dev/pandas/issues/42875))

+   `is_list_like()` 现在将鸭式数组识别为类似列表,除非 `.ndim == 0` ([GH 35131](https://github.com/pandas-dev/pandas/issues/35131))

+   在使用 `orient='table'` 导出 `DataFrame` 时,`ExtensionDtype` 和 `ExtensionArray` 现在可以(反)序列化 ([GH 20612](https://github.com/pandas-dev/pandas/issues/20612), [GH 44705](https://github.com/pandas-dev/pandas/issues/44705))

+   为`DataFrame.to_pickle()`/`read_pickle()`及相关函数添加对[Zstandard](http://facebook.github.io/zstd/)压缩的支持([GH 43925](https://github.com/pandas-dev/pandas/issues/43925))

+   `DataFrame.to_sql()`现在返回写入行数的`int`类型([GH 23998](https://github.com/pandas-dev/pandas/issues/23998))  ## 显著的错误修复

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

### 不一致的日期字符串解析

`to_datetime()`的`dayfirst`选项不是严格的,这可能导致意外行为:

```py
In [17]: pd.to_datetime(["31-12-2021"], dayfirst=False)
Out[17]: DatetimeIndex(['2021-12-31'], dtype='datetime64[ns]', freq=None) 

现在,如果一个日期字符串不能根据给定的dayfirst值进行解析,而该值是一个分隔的日期字符串(例如31-12-2012),则会发出警告。 ### 忽略与空列或全 NA 列连接的数据类型

注意

此行为更改在 pandas 1.4.3 中已被恢复。

当使用concat()来连接两个或多个DataFrame对象时,如果其中一个 DataFrame 是空的或具有全 NA 值,则在找到连接数据类型时,其数据类型有时会被忽略。现在这些都一致地被忽略(GH 43507)。

In [3]: df1 = pd.DataFrame({"bar": [pd.Timestamp("2013-01-01")]}, index=range(1))
In [4]: df2 = pd.DataFrame({"bar": np.nan}, index=range(1, 2))
In [5]: res = pd.concat([df1, df2]) 

以前,df2中的浮点数据类型将被忽略,因此结果数据类型将为datetime64[ns]。 结果,np.nan将被转换为NaT

以前的行为

In [6]: res
Out[6]:
 bar
0 2013-01-01
1        NaT 

现在浮点数据类型受到尊重。 由于这些 DataFrame 的常见数据类型是 object,因此np.nan将被保留。

新行为

In [6]: res
Out[6]:
 bar
0  2013-01-01 00:00:00
1                  NaN 
```  ### value_counts 和 mode 中不再将空值强制转换为 NaN 值

`Series.value_counts()` 和 `Series.mode()` 现在不再将`None`、`NaT`和其他空值强制转换为`np.object_`类型的 NaN 值。 此行为现在与`unique`、`isin`和其他行为一致([GH 42688](https://github.com/pandas-dev/pandas/issues/42688))。

```py
In [18]: s = pd.Series([True, None, pd.NaT, None, pd.NaT, None])

In [19]: res = s.value_counts(dropna=False) 

以前,所有空值都被替换为 NaN 值。

以前的行为

In [3]: res
Out[3]:
NaN     5
True    1
dtype: int64 

现在空值不再混乱。

新行为

In [20]: res
Out[20]: 
None    3
NaT     2
True    1
Name: count, dtype: int64 
```  ### 在 read_csv 中 mangle_dupe_cols 不再重命名与目标名称冲突的唯一列

`read_csv()` 不再重命名与重复列的目标名称冲突的唯一列标签。已存在的列会被跳过,即下一个可用索引用于目标列名 ([GH 14704](https://github.com/pandas-dev/pandas/issues/14704))。

```py
In [21]: import io

In [22]: data = "a,a,a.1\n1,2,3"

In [23]: res = pd.read_csv(io.StringIO(data)) 

以前,第二列称为 a.1,而第三列也重命名为 a.1.1

之前的行为

In [3]: res
Out[3]:
 a  a.1  a.1.1
0   1    2      3 

现在在更改第二列名称时,重命名检查是否已存在 a.1,并跳过此索引。第二列改为重命名为 a.2

新行为

In [24]: res
Out[24]: 
 a  a.2  a.1
0  1    2    3 
```  ### unstack 和 pivot_table 不再对结果超过 int32 限制而引发 ValueError

以前 `DataFrame.pivot_table()` 和 `DataFrame.unstack()` 如果操作可以生成超过 `2**31 - 1` 元素的结果,则会引发 `ValueError`。此操作现在会引发一个 `errors.PerformanceWarning` ([GH 26314](https://github.com/pandas-dev/pandas/issues/26314))。

*之前的行为*:

```py
In [3]: df = DataFrame({"ind1": np.arange(2 ** 16), "ind2": np.arange(2 ** 16), "count": 0})
In [4]: df.pivot_table(index="ind1", columns="ind2", values="count", aggfunc="count")
ValueError: Unstacked DataFrame is too big, causing int32 overflow 

新行为

In [4]: df.pivot_table(index="ind1", columns="ind2", values="count", aggfunc="count")
PerformanceWarning: The following operation may generate 4294967296 cells in the resulting pandas object. 
```  ### groupby.apply 一致的变换检测

`DataFrameGroupBy.apply()` 和 `SeriesGroupBy.apply()` 被设计成灵活的,允许用户执行聚合、变换、过滤,并与用户定义的不属于这些类别的函数一起使用。作为其中的一部分,apply 将尝试检测操作是否是一个变换,在这种情况下,结果将具有与输入相同的索引。为了确定操作是否是一个变换,pandas 将输入的索引与结果的索引进行比较,并确定是否已被改变。在 pandas 1.3 中,不同的代码路径使用不同的“已改变”定义:一些将使用 Python 的 `is`,而其他一些则只测试到相等性。

这种不一致性已经被移除,pandas 现在进行了相等性测试。

```py
In [25]: def func(x):
 ....:    return x.copy()
 ....: 

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

In [27]: df
Out[27]: 
 a  b  c
0  1  3  5
1  2  4  6 

之前的行为

In [3]: df.groupby(['a']).apply(func)
Out[3]:
 a  b  c
a
1 0  1  3  5
2 1  2  4  6

In [4]: df.set_index(['a', 'b']).groupby(['a']).apply(func)
Out[4]:
 c
a b
1 3  5
2 4  6 

在上述示例中,第一个使用了 pandas 使用 is 并确定 func 不是一个变换的代码路径,而第二个则测试到相等性并确定 func 是一个变换。在第一种情况下,结果的索引与输入的索引不同。

新行为

In [5]: df.groupby(['a']).apply(func)
Out[5]:
 a  b  c
0  1  3  5
1  2  4  6

In [6]: df.set_index(['a', 'b']).groupby(['a']).apply(func)
Out[6]:
 c
a b
1 3  5
2 4  6 

现在在两种情况下都确定func是一个 transform。在每种情况下,结果与输入具有相同的索引。 ## 不兼容的 API 更改

Python 的最低版本增加

pandas 1.4.0 支持 Python 3.8 及更高版本。 ### 增加了依赖项的最低版本

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

包名 最低版本 需要 更改
numpy 1.18.5 X X
pytz 2020.1 X X
python-dateutil 2.8.1 X X
bottleneck 1.3.1 X
numexpr 2.7.1 X
pytest (dev) 6.0
mypy (dev) 0.930 X

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

包名 最低版本 更改
beautifulsoup4 4.8.2 X
fastparquet 0.4.0
fsspec 0.7.4
gcsfs 0.6.0
lxml 4.5.0 X
matplotlib 3.3.2 X
numba 0.50.1 X
openpyxl 3.0.3 X
pandas-gbq 0.14.0 X
pyarrow 1.0.1 X
pymysql 0.10.1 X
pytables 3.6.1 X
s3fs 0.4.0
scipy 1.4.1 X
sqlalchemy 1.4.0 X
tabulate 0.8.7
xarray 0.15.1 X
xlrd 2.0.1 X
xlsxwriter 1.2.2 X
xlwt 1.3.0

查看依赖项和可选依赖项了解更多。 ### 其他 API 更改

  • Index.get_indexer_for()不再接受关键字参数(除了target);过去如果索引不唯一,这些参数将被静默忽略(GH 42310

  • 由于文档字符串的更改,DataFrame.to_string()min_rows参数的位置发生变化(GH 44304)

  • 对于DataFrameSeries的缩减操作现在在skipna传递None时引发ValueErrorGH 44178

  • 当其中一个标题行仅包含Unnamed:列时,read_csv()read_html()不再引发错误(GH 13054

  • USFederalHolidayCalendar中几个节日的name属性更改为匹配官方联邦节日名称

    • “元旦”获得所有格符号
    • “总统日”现在变成了“华盛顿生日”
    • “马丁·路德·金·恩格尔斯日”现在是“马丁·路德·金·恩格尔斯的生日”
    • “7 月 4 日”现在是“独立日”
    • “感恩节”现在是“感恩节”
    • “圣诞节”现在是“圣诞节”
    • 添加“六月节国家独立日” ## 已弃用项

已弃用的 Int64Index、UInt64Index 和 Float64Index

Int64IndexUInt64IndexFloat64Index已被弃用,推荐使用基础Index类,并将在 Pandas 2.0 中移除(GH 43028)。

为构建数值索引,您可以使用基础Index类,而不是指定数据类型(这也适用于较旧的 pandas 版本):

# replace
pd.Int64Index([1, 2, 3])
# with
pd.Index([1, 2, 3], dtype="int64") 

用于检查索引对象数据类型,您可以用检查dtype替换isinstance检查:

# replace
isinstance(idx, pd.Int64Index)
# with
idx.dtype == "int64" 

目前为了保持向后兼容性,对Index的调用在给定数值数据时仍将返回Int64IndexUInt64IndexFloat64Index,但在未来将返回一个Index

当前行为:

In [1]: pd.Index([1, 2, 3], dtype="int32")
Out [1]: Int64Index([1, 2, 3], dtype='int64')
In [1]: pd.Index([1, 2, 3], dtype="uint64")
Out [1]: UInt64Index([1, 2, 3], dtype='uint64') 

未来行为:

In [3]: pd.Index([1, 2, 3], dtype="int32")
Out [3]: Index([1, 2, 3], dtype='int32')
In [4]: pd.Index([1, 2, 3], dtype="uint64")
Out [4]: Index([1, 2, 3], dtype='uint64') 
```  ### 已弃用的 DataFrame.append 和 Series.append

`DataFrame.append()`和`Series.append()`已被弃用,并将在未来版本中移除。请改用`pandas.concat()`([GH 35407](https://github.com/pandas-dev/pandas/issues/35407))。

*已弃用的语法*

```py
In [1]: pd.Series([1, 2]).append(pd.Series([3, 4])
Out [1]:
<stdin>:1: FutureWarning: The series.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
0    1
1    2
0    3
1    4
dtype: int64

In [2]: df1 = pd.DataFrame([[1, 2], [3, 4]], columns=list('AB'))
In [3]: df2 = pd.DataFrame([[5, 6], [7, 8]], columns=list('AB'))
In [4]: df1.append(df2)
Out [4]:
<stdin>:1: FutureWarning: The series.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
 A  B
0  1  2
1  3  4
0  5  6
1  7  8 

推荐的语法

In [28]: pd.concat([pd.Series([1, 2]), pd.Series([3, 4])])
Out[28]: 
0    1
1    2
0    3
1    4
dtype: int64

In [29]: df1 = pd.DataFrame([[1, 2], [3, 4]], columns=list('AB'))

In [30]: df2 = pd.DataFrame([[5, 6], [7, 8]], columns=list('AB'))

In [31]: pd.concat([df1, df2])
Out[31]: 
 A  B
0  1  2
1  3  4
0  5  6
1  7  8 
```  ### 其他已弃用项

+   已弃用`Index.is_type_compatible()`([GH 42113](https://github.com/pandas-dev/pandas/issues/42113))

+   已弃用`Index.get_loc()`中的`method`参数,改用`index.get_indexer([label], method=...)`代替([GH 42269](https://github.com/pandas-dev/pandas/issues/42269))

+   当索引为`Float64Index`且不包含键、`IntervalIndex` 不包含键或具有未包含键的前导`Float64Index`级别时,在 `Series.__setitem__()` 中不再将整数键视为位置时已过时([GH 33469](https://github.com/pandas-dev/pandas/issues/33469))

+   当与时区一起传递给`Timestamp` 构造函数时,不再将`numpy.datetime64`对象视为 UTC 时间已过时。在将来的版本中,它们将被视为墙上时间。要保留旧行为,请使用`Timestamp(dt64).tz_localize("UTC").tz_convert(tz)`([GH 24559](https://github.com/pandas-dev/pandas/issues/24559))

+   使用序列标签索引`MultiIndex` 时,不再忽略缺失的标签([GH 42351](https://github.com/pandas-dev/pandas/issues/42351))

+   创建不带`dtype`的空`Series` 现在会引发更明显的`FutureWarning`,而不是`DeprecationWarning`([GH 30017](https://github.com/pandas-dev/pandas/issues/30017))

+   在未来的版本中,通过`kind`将在 `Index.get_slice_bound()`, `Index.slice_indexer()`, 和 `Index.slice_locs()` 中引发异常已过时([GH 42857](https://github.com/pandas-dev/pandas/issues/42857))

+   在`Rolling`、`Expanding`和`EWM`聚合中不再删除无用列已过时([GH 42738](https://github.com/pandas-dev/pandas/issues/42738))

+   不再推荐使用带有非唯一`Index` 的`Index.reindex()`([GH 42568](https://github.com/pandas-dev/pandas/issues/42568))

+   不再推荐使用`Styler.render()`,而是使用`Styler.to_html()`([GH 42140](https://github.com/pandas-dev/pandas/issues/42140))

+   不再推荐使用`Styler.hide_index()` 和 `Styler.hide_columns()`,而是使用`Styler.hide()`([GH 43758](https://github.com/pandas-dev/pandas/issues/43758)")

+   在`DataFrame.ewm()`中,不再支持将字符串列标签传递给`times`参数([GH 43265](https://github.com/pandas-dev/pandas/issues/43265))

+   在`DataFrame.between_time()`中弃用了`include_start`和`include_end`参数;在将来的版本中,传递`include_start`或`include_end`将引发错误([GH 40245](https://github.com/pandas-dev/pandas/issues/40245))

+   在`read_csv()`、`read_table()`和`read_excel()`中,弃用了`squeeze`参数。用户应该使用`.squeeze("columns")`在之后挤压`DataFrame`([GH 43242](https://github.com/pandas-dev/pandas/issues/43242))

+   在`SparseArray`构造函数中弃用了`index`参数([GH 23089](https://github.com/pandas-dev/pandas/issues/23089))

+   在`date_range()`和`bdate_range()`中弃用了`closed`参数,支持`inclusive`参数;在将来的版本中传递`closed`将引发错误([GH 40245](https://github.com/pandas-dev/pandas/issues/40245))

+   弃用了`Rolling.validate()`、`Expanding.validate()`和`ExponentialMovingWindow.validate()`([GH 43665](https://github.com/pandas-dev/pandas/issues/43665))

+   当与字典一起使用时,在`Series.transform`和`DataFrame.transform`中弃用了无声删除引发`TypeError`的列([GH 43740](https://github.com/pandas-dev/pandas/issues/43740))

+   在`Series.aggregate()`、`DataFrame.aggregate()`、`Series.groupby.aggregate()`和`DataFrame.groupby.aggregate()`中,当与列表一起使用时,不再支持无声删除引发`TypeError`、`DataError`和某些情况下的`ValueError`的列([GH 43740](https://github.com/pandas-dev/pandas/issues/43740))

+   当将带有不匹配时区的值设置为带时区的`Series`或`DataFrame`列时,不再支持强制转换行为。以前会转换为对象 dtype。在将来的版本中,将插入的值将转换为系列或列的现有时区([GH 37605](https://github.com/pandas-dev/pandas/issues/37605))

+   当将带有不匹配时区的项目传递给`DatetimeIndex.insert()`、`DatetimeIndex.putmask()`、`DatetimeIndex.where()`、`DatetimeIndex.fillna()`、`Series.mask()`、`Series.where()`、`Series.fillna()`、`Series.shift()`、`Series.replace()`、`Series.reindex()`(以及`DataFrame`列类似情况)时,不再支持强制转换行为。过去会转换为对象 dtype。在将来���版本中,这些将转换为索引或系列的时区([GH 37605](https://github.com/pandas-dev/pandas/issues/37605),[GH 44940](https://github.com/pandas-dev/pandas/issues/44940))

+   在`read_csv()`和`read_table()`中不再支持`prefix`关键字参数,在将来的版本中将删除该参数([GH 43396](https://github.com/pandas-dev/pandas/issues/43396))

+   在`concat()`中不再支持将非布尔值参数传递给`sort`([GH 41518](https://github.com/pandas-dev/pandas/issues/41518))

+   对于`read_fwf()`,不再支持将参数作为位置参数传递,除了`filepath_or_buffer`([GH 41485](https://github.com/pandas-dev/pandas/issues/41485))

+   对于`read_xml()`,不再支持将参数作为位置参数传递,除了`path_or_buffer`([GH 45133](https://github.com/pandas-dev/pandas/issues/45133))

+   对于`DataFrame.mad()`和`Series.mad()`,不再支持传递`skipna=None`,请改为传递`skipna=True`([GH 44580](https://github.com/pandas-dev/pandas/issues/44580))

+   废弃了带有字符串“now”的`to_datetime()`的行为,`utc=False`;在未来版本中,这将匹配`Timestamp("now")`,进而匹配`Timestamp.now()`返回本地时间([GH 18705](https://github.com/pandas-dev/pandas/issues/18705))

+   废弃了`DateOffset.apply()`,请使用`offset + other`代替([GH 44522](https://github.com/pandas-dev/pandas/issues/44522))

+   在`Index.copy()`中弃用了参数`names`([GH 44916](https://github.com/pandas-dev/pandas/issues/44916))

+   现在为`DataFrame.to_latex()`显示了一个弃用警告,表明参数签名可能会改变,并在未来版本中模拟更多`Styler.to_latex()`的参数([GH 44411](https://github.com/pandas-dev/pandas/issues/44411))

+   废弃了在布尔类型和数值类型对象之间的`concat()`行为;在未来版本中,这些将转换为对象类型,而不是将布尔值强制转换为数值值([GH 39817](https://github.com/pandas-dev/pandas/issues/39817))

+   废弃了`Categorical.replace()`,请使用`Series.replace()`代替([GH 44929](https://github.com/pandas-dev/pandas/issues/44929))

+   废弃了将`set`或`dict`作为`DataFrame.loc.__setitem__()`、`DataFrame.loc.__getitem__()`、`Series.loc.__setitem__()`、`Series.loc.__getitem__()`、`DataFrame.__getitem__()`、`Series.__getitem__()`和`Series.__setitem__()`的索引器传递([GH 42825](https://github.com/pandas-dev/pandas/issues/42825))

+   废弃了使用布尔键的`Index.__getitem__()`;请使用`index.values[key]`来获取旧的行为([GH 44051](https://github.com/pandas-dev/pandas/issues/44051))

+   在`DataFrame.where()`中弃用了逐列降级,使用整数类型([GH 44597](https://github.com/pandas-dev/pandas/issues/44597))

+   废弃了`DatetimeIndex.union_many()`,请使用`DatetimeIndex.union()`代替([GH 44091](https://github.com/pandas-dev/pandas/issues/44091))

+   废弃了`Groupby.pad()`,推荐使用`Groupby.ffill()`([GH 33396](https://github.com/pandas-dev/pandas/issues/33396))

+   废弃了`Groupby.backfill()`,推荐使用`Groupby.bfill()`([GH 33396](https://github.com/pandas-dev/pandas/issues/33396))

+   弃用了`Resample.pad()`,推荐使用`Resample.ffill()`([GH 33396](https://github.com/pandas-dev/pandas/issues/33396))

+   弃用了`Resample.backfill()`,推荐使用`Resample.bfill()`([GH 33396](https://github.com/pandas-dev/pandas/issues/33396))

+   弃用了`DataFrame.rank()`中的`numeric_only=None`;在将来的版本中,`numeric_only`必须是`True`或`False`(默认值)([GH 45036](https://github.com/pandas-dev/pandas/issues/45036))

+   弃用了`Timestamp.utcfromtimestamp()`的行为,将来将返回一个带有时区信息的 UTC `Timestamp`([GH 22451](https://github.com/pandas-dev/pandas/issues/22451))

+   弃用了`NaT.freq()`([GH 45071](https://github.com/pandas-dev/pandas/issues/45071))

+   当传递包含`NaN`和整数 dtype 的浮点 dtype 数据时,弃用了`Series`和`DataFrame`构造的行为,忽略 dtype 参数;在将来的版本中,这将会引发错误([GH 40110](https://github.com/pandas-dev/pandas/issues/40110))

+   弃用了`Series.to_frame()`和`Index.to_frame()`在`name=None`时忽略`name`参数的行为。目前,这意味着保留现有名称,但在将来,显式传递`name=None`将会将`None`设置为生成的 DataFrame 中列的名称([GH 44212](https://github.com/pandas-dev/pandas/issues/44212))  ## 性能改进

+   在`DataFrameGroupBy.sample()`和`SeriesGroupBy.sample()`中的性能改进,特别是在提供`weights`参数时([GH 34483](https://github.com/pandas-dev/pandas/issues/34483))

+   将非字符串数组转换为字符串数组时的性能改进([GH 34483](https://github.com/pandas-dev/pandas/issues/34483))

+   对于用户定义的函数,在 `DataFrameGroupBy.transform()` 和 `SeriesGroupBy.transform()` 中的性能改进([GH 41598](https://github.com/pandas-dev/pandas/issues/41598))

+   构造 `DataFrame` 对象时的性能改进([GH 42631](https://github.com/pandas-dev/pandas/issues/42631),[GH 43142](https://github.com/pandas-dev/pandas/issues/43142),[GH 43147](https://github.com/pandas-dev/pandas/issues/43147),[GH 43307](https://github.com/pandas-dev/pandas/issues/43307),[GH 43144](https://github.com/pandas-dev/pandas/issues/43144),[GH 44826](https://github.com/pandas-dev/pandas/issues/44826))

+   当提供 `fill_value` 参数时,在 `DataFrameGroupBy.shift()` 和 `SeriesGroupBy.shift()` 中的性能改进([GH 26615](https://github.com/pandas-dev/pandas/issues/26615))

+   在没有缺失值的数据上,`DataFrame.corr()` 中 `method=pearson` 的性能改进([GH 40956](https://github.com/pandas-dev/pandas/issues/40956))

+   在一些 `DataFrameGroupBy.apply()` 和 `SeriesGroupBy.apply()` 操作中的性能改进([GH 42992](https://github.com/pandas-dev/pandas/issues/42992),[GH 43578](https://github.com/pandas-dev/pandas/issues/43578))

+   在 `read_stata()` 中的性能改进([GH 43059](https://github.com/pandas-dev/pandas/issues/43059),[GH 43227](https://github.com/pandas-dev/pandas/issues/43227))

+   在 `read_sas()` 中的性能改进([GH 43333](https://github.com/pandas-dev/pandas/issues/43333))

+   在带有 `uint` 数据类型的 `to_datetime()` 中的性能改进([GH 42606](https://github.com/pandas-dev/pandas/issues/42606))

+   在`to_datetime()`中将`infer_datetime_format`设置为`True`时的性能改进([GH 43901](https://github.com/pandas-dev/pandas/issues/43901))

+   在`Series.sparse.to_coo()`中的性能改进([GH 42880](https://github.com/pandas-dev/pandas/issues/42880))

+   在使用`UInt64Index`进行索引时的性能改进([GH 43862](https://github.com/pandas-dev/pandas/issues/43862))

+   在使用`Float64Index`进行索引时的性能改进([GH 43705](https://github.com/pandas-dev/pandas/issues/43705))

+   在使用非唯一`Index`进行索引时的性能改进([GH 43792](https://github.com/pandas-dev/pandas/issues/43792))

+   在使用`MultiIndex`上的列表索引器进行索引时的性能改进([GH 43370](https://github.com/pandas-dev/pandas/issues/43370))

+   在另一个`MultiIndex`上的`MultiIndex`索引器上进行索引时的性能改进([GH 43370](https://github.com/pandas-dev/pandas/issues/43370))

+   在`DataFrameGroupBy.quantile()`和`SeriesGroupBy.quantile()`中的性能改进([GH 43469](https://github.com/pandas-dev/pandas/issues/43469),[GH 43725](https://github.com/pandas-dev/pandas/issues/43725))

+   在`DataFrameGroupBy.count()`和`SeriesGroupBy.count()`中的性能改进([GH 43730](https://github.com/pandas-dev/pandas/issues/43730),[GH 43694](https://github.com/pandas-dev/pandas/issues/43694))

+   `DataFrameGroupBy.any()`、`SeriesGroupBy.any()`、`DataFrameGroupBy.all()` 和 `SeriesGroupBy.all()` 的性能改进([GH 43675](https://github.com/pandas-dev/pandas/issues/43675), [GH 42841](https://github.com/pandas-dev/pandas/issues/42841))

+   `DataFrameGroupBy.std()` 和 `SeriesGroupBy.std()` 的性能改进([GH 43115](https://github.com/pandas-dev/pandas/issues/43115), [GH 43576](https://github.com/pandas-dev/pandas/issues/43576))

+   `DataFrameGroupBy.cumsum()` 和 `SeriesGroupBy.cumsum()` 的性能改进([GH 43309](https://github.com/pandas-dev/pandas/issues/43309))

+   `SparseArray.min()` 和 `SparseArray.max()` 不再需要转换为稠密数组([GH 43526](https://github.com/pandas-dev/pandas/issues/43526))

+   使用 `step=1` 的 `slice` 进行 `SparseArray` 索引不再需要转换为稠密数组([GH 43777](https://github.com/pandas-dev/pandas/issues/43777))

+   在 `SparseArray.take()` 中使用 `allow_fill=False` 的性能改进([GH 43654](https://github.com/pandas-dev/pandas/issues/43654))

+   `Rolling.mean()`、`Expanding.mean()`、`Rolling.sum()`、`Expanding.sum()`、`Rolling.max()`、`Expanding.max()`、`Rolling.min()` 和 `Expanding.min()` 在使用 `engine="numba"` 时的性能改进([GH 43612](https://github.com/pandas-dev/pandas/issues/43612),[GH 44176](https://github.com/pandas-dev/pandas/issues/44176),[GH 45170](https://github.com/pandas-dev/pandas/issues/45170))

+   `pandas.read_csv()` 在文件编码为 UTF-8 时,使用 `memory_map=True` 可以提高性能([GH 43787](https://github.com/pandas-dev/pandas/issues/43787))

+   `RangeIndex.sort_values()` 的性能改进,覆盖了 `Index.sort_values()`([GH 43666](https://github.com/pandas-dev/pandas/issues/43666))

+   `RangeIndex.insert()` 的性能改进([GH 43988](https://github.com/pandas-dev/pandas/issues/43988))

+   `Index.insert()` 的性能改进([GH 43953](https://github.com/pandas-dev/pandas/issues/43953))

+   `DatetimeIndex.tolist()` 的性能改进([GH 43823](https://github.com/pandas-dev/pandas/issues/43823))

+   `DatetimeIndex.union()` 的性能改进([GH 42353](https://github.com/pandas-dev/pandas/issues/42353))

+   `Series.nsmallest()` 的性能改进([GH 43696](https://github.com/pandas-dev/pandas/issues/43696))

+   在`DataFrame.insert()`中提高了性能([GH 42998](https://github.com/pandas-dev/pandas/issues/42998))

+   在`DataFrame.dropna()`中提高了性能([GH 43683](https://github.com/pandas-dev/pandas/issues/43683))

+   在`DataFrame.fillna()`中提高了性能([GH 43316](https://github.com/pandas-dev/pandas/issues/43316))

+   在`DataFrame.values()`中提高了性能([GH 43160](https://github.com/pandas-dev/pandas/issues/43160))

+   在`DataFrame.select_dtypes()`中提高了性能([GH 42611](https://github.com/pandas-dev/pandas/issues/42611))

+   在`DataFrame`的减少中提高了性能([GH 43185](https://github.com/pandas-dev/pandas/issues/43185), [GH 43243](https://github.com/pandas-dev/pandas/issues/43243), [GH 43311](https://github.com/pandas-dev/pandas/issues/43311), [GH 43609](https://github.com/pandas-dev/pandas/issues/43609))

+   在`Series.unstack()`和`DataFrame.unstack()`中提高了性能([GH 43335](https://github.com/pandas-dev/pandas/issues/43335), [GH 43352](https://github.com/pandas-dev/pandas/issues/43352), [GH 42704](https://github.com/pandas-dev/pandas/issues/42704), [GH 43025](https://github.com/pandas-dev/pandas/issues/43025))

+   在`Series.to_frame()`中提高了性能([GH 43558](https://github.com/pandas-dev/pandas/issues/43558))

+   在`Series.mad()`中提高了性能([GH 43010](https://github.com/pandas-dev/pandas/issues/43010))

+   在`merge()`中提高了性能([GH 43332](https://github.com/pandas-dev/pandas/issues/43332))

+   在`to_csv()`中提高了性能,当索引列是日期时间并且已格式化时([GH 39413](https://github.com/pandas-dev/pandas/issues/39413))

+   在`to_csv()`中提高了性能,当`MultiIndex`包含许多未使用的级别时([GH 37484](https://github.com/pandas-dev/pandas/issues/37484))

+   在设置`index_col`为数字列时,改进了`read_csv()`的性能([GH 44158](https://github.com/pandas-dev/pandas/issues/44158))

+   改进了`concat()`的性能([GH 43354](https://github.com/pandas-dev/pandas/issues/43354))

+   改进了`SparseArray.__getitem__()`的性能([GH 23122](https://github.com/pandas-dev/pandas/issues/23122))

+   构建`DataFrame`从类似数组的对象(如`Pytorch`张量)的性能改进([GH 44616](https://github.com/pandas-dev/pandas/issues/44616))  ## Bug 修复

### 分类

+   将与 dtype 不兼容的值设置到`Categorical`(或由`Categorical`支持的`Series`或`DataFrame`)中存在 bug,抛出`ValueError`而不是`TypeError`([GH 41919](https://github.com/pandas-dev/pandas/issues/41919))

+   在传递与 dtype 不兼容的值时,`Categorical.searchsorted()`存在 bug,抛出`KeyError`而不是`TypeError`([GH 41919](https://github.com/pandas-dev/pandas/issues/41919))

+   在`Categorical.astype()`中存在 bug,将日期时间和`Timestamp`强制转换为 dtype 为`object`的整数([GH 44930](https://github.com/pandas-dev/pandas/issues/44930))

+   在传递与 dtype 不兼容的值时,`Series.where()`与`CategoricalDtype`存在 bug,抛出`ValueError`而不是`TypeError`([GH 41919](https://github.com/pandas-dev/pandas/issues/41919))

+   在传递与 dtype 不兼容的值时,`Categorical.fillna()`存在 bug,抛出`ValueError`而不是`TypeError`([GH 41919](https://github.com/pandas-dev/pandas/issues/41919))

+   在使用类似元组的类别进行`Categorical.fillna()`时,如果用非类别元组进行填充,则会抛出`ValueError`而不是`TypeError`([GH 41919](https://github.com/pandas-dev/pandas/issues/41919))

### 日期时间型

+   `DataFrame`构造函数中存在 bug,不必要地复制非日期时间型二维对象数组([GH 39272](https://github.com/pandas-dev/pandas/issues/39272))

+   在`to_datetime()`中存在 bug,当`format`和`pandas.NA`时抛出`ValueError`([GH 42957](https://github.com/pandas-dev/pandas/issues/42957))

+   `to_datetime()`如果无法遵守给定的`dayfirst`选项,将默默交换`MM/DD/YYYY`和`DD/MM/YYYY`格式 - 现在,在分隔日期字符串(例如`31-12-2012`)的情况下,会发出警告([GH 12585](https://github.com/pandas-dev/pandas/issues/12585))

+   在`start`=`end`且一侧关闭时,`date_range()`和`bdate_range()`未返回正确的右边界([GH 43394](https://github.com/pandas-dev/pandas/issues/43394))

+   在就地添加和减法操作`DatetimeIndex`或`TimedeltaIndex`与`DatetimeArray`或`TimedeltaArray`时出现错误([GH 43904](https://github.com/pandas-dev/pandas/issues/43904))

+   在时区感知的`DatetimeIndex`上调用`np.isnan`、`np.isfinite`或`np.isinf`时出现错误,错误地引发`TypeError`([GH 43917](https://github.com/pandas-dev/pandas/issues/43917))

+   使用混合时区的日期时间字符串构造`Series`时出现错误,错误地部分推断日期时间值([GH 40111](https://github.com/pandas-dev/pandas/issues/40111))

+   将`Tick`对象和`np.timedelta64`对象相加时出现错误,而不是返回`Timedelta`([GH 44474](https://github.com/pandas-dev/pandas/issues/44474))

+   当在具有`datetime64[ns]`或`timedelta64[ns]`dtype 的`Series`、`DataFrame`或`Index`上操作时,`np.maximum.reduce`和`np.minimum.reduce`现在正确返回`Timestamp`和`Timedelta`对象([GH 43923](https://github.com/pandas-dev/pandas/issues/43923))

+   将`np.timedelta64`对象添加到`BusinessDay`或`CustomBusinessDay`对象时出现错误([GH 44532](https://github.com/pandas-dev/pandas/issues/44532))

+   在将`np.datetime64`、`np.timedelta64`或`tuple`插入具有`dtype='object'`的`Index`时,使用`Index.insert()`出现错误,负 loc 添加`None`并替换现有值([GH 44509](https://github.com/pandas-dev/pandas/issues/44509))

+   在调用`Timestamp.to_pydatetime()`时未能保留`fold`属性([GH 45087](https://github.com/pandas-dev/pandas/issues/45087))

+   在使用 `DatetimeTZDtype` 进行 `Series.mode()` 时,错误地返回时区非感知值,并且在使用 `PeriodDtype` 时错误地引发错误 ([GH 41927](https://github.com/pandas-dev/pandas/issues/41927))

+   修复了 `reindex()` 中的回归错误,在使用与 datetime 类似的数据类型不兼容的填充值时引发错误(或者在使用 `datetime.date` 作为填充值时没有引发弃用警告) ([GH 42921](https://github.com/pandas-dev/pandas/issues/42921))

+   在使用 `Timestamp` 进行 `DateOffset` 添加时,修复了 `offset.nanoseconds` 不包含在结果中的错误 ([GH 43968](https://github.com/pandas-dev/pandas/issues/43968),[GH 36589](https://github.com/pandas-dev/pandas/issues/36589))

+   修复了 `Timestamp.fromtimestamp()` 中不支持 `tz` 参数的错误 ([GH 45083](https://github.com/pandas-dev/pandas/issues/45083))

+   修复了从具有不匹配索引数据类型的 `Series` 字典构造 `DataFrame` 时的错误,有时会根据传递的字典的顺序引发错误 ([GH 44091](https://github.com/pandas-dev/pandas/issues/44091))

+   修复了`Timestamp`在某些夏令时转换期间哈希时的错误,导致分段错误 ([GH 33931](https://github.com/pandas-dev/pandas/issues/33931) 和 [GH 40817](https://github.com/pandas-dev/pandas/issues/40817))

### 时间增量

+   所有全 `NaT` `TimeDeltaIndex`,`Series` 或 `DataFrame` 列的除法错误,在处理对象数据类型的数字数组时无法推断结果为 timedelta64 类型 ([GH 39750](https://github.com/pandas-dev/pandas/issues/39750))

+   修复了对 `timedelta64[ns]` 数据进行标量除法时返回垃圾值的错误 ([GH 44466](https://github.com/pandas-dev/pandas/issues/44466))

+   修复了`Timedelta`中的一个错误,现在正确考虑了任何关键字参数的任何纳秒贡献([GH 43764](https://github.com/pandas-dev/pandas/issues/43764),[GH 45227](https://github.com/pandas-dev/pandas/issues/45227))

### 时区

+   在使用 `infer_datetime_format=True` 时,修复了 `to_datetime()` 无法正确解析零 UTC 偏移 (`Z`) 的错误 ([GH 41047](https://github.com/pandas-dev/pandas/issues/41047))

+   在 `Series.dt.tz_convert()` 中存在的错误,会在具有 `CategoricalIndex` 的 `Series` 中重置索引([GH 43080](https://github.com/pandas-dev/pandas/issues/43080))

+   在减去两个时区不匹配的对象时,`Timestamp` 和 `DatetimeIndex` 错误地引发 `TypeError`([GH 31793](https://github.com/pandas-dev/pandas/issues/31793))

### 数字

+   在将整数列表或元组除以 `Series` 时存在的地板除法错误([GH 44674](https://github.com/pandas-dev/pandas/issues/44674))

+   在 `DataFrame.rank()` 中存在的错误,在具有 `object` 列和 `method="first"` 时会引发 `ValueError`([GH 41931](https://github.com/pandas-dev/pandas/issues/41931))

+   在 `DataFrame.rank()` 中存在的错误,将缺失值和极端值视为相等(例如 `np.nan` 和 `np.inf`),在使用 `na_option="bottom"` 或 `na_option="top` 时会导致不正确的结果([GH 41931](https://github.com/pandas-dev/pandas/issues/41931))

+   在选项 `compute.use_numexpr` 设置为 `False` 时,仍然使用 `numexpr` 引擎存在的错误([GH 32556](https://github.com/pandas-dev/pandas/issues/32556))

+   在具有 `_constructor()` 属性为除子类本身以外的可调用对象的子类中,`DataFrame` 算术操作中存在的错误([GH 43201](https://github.com/pandas-dev/pandas/issues/43201))

+   在涉及 `RangeIndex` 的算术操作中存在的错误,结果会具有不正确的 `name`([GH 43962](https://github.com/pandas-dev/pandas/issues/43962))

+   在涉及 `Series` 的算术操作中存在的错误,当操作数具有匹配的 NA 或匹配的元组名称时,结果可能会具有不正确的 `name`([GH 44459](https://github.com/pandas-dev/pandas/issues/44459))

+   在使用 `IntegerDtype` 或 `BooleanDtype` 数组和 NA 标量进行除法时存在的错误,会错误地引发([GH 44685](https://github.com/pandas-dev/pandas/issues/44685))

+   在将带有 `FloatingDtype` 的 `Series` 与时间间隔标量相乘时存在的错误引发([GH 44772](https://github.com/pandas-dev/pandas/issues/44772))

### 转换

+   在传递包含既可转换为 int64 又过大无法保持在 int64 中的正整数的列表时,`UInt64Index` 构造函数中的错误([GH 42201](https://github.com/pandas-dev/pandas/issues/42201))

+   在缺失值 dtype 为 `int64` 时,`Series` 构造函数返回 0,dtype 为 `bool` 时返回 `False` 的错误([GH 43017](https://github.com/pandas-dev/pandas/issues/43017),[GH 43018](https://github.com/pandas-dev/pandas/issues/43018))

+   从包含 `Series` 对象的 `PandasArray` 构造 `DataFrame` 时的错误与等效的 `np.ndarray` 行为不同([GH 43986](https://github.com/pandas-dev/pandas/issues/43986))

+   `IntegerDtype` 中的错误不允许从字符串类型强制转换([GH 25472](https://github.com/pandas-dev/pandas/issues/25472))

+   在指定 `arg:xr.DataArray` 和 `unit="ns"` 的情况下,`to_datetime()` 函数引发 `TypeError` 错误([GH 44053](https://github.com/pandas-dev/pandas/issues/44053))

+   当子类未重载 `_constructor_sliced()` 时,`DataFrame.convert_dtypes()` 中的错误未返回正确的类型([GH 43201](https://github.com/pandas-dev/pandas/issues/43201))

+   `DataFrame.astype()` 中的错误未从原始 `DataFrame` 传播 `attrs`([GH 44414](https://github.com/pandas-dev/pandas/issues/44414))

+   `DataFrame.convert_dtypes()` 结果丢失 `columns.names` 的错误([GH 41435](https://github.com/pandas-dev/pandas/issues/41435))

+   从 pyarrow 数据构造 `IntegerArray` 时,未能验证 dtype 的错误([GH 44891](https://github.com/pandas-dev/pandas/issues/44891))

+   `Series.astype()` 中的错误不允许从 `PeriodDtype` 转换为 `datetime64` 类型,与 `PeriodIndex` 的行为不一致([GH 45038](https://github.com/pandas-dev/pandas/issues/45038))

### 字符串

+   在没有安装 pyarrow 时,检查 `string[pyarrow]` dtype 时错误地引发 `ImportError` 错误([GH 44276](https://github.com/pandas-dev/pandas/issues/44276))

### 区间

+   `Series.where()` 中存在的 bug,使用 `IntervalDtype` 时,错误地在 `where` 调用时引发了 `ValueError`,而应该不替换任何内容。 ([GH 44181](https://github.com/pandas-dev/pandas/issues/44181))

### 索引

+   在具有 `MultiIndex` 和提供了 `level` 的 `Series.rename()` 中的 bug。 ([GH 43659](https://github.com/pandas-dev/pandas/issues/43659))

+   在对象的 `Index` 长度大于一但只有一个唯一值时的 `DataFrame.truncate()` 和 `Series.truncate()` 中的 bug。 ([GH 42365](https://github.com/pandas-dev/pandas/issues/42365))

+   在具有 `MultiIndex` 的 `Series.loc()` 和 `DataFrame.loc()` 中索引时,使用包含一个级别也是元组的元组时出现的 bug。 ([GH 27591](https://github.com/pandas-dev/pandas/issues/27591))

+   在具有只包含 `np.nan` 值的 `MultiIndex` 的 `Series.loc()` 中的 bug。 ([GH 42055](https://github.com/pandas-dev/pandas/issues/42055))

+   在具有 `DatetimeIndex` 的 `Series` 或 `DataFrame` 上进行索引时的 bug,当传递字符串时,返回类型取决于索引是否单调。 ([GH 24892](https://github.com/pandas-dev/pandas/issues/24892))

+   在 `MultiIndex` 上进行索引时的 bug,在索引器是包含日期时间类字符串的元组时,未能删除标量级别。 ([GH 42476](https://github.com/pandas-dev/pandas/issues/42476))

+   在 `DataFrame.sort_values()` 和 `Series.sort_values()` 中传递升序值时,未能引发或错误地引发了 `ValueError`。 ([GH 41634](https://github.com/pandas-dev/pandas/issues/41634))

+   使用通过`DataFrame.pop()`创建的布尔索引更新`pandas.Series`的值时的 bug([GH 42530](https://github.com/pandas-dev/pandas/issues/42530))

+   当索引包含多个`np.nan`时,`Index.get_indexer_non_unique()`中的 bug([GH 35392](https://github.com/pandas-dev/pandas/issues/35392))

+   在`DataFrame.query()`中未处理度符号在反引号列名中的 bug,例如`Temp(°C)`,用于查询`DataFrame`的表达式中([GH 42826](https://github.com/pandas-dev/pandas/issues/42826))

+   在`DataFrame.drop()`中的 bug,当抛出`KeyError`时,错误消息中没有显示带有逗号的缺失标签([GH 42881](https://github.com/pandas-dev/pandas/issues/42881))

+   在查询字符串中调用方法时,在安装`numexpr`包时会导致错误的`DataFrame.query()`中的 bug([GH 22435](https://github.com/pandas-dev/pandas/issues/22435))

+   在`DataFrame.nlargest()`和`Series.nlargest()`中的 bug,排序结果未计算包含`np.nan`的索引([GH 28984](https://github.com/pandas-dev/pandas/issues/28984))

+   在非唯一对象类型(`Index`)上索引时遇到带有 NA 标量(例如`np.nan`)的 bug([GH 43711](https://github.com/pandas-dev/pandas/issues/43711))

+   当新的 dtype 和旧的 dtype 匹配时,`DataFrame.__setitem__()`中的 bug 会错误地写入现有列的数组,而不是在设置新数组([GH 43406](https://github.com/pandas-dev/pandas/issues/43406))

+   将浮点型值设置到整数类型(`Series`)中时失败设置`inplace`的 bug([GH 44316](https://github.com/pandas-dev/pandas/issues/44316))

+   当设置与大小和 dtype=’datetime64[ns]’或 dtype=’timedelta64[ns]’匹配的数组时,`Series.__setitem__()`中对象 dtype 的 bug 将错误地将 datetime/timedeltas 转换为整数([GH 43868](https://github.com/pandas-dev/pandas/issues/43868))

+   在 `DataFrame.sort_index()` 中存在的 bug,当 `ignore_index=True` 时,如果索引已经排序,则不会被尊重([GH 43591](https://github.com/pandas-dev/pandas/issues/43591))

+   在 `Index.get_indexer_non_unique()` 中存在的 bug,当索引包含多个 `np.datetime64("NaT")` 和 `np.timedelta64("NaT")` 时 ([GH 43869](https://github.com/pandas-dev/pandas/issues/43869))

+   在将标量 `Interval` 值设置到具有 `IntervalDtype` 的 `Series` 中时存在 bug,当标量的边界为浮点数而值的边界为整数时 ([GH 44201](https://github.com/pandas-dev/pandas/issues/44201))

+   在设置可以解析为日期时间的字符串支持的 `Categorical` 值到由 `DatetimeArray` 或 `Series` 或 `DataFrame` 列支持的 `DatetimeArray` 中时存在的 bug,无法解析这些字符串 ([GH 44236](https://github.com/pandas-dev/pandas/issues/44236))

+   在 `Series.__setitem__()` 中存在的 bug,除 `int64` 外的整数 dtype 设置为 `range` 对象时,不必要地向上转换为 `int64` ([GH 44261](https://github.com/pandas-dev/pandas/issues/44261))

+   在 `Series.__setitem__()` 中存在的 bug,使用布尔掩码索引器设置长度为 1 的列表值时,错误地广播该值 ([GH 44265](https://github.com/pandas-dev/pandas/issues/44265))

+   在 `Series.reset_index()` 中存在的 bug,当 `drop` 和 `inplace` 设置为 `True` 时不会忽略 `name` 参数 ([GH 44575](https://github.com/pandas-dev/pandas/issues/44575))

+   在 `DataFrame.loc.__setitem__()` 和 `DataFrame.iloc.__setitem__()` 中存在的 bug,有时无法就地操作混合 dtype ([GH 44345](https://github.com/pandas-dev/pandas/issues/44345))

+   在 `DataFrame.loc.__getitem__()` 中存在的 bug,当使用布尔键选择单个列时,错误地引发 `KeyError` ([GH 44322](https://github.com/pandas-dev/pandas/issues/44322)).

+   在设置带有单个 `ExtensionDtype` 列并设置 2D 值的 `DataFrame.iloc()` 中存在的 bug,例如 `df.iloc[:] = df.values` 错误地引发 ([GH 44514](https://github.com/pandas-dev/pandas/issues/44514))

+   使用单个 `ExtensionDtype` 列和数组元组作为索引器时,通过 `DataFrame.iloc()` 设置值存在 bug([GH 44703](https://github.com/pandas-dev/pandas/issues/44703))

+   在使用带有负步长的切片的 `loc` 或 `iloc` 对列进行索引时,如果列是 `ExtensionDtype`,则会错误地引发异常([GH 44551](https://github.com/pandas-dev/pandas/issues/44551))

+   当索引器完全为 `False` 时,`DataFrame.loc.__setitem__()` 中存在的 bug 会更改 dtype([GH 37550](https://github.com/pandas-dev/pandas/issues/37550))

+   `IntervalIndex.get_indexer_non_unique()` 中存在的 bug 返回布尔掩码而不是整数数组,对于非唯一且非单调的索引([GH 44084](https://github.com/pandas-dev/pandas/issues/44084))

+   `IntervalIndex.get_indexer_non_unique()` 中存在的 bug 在处理具有 NaN 的 `dtype` ‘object’ 的目标时不正确([GH 44482](https://github.com/pandas-dev/pandas/issues/44482))

+   修复了一个回归,即当将单列 `np.matrix` 添加到 `DataFrame` 中时,不再将其强制转换为 1d `np.ndarray`([GH 42376](https://github.com/pandas-dev/pandas/issues/42376))

+   在具有整数的 `CategoricalIndex` 的 `Series.__getitem__()` 中,将整数列表视为位置索引器存在 bug,与单个标量整数的行为不一致([GH 15470](https://github.com/pandas-dev/pandas/issues/15470),[GH 14865](https://github.com/pandas-dev/pandas/issues/14865))

+   在将浮点数或整数设置到整数类型的 `Series` 中时,`Series.__setitem__()` 存在 bug,无法在需要时进行适当的升级以保留精度([GH 45121](https://github.com/pandas-dev/pandas/issues/45121))

+   `DataFrame.iloc.__setitem__()` 中存在的 bug 忽略了轴参数([GH 45032](https://github.com/pandas-dev/pandas/issues/45032))

### Missing

+   `DataFrame.fillna()` 中存在的 bug 在没有 `method` 的情况下忽略了 `limit`,并且不会考虑 `axis='columns'` 或 `axis = 1`([GH 40989](https://github.com/pandas-dev/pandas/issues/40989),[GH 17399](https://github.com/pandas-dev/pandas/issues/17399))

+   在使用类似于字典的 `value` 和重复列名时,`DataFrame.fillna()` 中存在的 bug 不会替换缺失值([GH 43476](https://github.com/pandas-dev/pandas/issues/43476))

+   在构造一个 `DataFrame` 时,当字典中的值是 `np.datetime64`,且 `dtype='timedelta64[ns]'`,或反之,则会错误地进行转换而不是引发错误([GH 44428](https://github.com/pandas-dev/pandas/issues/44428))

+   在`Series.interpolate()`和`DataFrame.interpolate()`中的错误,`inplace=True`时未就地写入基础数组([GH 44749](https://github.com/pandas-dev/pandas/issues/44749))

+   在`Index.fillna()`中的错误,当存在 NA 值并且指定了`downcast`参数时,错误地返回未填充的`Index`。现在会引发`NotImplementedError`;不要传递`downcast`参数([GH 44873](https://github.com/pandas-dev/pandas/issues/44873))

+   在`DataFrame.dropna()`中的错误,即使没有删除任何条目,也会更改`Index`([GH 41965](https://github.com/pandas-dev/pandas/issues/41965))

+   在`Series.fillna()`中的错误,使用对象 dtype 时错误地忽略`downcast="infer"`([GH 44241](https://github.com/pandas-dev/pandas/issues/44241))

### 多级索引

+   在`MultiIndex.get_loc()`中的错误,其中第一级是`DatetimeIndex`,并且传递了一个字符串键([GH 42465](https://github.com/pandas-dev/pandas/issues/42465))

+   在`MultiIndex.reindex()`中的错误,当传递与`ExtensionDtype`级别对应的`level`时([GH 42043](https://github.com/pandas-dev/pandas/issues/42043))

+   在`MultiIndex.get_loc()`中的错误,对嵌套元组引发`TypeError`而不是`KeyError`([GH 42440](https://github.com/pandas-dev/pandas/issues/42440))

+   在`MultiIndex.union()`中的错误,设置错误的`sortorder`导致使用切片进行后续索引操作时出错([GH 44752](https://github.com/pandas-dev/pandas/issues/44752))

+   在`MultiIndex.putmask()`中的错误,其中另一个值也是`MultiIndex`([GH 43212](https://github.com/pandas-dev/pandas/issues/43212))

+   在`MultiIndex.dtypes()`中的错误,重复级别名称仅返回一个名称对应的 dtype([GH 45174](https://github.com/pandas-dev/pandas/issues/45174))

### 输入/输出

+   试图从.xlsx 文件中读取图表工作表的`read_excel()`中的错误([GH 41448](https://github.com/pandas-dev/pandas/issues/41448))

+   当`record_path`长度大于 1 时,`json_normalize()`中的`errors=ignore`可能无法忽略`meta`的缺失值时的错误([GH 41876](https://github.com/pandas-dev/pandas/issues/41876))

+   具有多个标题输入并且参数引用列名为元组时,`read_csv()`中的错误([GH 42446](https://github.com/pandas-dev/pandas/issues/42446))

+   在`read_fwf()`中,`colspecs`和`names`长度不同时,未引发`ValueError`的错误([GH 40830](https://github.com/pandas-dev/pandas/issues/40830))

+   将纯 Python 对象序列化为 JSON 时,`Series.to_json()`和`DataFrame.to_json()`中跳过了某些属性的错误([GH 42768](https://github.com/pandas-dev/pandas/issues/42768), [GH 33043](https://github.com/pandas-dev/pandas/issues/33043))

+   从 sqlalchemy 的`Row`对象构造`DataFrame`时丢弃了列标题([GH 40682](https://github.com/pandas-dev/pandas/issues/40682))

+   未正确推断具有对象 dtype 的`Index`在反序列化时的错误([GH 43188](https://github.com/pandas-dev/pandas/issues/43188))

+   使用不等长度的多标题输入时,`read_csv()`中的错误不正确地引发了`IndexError`([GH 43102](https://github.com/pandas-dev/pandas/issues/43102))

+   在以块方式读取文件并且一些块的列少于`engine="c"`时,`read_csv()`中引发`ParserError`的错误([GH 21211](https://github.com/pandas-dev/pandas/issues/21211))

+   在期望文件路径名或文件类对象时,`read_csv()`中的异常类已从`OSError`更改为`TypeError`([GH 43366](https://github.com/pandas-dev/pandas/issues/43366))

+   在为`engine='python'`指定`nrows`时,`read_csv()`和`read_fwf()`未能忽略除第一行外的所有`skiprows`的 Bug([GH 44021](https://github.com/pandas-dev/pandas/issues/44021),[GH 10261](https://github.com/pandas-dev/pandas/issues/10261))。

+   在设置`keep_date_col=True`时,`read_csv()`保留原始列的对象格式的 Bug([GH 13378](https://github.com/pandas-dev/pandas/issues/13378))。

+   在未正确处理非 numpy 数据类型(特别是`category`)时的`read_json()` Bug([GH 21892](https://github.com/pandas-dev/pandas/issues/21892),[GH 33205](https://github.com/pandas-dev/pandas/issues/33205))。

+   在多字符`sep`参数错误地前缀到每个键上的`json_normalize()` Bug([GH 43831](https://github.com/pandas-dev/pandas/issues/43831))。

+   在读取带有缺失多级元数据的数据时,`json_normalize()`未能尊重`errors="ignore"`的 Bug([GH 44312](https://github.com/pandas-dev/pandas/issues/44312))。

+   当将`header`设置为`None`并且`engine="python"`时,`read_csv()`使用第二行来猜测隐式索引的 Bug([GH 22144](https://github.com/pandas-dev/pandas/issues/22144))。

+   在使用`engine="c"`时,`read_csv()`未能识别带有`names`的坏行的 Bug([GH 22144](https://github.com/pandas-dev/pandas/issues/22144))。

+   在使用`float_precision="round_trip"`时,`read_csv()`未能跳过初始/尾随空白的 Bug([GH 43713](https://github.com/pandas-dev/pandas/issues/43713))。

+   当 Python 构建时没有 lzma 模块时,即使不使用 lzma 功能,也会在 pandas 导入时引发警告的 Bug([GH 43495](https://github.com/pandas-dev/pandas/issues/43495))。

+   在`index_col`中未应用 dtype 的 Bug([GH 9435](https://github.com/pandas-dev/pandas/issues/9435))。

+   在使用`yaml.dump(frame)`时,对`DataFrame`进行转储/加载时的 Bug([GH 42748](https://github.com/pandas-dev/pandas/issues/42748))。

+   `read_csv()` 中的 Bug,当 `names` 长度大于 `header` 但等于数据行数时,使用 `engine="python"` 时引发 `ValueError`([GH 38453](https://github.com/pandas-dev/pandas/issues/38453))

+   `ExcelWriter` 中的 Bug,未将 `engine_kwargs` 传递给所有引擎([GH 43442](https://github.com/pandas-dev/pandas/issues/43442))

+   `read_csv()` 中的 Bug,当与 `MultiIndex` 列一起使用 `parse_dates` 时引发 `ValueError`([GH 8991](https://github.com/pandas-dev/pandas/issues/8991))

+   `read_csv()` 中的 Bug,在指定 `\n` 作为 `delimiter` 或 `sep` 时未引发 `ValueError`,与 `lineterminator` 冲突([GH 43528](https://github.com/pandas-dev/pandas/issues/43528))

+   `to_csv()` 中的 Bug,在分类 `Series` 中转换日期时间为整数([GH 40754](https://github.com/pandas-dev/pandas/issues/40754))

+   `read_csv()` 中的 Bug,在日期解析失败后将列转换为数值类型([GH 11019](https://github.com/pandas-dev/pandas/issues/11019))

+   `read_csv()` 中的 Bug,在尝试日期转换之前未用 `np.nan` 替换 `NaN` 值([GH 26203](https://github.com/pandas-dev/pandas/issues/26203))

+   `read_csv()` 中的 Bug,尝试从可为空整数类型推断索引列 dtype 时引发 `AttributeError`([GH 44079](https://github.com/pandas-dev/pandas/issues/44079))

+   `to_csv()` 中的 Bug,总是将具有不同格式的日期时间列强制转换为相同格式([GH 21734](https://github.com/pandas-dev/pandas/issues/21734))

+   `DataFrame.to_csv()` 和 `Series.to_csv()` 中,当 `compression` 设为 `'zip'` 时不再创建以 “.zip” 结尾的 zip 文件。相反,它们会更智能地推断内部文件名([GH 39465](https://github.com/pandas-dev/pandas/issues/39465))

+   `read_csv()` 中的 Bug,将布尔值和缺失值的混合列读取为浮点类型时,缺失值变为 1.0 而不是 NaN([GH 42808](https://github.com/pandas-dev/pandas/issues/42808), [GH 34120](https://github.com/pandas-dev/pandas/issues/34120))

+   对于具有扩展数组数据类型的 `pd.NA`,`to_xml()` 引发错误的错误([GH 43903](https://github.com/pandas-dev/pandas/issues/43903))

+   同时在 `date_parser` 和 `parse_dates=False` 中传递解析器时,仍会调用解析的 `read_csv()` 的错误([GH 44366](https://github.com/pandas-dev/pandas/issues/44366))

+   当 `index_col` 不是第一列时,`read_csv()` 未正确设置 `MultiIndex` 列的名称的错误([GH 38549](https://github.com/pandas-dev/pandas/issues/38549)")

+   当无法创建内存映射文件时,`read_csv()` 静默忽略错误的错误([GH 44766](https://github.com/pandas-dev/pandas/issues/44766))

+   在以二进制模式打开的 `tempfile.SpooledTemporaryFile` 中传递给 `read_csv()` 时的错误([GH 44748](https://github.com/pandas-dev/pandas/issues/44748))

+   在尝试解析包含“://”的 json 字符串时,`read_json()` 引发 `ValueError` 的错误([GH 36271](https://github.com/pandas-dev/pandas/issues/36271))

+   在 `engine="c"` 且 `encoding_errors=None` 的情况下,`read_csv()` 引发段错误的错误([GH 45180](https://github.com/pandas-dev/pandas/issues/45180))

+   当 `usecols` 的值无效时,`read_csv()` 引导一个未关闭的文件句柄的错误([GH 45384](https://github.com/pandas-dev/pandas/issues/45384))

+   修复 `DataFrame.to_json()` 中的内存泄漏问题([GH 43877](https://github.com/pandas-dev/pandas/issues/43877))

### Period

+   将 `Period` 对象添加到 `np.timedelta64` 对象中时出现错误,错误地引发 `TypeError`([GH 44182](https://github.com/pandas-dev/pandas/issues/44182))

+   当索引具有 `freq="B"` 时,`PeriodIndex.to_timestamp()` 推断其结果的 `freq="B"` 而不是 `freq="D"` 的错误([GH 44105](https://github.com/pandas-dev/pandas/issues/44105))

+   `Period` 构造函数中的错误,不正确地允许 `np.timedelta64("NaT")`([GH 44507](https://github.com/pandas-dev/pandas/issues/44507))

+   `PeriodIndex.to_timestamp()` 存在的错误,对具有非连续数据的索引提供了错误的值 ([GH 44100](https://github.com/pandas-dev/pandas/issues/44100))

+   `Series.where()` 存在的错误,使用 `PeriodDtype` 时,`where` 调用在不应该替换任何内容时错误地引发异常 ([GH 45135](https://github.com/pandas-dev/pandas/issues/45135))

### 绘图

+   当给定非数字数据时,`DataFrame.boxplot()` 现在会引发 `ValueError` 而不是难以理解的 `KeyError` 或 `ZeroDivisionError`,与其他绘图函数(如 `DataFrame.hist()`)保持一致 ([GH 43480](https://github.com/pandas-dev/pandas/issues/43480))

### Groupby/resample/rolling

+   `SeriesGroupBy.apply()` 存在的错误,在底层 `Series` 为空时传递未识别的字符串参数未能引发 `TypeError` ([GH 42021](https://github.com/pandas-dev/pandas/issues/42021))

+   `Series.rolling.apply()`、`DataFrame.rolling.apply()`、`Series.expanding.apply()` 和 `DataFrame.expanding.apply()` 中存在的错误,当 `engine="numba"` 时,`*args` 会被缓存与用户传递的函数 ([GH 42287](https://github.com/pandas-dev/pandas/issues/42287))

+   `DataFrameGroupBy.max()`、`SeriesGroupBy.max()`、`DataFrameGroupBy.min()` 和 `SeriesGroupBy.min()` 中存在的错误,具有可为空的整数 dtype 会丢失精度 ([GH 41743](https://github.com/pandas-dev/pandas/issues/41743))

+   `DataFrame.groupby.rolling.var()` 存在的错误,只会在第一组上计算滚动方差 ([GH 42442](https://github.com/pandas-dev/pandas/issues/42442))

+   `DataFrameGroupBy.shift()` 和 `SeriesGroupBy.shift()` 存在的错误,如果 `fill_value` 不是 `None`,会返回分组列 ([GH 41556](https://github.com/pandas-dev/pandas/issues/41556))

+   在输入 `Series` 已排序且 `n` 大于或等于所有组大小时,`SeriesGroupBy.nlargest()` 和 `SeriesGroupBy.nsmallest()` 存在的 Bug 会导致索引不一致 ([GH 15272](https://github.com/pandas-dev/pandas/issues/15272), [GH 16345](https://github.com/pandas-dev/pandas/issues/16345), [GH 29129](https://github.com/pandas-dev/pandas/issues/29129))

+   在 `pandas.DataFrame.ewm()` 中存在的 Bug,非 `float64` dtypes 会静默失败 ([GH 42452](https://github.com/pandas-dev/pandas/issues/42452))

+   在沿行(`axis=1`)进行 `pandas.DataFrame.rolling()` 操作时,错误地省略了包含 `float16` 和 `float32` 的列 ([GH 41779](https://github.com/pandas-dev/pandas/issues/41779))

+   在 `Resampler.aggregate()` 中存在的 Bug 不允许使用命名聚合 ([GH 32803](https://github.com/pandas-dev/pandas/issues/32803))

+   当 `Series` 的 `dtype` 为 `Int64` 时,`Series.rolling()` 存在的 Bug ([GH 43016](https://github.com/pandas-dev/pandas/issues/43016))

+   当 `DataFrame` 列为 `MultiIndex` 时,`DataFrame.rolling.corr()` 中存在的 Bug ([GH 21157](https://github.com/pandas-dev/pandas/issues/21157))

+   在指定 `on` 并调用 `__getitem__` 时,`DataFrame.groupby.rolling()` 存在的 Bug 会随后返回不正确的结果 ([GH 43355](https://github.com/pandas-dev/pandas/issues/43355))

+   在使用基于时间的 `Grouper` 对象的 `DataFrameGroupBy.apply()` 和 `SeriesGroupBy.apply()` 时存在的 Bug,在分组向量包含 `NaT` 的极端情况下会错误地引发 `ValueError` ([GH 43500](https://github.com/pandas-dev/pandas/issues/43500), [GH 43515](https://github.com/pandas-dev/pandas/issues/43515))

+   `DataFrameGroupBy.mean()` 和 `SeriesGroupBy.mean()` 中的 Bug 在 `complex` dtype 上失败 ([GH 43701](https://github.com/pandas-dev/pandas/issues/43701))

+   `Series.rolling()` 和 `DataFrame.rolling()` 中的 Bug 在 `center=True` 且索引递减时未正确计算第一行的窗口边界 ([GH 43927](https://github.com/pandas-dev/pandas/issues/43927))

+   `Series.rolling()` 和 `DataFrame.rolling()` 中的 Bug 在不均匀纳秒的居中日期时间窗口上失败 ([GH 43997](https://github.com/pandas-dev/pandas/issues/43997))

+   `DataFrameGroupBy.mean()` 和 `SeriesGroupBy.mean()` 中的 Bug 在至少选择两次列时引发 `KeyError` ([GH 44924](https://github.com/pandas-dev/pandas/issues/44924))

+   `DataFrameGroupBy.nth()` 和 `SeriesGroupBy.nth()` 中的 Bug 在 `axis=1` 上失败 ([GH 43926](https://github.com/pandas-dev/pandas/issues/43926))

+   `Series.rolling()` 和 `DataFrame.rolling()` 中的 Bug 在处理带有重复索引的居中日期时间窗口时未尊重右边界,导致问题 ([GH 3944](https://github.com/pandas-dev/pandas/issues/3944))

+   在使用`pandas.api.indexers.BaseIndexer`子类并返回不相等的起始和结束数组时,`Series.rolling()` 和 `DataFrame.rolling()` 中的 bug 会导致段错误而不是引发`ValueError`错误 ([GH 44470](https://github.com/pandas-dev/pandas/issues/44470))。

+   在`categorical`分组列中,`Groupby.nunique()`的 bug 未能遵守`observed=True` ([GH 45128](https://github.com/pandas-dev/pandas/issues/45128))。

+   当`dropna=True`时,`DataFrameGroupBy.head()`、`SeriesGroupBy.head()`、`DataFrameGroupBy.tail()` 和 `SeriesGroupBy.tail()` 中的 bug 会导致不会删除含有`NaN`的分组 ([GH 45089](https://github.com/pandas-dev/pandas/issues/45089))。

+   在`GroupBy`对象中选择列子集后,在`GroupBy.__iter__()`中的 bug 会导致返回所有列而不是所选择的子集 ([GH 44821](https://github.com/pandas-dev/pandas/issues/44821))。

+   当传递非单调数据时,`Groupby.rolling()`中的 bug 未能正确引发`ValueError`错误 ([GH 43909](https://github.com/pandas-dev/pandas/issues/43909))。

+   当对长度与分组轴不相等的具有`categorical`数据类型的`Series`进行分组时,会引发`ValueError`错误([GH 44179](https://github.com/pandas-dev/pandas/issues/44179))。

### 重塑

+   当从多维[`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v1.26)")创建`DataFrame`列时,提升了错误信息的清晰度([GH 42463](https://github.com/pandas-dev/pandas/issues/42463))。

+   `concat()`中的错误,在连接具有`Index`中的重复项��多个键的`DataFrame`时创建具有重复级别条目的`MultiIndex`([GH 42651](https://github.com/pandas-dev/pandas/issues/42651))

+   `pandas.cut()`中的错误在具有重复索引和非精确`pandas.CategoricalIndex()`的`Series`上([GH 42185](https://github.com/pandas-dev/pandas/issues/42185), [GH 42425](https://github.com/pandas-dev/pandas/issues/42425))

+   `DataFrame.append()`中的错误,在附加的列不匹配时未能保留 dtypes([GH 43392](https://github.com/pandas-dev/pandas/issues/43392))

+   `concat()`中的错误导致`bool`和`boolean` dtypes 的结果为`object` dtype 而不是`boolean` dtype([GH 42800](https://github.com/pandas-dev/pandas/issues/42800))

+   `crosstab()`中的错误,当输入为分类`Series`时,其中一个或两个`Series`中不存在的类别,且`margins=True`。以前缺失类别的边际值为`NaN`。现在正确报告为 0([GH 43505](https://github.com/pandas-dev/pandas/issues/43505))

+   `concat()`中的错误会在`objs`参数都具有相同索引且`keys`参数包含重复项时失败([GH 43595](https://github.com/pandas-dev/pandas/issues/43595))

+   `concat()`中的错误忽略了`sort`参数([GH 43375](https://github.com/pandas-dev/pandas/issues/43375))

+   `merge()`中的错误,使用`MultiIndex`作为`on`参数的列索引时,在内部分配列时返回错误([GH 43734](https://github.com/pandas-dev/pandas/issues/43734))

+   `crosstab()`中的错误会在输入为列表或元组时失败([GH 44076](https://github.com/pandas-dev/pandas/issues/44076))

+   `DataFrame.append()` 中的 bug,在附加 `Series` 对象列表时未能保留 `index.name`([GH 44109](https://github.com/pandas-dev/pandas/issues/44109))

+   `Dataframe.apply()` 方法中修复了元数据传播,因此也修复了 `Dataframe.transform()`、`Dataframe.nunique()` 和 `Dataframe.mode()` 中的相同问题([GH 28283](https://github.com/pandas-dev/pandas/issues/28283))

+   `concat()` 中的 bug,如果所有级别只包含缺失值,则将 `MultiIndex` 的级别转换为浮点数([GH 44900](https://github.com/pandas-dev/pandas/issues/44900))

+   `DataFrame.stack()` 中的 bug,在 `ExtensionDtype` 列中错误地引发异常([GH 43561](https://github.com/pandas-dev/pandas/issues/43561))

+   `merge()` 中的 bug,在使用 on 关键字连接具有不同命名索引时引发 `KeyError`([GH 45094](https://github.com/pandas-dev/pandas/issues/45094))

+   `Series.unstack()` 在对象上的 bug,在结果列上执行不需要的类型推断([GH 44595](https://github.com/pandas-dev/pandas/issues/44595))

+   `MultiIndex.join()` 中的 bug,在重叠的 `IntervalIndex` 级别上([GH 44096](https://github.com/pandas-dev/pandas/issues/44096))

+   `DataFrame.replace()` 和 `Series.replace()` 的 bug 在基于 `regex` 参数的情况下导致不同的 `dtype` 结果([GH 44864](https://github.com/pandas-dev/pandas/issues/44864))

+   `DataFrame.pivot()` 中的 bug,在 `index=None` 时,`DataFrame` 索引是 `MultiIndex` 时([GH 23955](https://github.com/pandas-dev/pandas/issues/23955))

### Sparse

+   `DataFrame.sparse.to_coo()` 的 bug,在列名不唯一时引发 `AttributeError`([GH 29564](https://github.com/pandas-dev/pandas/issues/29564))

+   `SparseArray.max()` 和 `SparseArray.min()` 的 bug,对于具有 0 个非空元素的数组引发 `ValueError`([GH 43527](https://github.com/pandas-dev/pandas/issues/43527))

+   在`DataFrame.sparse.to_coo()`中存在错误,将非零填充值静默转换为零([GH 24817](https://github.com/pandas-dev/pandas/issues/24817))

+   使用不匹配长度的数组式操作数的`SparseArray`比较方法中存在错误,可能会引发`AssertionError`或不明确的`ValueError`,具体取决于输入([GH 43863](https://github.com/pandas-dev/pandas/issues/43863))

+   当除以零时,`SparseArray`算术方法`floordiv`和`mod`的行为与非稀疏的`Series`行为不匹配([GH 38172](https://github.com/pandas-dev/pandas/issues/38172))

+   `SparseArray`的一元方法以及`SparseArray.isna()`存在错误,不会重新计算索引([GH 44955](https://github.com/pandas-dev/pandas/issues/44955))

### ExtensionArray

+   `array()`存在错误,无法保留`PandasArray`([GH 43887](https://github.com/pandas-dev/pandas/issues/43887))

+   当调用具有`__abs__, __pos__, __neg__`的 ExtensionArrays 上的 NumPy ufuncs `np.abs`, `np.positive`, `np.negative`时,现在会正确保留 dtype。特别是对于`TimedeltaArray`,这已得到修复([GH 43899](https://github.com/pandas-dev/pandas/issues/43899),[GH 23316](https://github.com/pandas-dev/pandas/issues/23316))

+   NumPy ufuncs `np.minimum.reduce` `np.maximum.reduce`, `np.add.reduce`和`np.prod.reduce`现在可以在具有`IntegerDtype`或`FloatDtype`的`Series`上正常工作,而不是引发`NotImplementedError`([GH 43923](https://github.com/pandas-dev/pandas/issues/43923),[GH 44793](https://github.com/pandas-dev/pandas/issues/44793))

+   现在通过具有`IntegerDtype`和`FloatingDtype`的数组支持带有`out`关键字的 NumPy ufuncs([GH 45122](https://github.com/pandas-dev/pandas/issues/45122))

+   避免在使用具有扩展数据类型的许多列时引发关于碎片化`DataFrame`的`PerformanceWarning`([GH 44098](https://github.com/pandas-dev/pandas/issues/44098))

+   `IntegerArray`和`FloatingArray`构造中的错误,将不匹配的 NA 值(例如`np.timedelta64("NaT")`)错误地强制转换为数字 NA([GH 44514](https://github.com/pandas-dev/pandas/issues/44514))

+   在与不兼容类型(如字符串)比较时,`BooleanArray.__eq__()`和`BooleanArray.__ne__()`存在错误,会引发`TypeError`。如果包括可空布尔列,则此错误有时会导致`DataFrame.replace()`引发`TypeError`([GH 44499](https://github.com/pandas-dev/pandas/issues/44499))

+   在`array()`中的错误,当传递带有`float16` dtype 的`ndarray`时错��地引发异常([GH 44715](https://github.com/pandas-dev/pandas/issues/44715))

+   调用`BooleanArray`上的`np.sqrt`时出现错误,返回了一个格式不正确的`FloatingArray`([GH 44715](https://github.com/pandas-dev/pandas/issues/44715))

+   在`Series.where()`中的错误,当`ExtensionDtype`中的`other`是与`Series` dtype 不兼容的 NA 标量时(例如,`NaT`与数值 dtype),错误地转换为兼容的 NA 值([GH 44697](https://github.com/pandas-dev/pandas/issues/44697))

+   在`Series.replace()`中的错误,明确传递`value=None`被视为未传递`value`,且结果中不包含`None`([GH 36984](https://github.com/pandas-dev/pandas/issues/36984),[GH 19998](https://github.com/pandas-dev/pandas/issues/19998))

+   在`Series.replace()`中的错误,在无操作替换中执行不需要的降级转换([GH 44498](https://github.com/pandas-dev/pandas/issues/44498))

+   在`Series.replace()`中的错误,当可能时,未保留`FloatDtype`、`string[python]`或`string[pyarrow]` dtype([GH 33484](https://github.com/pandas-dev/pandas/issues/33484),[GH 40732](https://github.com/pandas-dev/pandas/issues/40732),[GH 31644](https://github.com/pandas-dev/pandas/issues/31644),[GH 41215](https://github.com/pandas-dev/pandas/issues/41215),[GH 25438](https://github.com/pandas-dev/pandas/issues/25438))

### Styler

+   在`Styler`中的错误,初始化时`uuid`保留了一个浮动的下划线([GH 43037](https://github.com/pandas-dev/pandas/issues/43037))

+   在`Styler.to_html()`中的错误,如果调用`to_html`方法时带有一些参数,则会更新`Styler`对象([GH 43034](https://github.com/pandas-dev/pandas/issues/43034))

+   在`Styler.copy()`中的错误,先前未复制`uuid`([GH 40675](https://github.com/pandas-dev/pandas/issues/40675))

+   在`Styler.apply()`中的错误,未正确处理返回`Series`对象的函数,无法正确对齐其索引标签([GH 13657](https://github.com/pandas-dev/pandas/issues/13657),[GH 42014](https://github.com/pandas-dev/pandas/issues/42014))

+   在渲染空的`DataFrame`时带有命名的`Index`的错误([GH 43305](https://github.com/pandas-dev/pandas/issues/43305))

+   渲染单层`MultiIndex`时出现的错误([GH 43383](https://github.com/pandas-dev/pandas/issues/43383))

+   在组合非稀疏渲染和`Styler.hide_columns()`或`Styler.hide_index()`时的错误([GH 43464](https://github.com/pandas-dev/pandas/issues/43464))

+   在使用多个选择器时设置表格样式的错误`Styler`([GH 44011](https://github.com/pandas-dev/pandas/issues/44011))

+   行修剪和列修剪失败反映隐藏行的错误([GH 43703](https://github.com/pandas-dev/pandas/issues/43703),[GH 44247](https://github.com/pandas-dev/pandas/issues/44247))

### 其他

+   在`DataFrame.astype()`中,具有非唯一列和`Series` `dtype`参数的错误([GH 44417](https://github.com/pandas-dev/pandas/issues/44417))

+   `CustomBusinessMonthBegin.__add__()`(`CustomBusinessMonthEnd.__add__()`)中的错误,在目标月份的开始(结束)已经是工作日时,未应用额外的`offset`参数([GH 41356](https://github.com/pandas-dev/pandas/issues/41356))

+   在`RangeIndex.union()`中与另一个具有匹配(偶数)`step`和开始严格小于`step / 2`的`RangeIndex`的错误([GH 44019](https://github.com/pandas-dev/pandas/issues/44019))

+   在`RangeIndex.difference()`中使用`sort=None`和`step<0`时未能排序的错误([GH 44085](https://github.com/pandas-dev/pandas/issues/44085))

+   在`Series.replace()`和`DataFrame.replace()`中,使用`value=None`和 ExtensionDtypes 的错误([GH 44270](https://github.com/pandas-dev/pandas/issues/44270),[GH 37899](https://github.com/pandas-dev/pandas/issues/37899))

+   在`FloatingArray.equals()`中,如果包含`np.nan`��,则未考虑两个数组相等的错误([GH 44382](https://github.com/pandas-dev/pandas/issues/44382))

+   在`DataFrame.shift()`中,当`axis=1`和`ExtensionDtype`列不兼容的`fill_value`被传递时错误地引发异常([GH 44564](https://github.com/pandas-dev/pandas/issues/44564))

+   `DataFrame.shift()` 中的错误,`axis=1` 和 `periods` 大于 `len(frame.columns)` 时会产生无效的 `DataFrame` ([GH 44978](https://github.com/pandas-dev/pandas/issues/44978))

+   `DataFrame.diff()` 中的错误,传递 NumPy 整数对象而不是 `int` 对象时 ([GH 44572](https://github.com/pandas-dev/pandas/issues/44572))

+   `Series.replace()` 中的错误,使用 `regex=True` 时,包含 `np.nan` 值的 `Series` 引发 `ValueError` ([GH 43344](https://github.com/pandas-dev/pandas/issues/43344))

+   `DataFrame.to_records()` 中的错误,当缺少名称被替换为 `level_n` 时使用了不正确的 `n` ([GH 44818](https://github.com/pandas-dev/pandas/issues/44818))

+   `DataFrame.eval()` 中的错误,`resolvers` 参数覆盖了默认解析器 ([GH 34966](https://github.com/pandas-dev/pandas/issues/34966))

+   `Series.__repr__()` 和 `DataFrame.__repr__()` 不再将索引中的所有空值替换为“NaN”,而是使用它们的真实字符串表示。仅对 `float("nan")` 使用“NaN”([GH 45263](https://github.com/pandas-dev/pandas/issues/45263))  ## 贡献者

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

+   Abhishek R

+   Albert Villanova del Moral

+   Alessandro Bisiani +

+   Alex Lim

+   Alex-Gregory-1 +

+   Alexander Gorodetsky

+   Alexander Regueiro +

+   Alexey Györi

+   Alexis Mignon

+   Aleš Erjavec

+   Ali McMaster

+   Alibi +

+   Andrei Batomunkuev +

+   Andrew Eckart +

+   Andrew Hawyrluk

+   Andrew Wood

+   Anton Lodder +

+   Armin Berres +

+   Arushi Sharma +

+   Benedikt Heidrich +

+   Beni Bienz +

+   Benoît Vinot

+   Bert Palm +

+   Boris Rumyantsev +

+   Brian Hulette

+   Brock

+   Bruno Costa +

+   Bryan Racic +

+   Caleb Epstein

+   Calvin Ho

+   ChristofKaufmann +

+   Christopher Yeh +

+   Chuliang Xiao +

+   ClaudiaSilver +

+   DSM

+   Daniel Coll +

+   Daniel Schmidt +

+   Dare Adewumi

+   David +

+   David Sanders +

+   David Wales +

+   Derzan Chiang +

+   DeviousLab +

+   Dhruv B Shetty +

+   Digres45 +

+   Dominik Kutra +

+   Drew Levitt +

+   DriesS

+   EdAbati

+   Elle

+   Elliot Rampono

+   Endre Mark Borza

+   Erfan Nariman

+   Evgeny Naumov +

+   Ewout ter Hoeven +

+   Fangchen Li

+   Felix Divo

+   Felix Dulys +

+   Francesco Andreuzzi +

+   Francois Dion +

+   Frans Larsson +

+   Fred Reiss

+   GYvan

+   Gabriel Di Pardi Arruda +

+   Gesa Stupperich

+   Giacomo Caria +

+   Greg Siano +

+   Griffin Ansel

+   Hiroaki Ogasawara +

+   Horace +

+   Horace Lai +

+   Irv Lustig

+   Isaac Virshup

+   JHM Darbyshire (MBP)

+   JHM Darbyshire (iMac)

+   JHM Darbyshire +

+   Jack Liu

+   Jacob Skwirsk +

+   Jaime Di Cristina +

+   James Holcombe +

+   Janosh Riebesell +

+   Jarrod Millman

+   Jason Bian +

+   Jeff Reback

+   Jernej Makovsek +

+   Jim Bradley +

+   Joel Gibson +

+   Joeperdefloep +

+   Johannes Mueller +

+   John S Bogaardt +

+   John Zangwill +

+   Jon Haitz Legarreta Gorroño +

+   Jon Wiggins +

+   Jonas Haag +

+   Joris Van den Bossche

+   Josh Friedlander

+   José Duarte +

+   Julian Fleischer +

+   Julien de la Bruère-T

+   Justin McOmie

+   Kadatatlu Kishore +

+   Kaiqi Dong

+   Kashif Khan +

+   Kavya9986 +

+   Kendall +

+   Kevin Sheppard

+   Kiley Hewitt

+   Koen Roelofs +

+   Krishna Chivukula

+   KrishnaSai2020

+   Leonardo Freua +

+   Leonardus Chen

+   Liang-Chi Hsieh +

+   Loic Diridollou +

+   Lorenzo Maffioli +

+   Luke Manley +

+   LunarLanding +

+   Marc Garcia

+   Marcel Bittar +

+   Marcel Gerber +

+   Marco Edward Gorelli

+   Marco Gorelli

+   MarcoGorelli

+   Marvin +

+   Mateusz Piotrowski +

+   Mathias Hauser +

+   Matt Richards +

+   Matthew Davis +

+   Matthew Roeschke

+   Matthew Zeitlin

+   Matthias Bussonnier

+   Matti Picus

+   Mauro Silberberg +

+   Maxim Ivanov

+   Maximilian Carr +

+   MeeseeksMachine

+   Michael Sarrazin +

+   Michael Wang +

+   Michał Górny +

+   Mike Phung +

+   Mike Taves +

+   Mohamad Hussein Rkein +

+   NJOKU OKECHUKWU VALENTINE +

+   Neal McBurnett +

+   Nick Anderson +

+   Nikita Sobolev +

+   Olivier Cavadenti +

+   PApostol +

+   Pandas Development Team

+   Patrick Hoefler

+   Peter

+   Peter Tillmann +

+   Prabha Arivalagan +

+   Pradyumna Rahul

+   Prerana Chakraborty

+   Prithvijit +

+   Rahul Gaikwad +

+   Ray Bell

+   Ricardo Martins +

+   Richard Shadrach

+   Robbert-jan ‘t Hoen +

+   Robert Voyer +

+   Robin Raymond +

+   Rohan Sharma +

+   Rohan Sirohia +

+   Roman Yurchak

+   Ruan Pretorius +

+   Sam James +

+   Scott Talbert

+   Shashwat Sharma +

+   Sheogorath27 +

+   Shiv Gupta

+   Shoham Debnath

+   Simon Hawkins

+   Soumya +

+   Stan West +

+   Stefanie Molin +

+   Stefano Alberto Russo +

+   Stephan Heßelmann

+   Stephen

+   Suyash Gupta +

+   Sven

+   Swanand01 +

+   Sylvain Marié +

+   TLouf

+   Tania Allard +

+   Terji Petersen

+   TheDerivator +

+   Thomas Dickson

+   Thomas Kastl +

+   Thomas Kluyver

+   Thomas Li

+   Thomas Smith

+   Tim Swast

+   Tim Tran +

+   Tobias McNulty +

+   Tobias Pitters

+   Tomoki Nakagawa +

+   Tony Hirst +

+   Torsten Wörtwein

+   V.I. Wood +

+   Vaibhav K +

+   Valentin Oliver Loftsson +

+   Varun Shrivastava +

+   Vivek Thazhathattil +

+   Vyom Pathak

+   Wenjun Si

+   William Andrea +

+   William Bradley +

+   Wojciech Sadowski +

+   Yao-Ching Huang +

+   Yash Gupta +

+   Yiannis Hadjicharalambous +

+   Yoshiki Vázquez Baeza

+   Yuanhao Geng

+   Yury Mikhaylov

+   Yvan Gatete +

+   Yves Delley +

+   Zach Rait

+   Zbyszek Królikowski +

+   Zero +

+   Zheyuan

+   Zhiyi Wu +

+   aiudirog

+   ali sayyah +

+   aneesh98 +

+   aptalca

+   arw2019 +

+   attack68

+   brendandrury +

+   bubblingoak +

+   calvinsomething +

+   claws +

+   deponovo +

+   dicristina

+   el-g-1 +

+   evensure +

+   fotino21 +

+   fshi01 +

+   gfkang +

+   github-actions[bot]

+   i-aki-y

+   jbrockmendel

+   jreback

+   juliandwain +

+   jxb4892 +

+   kendall smith +

+   lmcindewar +

+   lrepiton

+   maximilianaccardo +

+   michal-gh

+   neelmraman

+   partev

+   phofl +

+   pratyushsharan +

+   quantumalaviya +

+   rafael +

+   realead

+   rocabrera +

+   rosagold

+   saehuihwang +

+   salomondush +

+   shubham11941140 +

+   srinivasan +

+   stphnlyd

+   suoniq

+   trevorkask +

+   tushushu

+   tyuyoshi +

+   usersblock +

+   vernetya +

+   vrserpa +

+   willie3838 +

+   zeitlinv +

+   zhangxiaoxing +  ## Enhancements

### Improved warning messages

以前,警告消息可能指向 pandas 库内的行。运行脚本 `setting_with_copy_warning.py`

```py
import pandas as pd

df = pd.DataFrame({'a': [1, 2, 3]})
df[:2].loc[:, 'a'] = 5 

在 pandas 1.3 中产生了以下结果:

.../site-packages/pandas/core/indexing.py:1951: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame. 

这使得难以确定警告是从哪里生成的。现在 pandas 将检查调用堆栈,报告产生警告的 pandas 库之外的第一行。上面脚本的输出现在是:

setting_with_copy_warning.py:4: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame. 
```  ### 索引可以持有任意 ExtensionArrays

到目前为止,将自定义的 `ExtensionArray` 传递给 `pd.Index` 会将数组转换为 `object` dtype。现在 `Index` 可以直接持有任意 ExtensionArrays ([GH 43930](https://github.com/pandas-dev/pandas/issues/43930))。

*以前的行为*:

```py
In [1]: arr = pd.array([1, 2, pd.NA])

In [2]: idx = pd.Index(arr) 

在旧行为中,idx 将是 object-dtype:

以前的行为

In [1]: idx
Out[1]: Index([1, 2, <NA>], dtype='object') 

使用新行为,我们保留原始 dtype:

新行为

In [3]: idx
Out[3]: Index([1, 2, <NA>], dtype='Int64') 

其中一个例外是 SparseArray,它将继续将其转换为 numpy dtype,直到 pandas 2.0。在那时,它将像其他 ExtensionArrays 一样保留其 dtype。### Styler

在 1.4.0 版本中,Styler 已进一步发展。已进行以下一般增强:

  • 已添加索引的样式和格式化,使用 Styler.apply_index()Styler.applymap_index()Styler.format_index()。这些方法与已用于样式化和格式化数据值的方法的签名相同,并且适用于 HTML、LaTeX 和 Excel 格式 (GH 41893, GH 43101, GH 41993, GH 41995)。
  • 新方法 Styler.hide() 废弃了 Styler.hide_index()Styler.hide_columns() (GH 43758)。
  • 已将关键字参数 levelnames 添加到 Styler.hide()(以及隐式添加到已废弃的方法 Styler.hide_index()Styler.hide_columns())以对 MultiIndexes 和索引名称的可见性进行额外控制 (GH 25475, GH 43404, GH 43346)。
  • Styler.export()Styler.use() 已更新,以解决从 v1.2.0 和 v1.3.0 添加的所有功能(GH 40675
  • 全局选项在pd.options.styler类别下已扩展,以配置默认的Styler属性,涉及格式、编码以及 HTML 和 LaTeX 渲染。请注意,以前Styler依赖于display.html.use_mathjax,现已由styler.html.mathjax替代(GH 41395
  • 验证某些关键字参数,例如captionGH 43368
  • 下面记录了各种错误修复

此外,HTML 特定渲染有特定的增强功能:

  • Styler.bar() 引入了额外的参数来控制对齐和显示(GH 26070GH 36419),还验证了输入参数widthheightGH 42511)
  • Styler.to_html() 引入了关键字参数sparse_indexsparse_columnsbold_headerscaptionmax_rowsmax_columnsGH 41946GH 43149GH 42972
  • Styler.to_html() 为隐藏的表元素省略了 CSS 样式规则,以提高性能(GH 43619
  • 自定义 CSS 类现在可以直接指定,无需字符串替换(GH 43686
  • 通过新的hyperlinks格式关键字参数自动呈现超链接的能力(GH 45058

还有一些 LaTeX 特定的增强功能:

  • Styler.to_latex() 引入了关键字参数environment,还允许通过单独的 jinja2 模板输入特定的“longtable”条目(GH 41866
  • 现在可以对 LaTeX 进行简单稀疏化,无需包含 multirow 包 (GH 43369)
  • cline 支持通过关键字参数为 MultiIndex 添加了行稀疏化(GH 45138) ### 基于 pyarrow 的多线程 CSV 读取与新 CSV 引擎

pandas.read_csv() 现在接受 engine="pyarrow"(至少需要 pyarrow 1.0.1)作为参数,允许在安装了 pyarrow 的多核机器上更快地解析 csv。 更多信息请参见 I/O 文档。 (GH 23697, GH 43706) ### 滚动和展开窗口的排名函数

RollingExpanding中添加了rank函数。 新函数支持DataFrame.rank()methodascendingpct 标志。 method 参数支持 minmaxaverage 排名方法。 示例:

In [4]: s = pd.Series([1, 4, 2, 3, 5, 3])

In [5]: s.rolling(3).rank()
Out[5]: 
0    NaN
1    NaN
2    2.0
3    2.0
4    3.0
5    1.5
dtype: float64

In [6]: s.rolling(3).rank(method="max")
Out[6]: 
0    NaN
1    NaN
2    2.0
3    2.0
4    3.0
5    2.0
dtype: float64 
```  ### 按位置索引进行分组

现在可以相对于每个组的末尾指定位置范围。

对于 `DataFrameGroupBy.head()`、`SeriesGroupBy.head()`、`DataFrameGroupBy.tail()` 和 `SeriesGroupBy.tail()`,现在负参数可以正确工作,并分别导致相对于每个组的末尾和开头的范围。 以前,负参数返回空框架。

```py
In [7]: df = pd.DataFrame([["g", "g0"], ["g", "g1"], ["g", "g2"], ["g", "g3"],
 ...:                   ["h", "h0"], ["h", "h1"]], columns=["A", "B"])
 ...: 

In [8]: df.groupby("A").head(-1)
Out[8]: 
 A   B
0  g  g0
1  g  g1
2  g  g2
4  h  h0 

DataFrameGroupBy.nth()SeriesGroupBy.nth() 现在接受整数和切片的切片或列表。

In [9]: df.groupby("A").nth(slice(1, -1))
Out[9]: 
 A   B
1  g  g1
2  g  g2

In [10]: df.groupby("A").nth([slice(None, 1), slice(-1, None)])
Out[10]: 
 A   B
0  g  g0
3  g  g3
4  h  h0
5  h  h1 

DataFrameGroupBy.nth()SeriesGroupBy.nth() 现在接受索引表示法。

In [11]: df.groupby("A").nth[1, -1]
Out[11]: 
 A   B
1  g  g1
3  g  g3
5  h  h1

In [12]: df.groupby("A").nth[1:-1]
Out[12]: 
 A   B
1  g  g1
2  g  g2

In [13]: df.groupby("A").nth[:1, -1:]
Out[13]: 
 A   B
0  g  g0
3  g  g3
4  h  h0
5  h  h1 
```  ### `DataFrame.from_dict` 和 `DataFrame.to_dict` 现在有新的 `'tight'` 选项

现在可以使用新的 `'tight'` 字典格式,通过 `DataFrame.from_dict()` 和 `DataFrame.to_dict()` 方法,以及标准的 `json` 库来生成 `DataFrame` 对象的紧凑表示,该格式保留了 `MultiIndex` 条目和名称 ([GH 4889](https://github.com/pandas-dev/pandas/issues/4889)).

```py
In [14]: df = pd.DataFrame.from_records(
 ....:    [[1, 3], [2, 4]],
 ....:    index=pd.MultiIndex.from_tuples([("a", "b"), ("a", "c")],
 ....:                                    names=["n1", "n2"]),
 ....:    columns=pd.MultiIndex.from_tuples([("x", 1), ("y", 2)],
 ....:                                      names=["z1", "z2"]),
 ....: )
 ....: 

In [15]: df
Out[15]: 
z1     x  y
z2     1  2
n1 n2 
a  b   1  3
 c   2  4

In [16]: df.to_dict(orient='tight')
Out[16]: 
{'index': [('a', 'b'), ('a', 'c')],
 'columns': [('x', 1), ('y', 2)],
 'data': [[1, 3], [2, 4]],
 'index_names': ['n1', 'n2'],
 'column_names': ['z1', 'z2']} 
```  ### 其他增强

+   当所有对象的 `attrs` 相同时,`concat()` 将保留 `attrs`,当它们不同时则丢弃 `attrs` ([GH 41828](https://github.com/pandas-dev/pandas/issues/41828))

+   使用 `as_index=False` 的 `DataFrameGroupBy` 操作现在正确保留被分组列的 `ExtensionDtype` 数据类型 ([GH 41373](https://github.com/pandas-dev/pandas/issues/41373))

+   在 `DataFrame.plot.hist()` 和 `DataFrame.plot.box()` 中添加对 `by` 参数赋值的支持 ([GH 15079](https://github.com/pandas-dev/pandas/issues/15079))

+   `Series.sample()`、`DataFrame.sample()`、`DataFrameGroupBy.sample()` 和 `SeriesGroupBy.sample()` 现在接受 `np.random.Generator` 作为 `random_state` 的输入。使用生成器将更高效,特别是在 `replace=False` 的情况下 ([GH 38100](https://github.com/pandas-dev/pandas/issues/38100))

+   `Series.ewm()` 和 `DataFrame.ewm()` 现在支持 `method` 参数,其中包含一个 `'table'` 选项,用于在整个 `DataFrame` 上执行窗口操作。查看 窗口概述 以���解性能和功能上的优势 ([GH 42273](https://github.com/pandas-dev/pandas/issues/42273))

+   `DataFrameGroupBy.cummin()`, `SeriesGroupBy.cummin()`, `DataFrameGroupBy.cummax()`, 和 `SeriesGroupBy.cummax()` 现在支持参数 `skipna` ([GH 34047](https://github.com/pandas-dev/pandas/issues/34047))

+   `read_table()` 现在支持参数 `storage_options` ([GH 39167](https://github.com/pandas-dev/pandas/issues/39167))

+   `DataFrame.to_stata()` 和 `StataWriter()` 现在接受关键字参数 `value_labels`,用于保存非分类列的标签 ([GH 38454](https://github.com/pandas-dev/pandas/issues/38454))

+   依赖于基于哈希映射算法的方法,如 `DataFrameGroupBy.value_counts()`,`DataFrameGroupBy.count()` 和 `factorize()`,对于复数忽略了虚部分 ([GH 17927](https://github.com/pandas-dev/pandas/issues/17927))

+   添加 `Series.str.removeprefix()` 和 `Series.str.removesuffix()`,引入了 Python 3.9 中用于从字符串类型 `Series` 中移除前缀/后缀的方法 ([GH 36944](https://github.com/pandas-dev/pandas/issues/36944))

+   尝试使用`DataFrame.to_csv()`、`DataFrame.to_html()`、`DataFrame.to_excel()`、`DataFrame.to_feather()`、`DataFrame.to_parquet()`、`DataFrame.to_stata()`、`DataFrame.to_json()`、`DataFrame.to_pickle()`和`DataFrame.to_xml()`时,现在明确提到了缺少父目录,对应的`Series`也是如此([GH 24306](https://github.com/pandas-dev/pandas/issues/24306))

+   使用`.loc`和`.iloc`进行索引现在支持`Ellipsis`([GH 37750](https://github.com/pandas-dev/pandas/issues/37750))

+   `IntegerArray.all()`、`IntegerArray.any()`、`FloatingArray.any()`和`FloatingArray.all()`现在使用 Kleene 逻辑([GH 41967](https://github.com/pandas-dev/pandas/issues/41967))

+   在`DataFrame.to_stata()`、`StataWriter`、`StataWriter117`和`StataWriterUTF8`中增加了对可空布尔值和整数类型的支持([GH 40855](https://github.com/pandas-dev/pandas/issues/40855))

+   `DataFrame.__pos__()`和`DataFrame.__neg__()`现在保留`ExtensionDtype`数据类型([GH 43883](https://github.com/pandas-dev/pandas/issues/43883))

+   当无法导入可选依赖项时引发的错误现在包含原始异常,以便更容易进行调查([GH 43882](https://github.com/pandas-dev/pandas/issues/43882))

+   增加了`ExponentialMovingWindow.sum()`([GH 13297](https://github.com/pandas-dev/pandas/issues/13297))

+   `Series.str.split()` 现在支持一个 `regex` 参数,明确指定模式是否为正则表达式。默认为 `None`([GH 43563](https://github.com/pandas-dev/pandas/issues/43563),[GH 32835](https://github.com/pandas-dev/pandas/issues/32835),[GH 25549](https://github.com/pandas-dev/pandas/issues/25549))

+   `DataFrame.dropna()` 现在可以接受一个标签作为 `subset`,以及类数组([GH 41021](https://github.com/pandas-dev/pandas/issues/41021))

+   添加了 `DataFrameGroupBy.value_counts()`([GH 43564](https://github.com/pandas-dev/pandas/issues/43564))

+   在 `engine="python"` 时,`read_csv()` 现在接受 `callable` 函数以在 `on_bad_lines` 中自定义处理错误行([GH 5686](https://github.com/pandas-dev/pandas/issues/5686))

+   `ExcelWriter` 参数 `if_sheet_exists="overlay"` 选项已添加([GH 40231](https://github.com/pandas-dev/pandas/issues/40231))

+   `read_excel()` 现在接受一个 `decimal` 参数,允许用户在将字符串列解析为数字时指定小数点([GH 14403](https://github.com/pandas-dev/pandas/issues/14403))

+   `DataFrameGroupBy.mean()`、`SeriesGroupBy.mean()`、`DataFrameGroupBy.std()`、`SeriesGroupBy.std()`、`DataFrameGroupBy.var()`、`SeriesGroupBy.var()`、`DataFrameGroupBy.sum()` 和 `SeriesGroupBy.sum()` 现在支持使用 `engine` 关键字进行 [Numba](http://numba.pydata.org/) 执行([GH 43731](https://github.com/pandas-dev/pandas/issues/43731),[GH 44862](https://github.com/pandas-dev/pandas/issues/44862),[GH 44939](https://github.com/pandas-dev/pandas/issues/44939))

+   `Timestamp.isoformat()` 现在处理基本 `datetime` 类的 `timespec` 参数([GH 26131](https://github.com/pandas-dev/pandas/issues/26131))

+   `NaT.to_numpy()` 的 `dtype` 参数现在受到尊重,因此可以返回 `np.timedelta64`([GH 44460](https://github.com/pandas-dev/pandas/issues/44460))

+   新选项 `display.max_dir_items` 自定义添加到 `Dataframe.__dir__()` 的列数,并为选项卡补全提供建议([GH 37996](https://github.com/pandas-dev/pandas/issues/37996))

+   将“六月节国家独立日”添加到 `USFederalHolidayCalendar`([GH 44574](https://github.com/pandas-dev/pandas/issues/44574))

+   `Rolling.var()`、`Expanding.var()`、`Rolling.std()` 和 `Expanding.std()` 现在支持 [Numba](http://numba.pydata.org/) 执行,使用 `engine` 关键字([GH 44461](https://github.com/pandas-dev/pandas/issues/44461))

+   已添加 `Series.info()`,以便与 `DataFrame.info()` 兼容([GH 5167](https://github.com/pandas-dev/pandas/issues/5167))

+   实现了 `IntervalArray.min()` 和 `IntervalArray.max()`,因此 `min` 和 `max` 现在适用于带有 `IntervalDtype` 的 `IntervalIndex`、`Series` 和 `DataFrame`([GH 44746](https://github.com/pandas-dev/pandas/issues/44746))

+   `UInt64Index.map()` 现在在可能的情况下保留 `dtype`([GH 44609](https://github.com/pandas-dev/pandas/issues/44609))

+   `read_json()` 现在可以解析无符号长长整型数([GH 26068](https://github.com/pandas-dev/pandas/issues/26068))

+   `DataFrame.take()` 现在在索引器传递标量时会引发 `TypeError`([GH 42875](https://github.com/pandas-dev/pandas/issues/42875))

+   `is_list_like()` 现在将鸭式数组识别为类似列表,除非 `.ndim == 0`([GH 35131](https://github.com/pandas-dev/pandas/issues/35131))

+   在使用 `orient='table'` 时,`DataFrame.to_json()` 现在可以(反)序列化 `ExtensionDtype` 和 `ExtensionArray`,在导出 `DataFrame` 时([GH 20612](https://github.com/pandas-dev/pandas/issues/20612),[GH 44705](https://github.com/pandas-dev/pandas/issues/44705))

+   为 `DataFrame.to_pickle()`/`read_pickle()` 及其相关函数添加对 [Zstandard](http://facebook.github.io/zstd/) 压缩的支持([GH 43925](https://github.com/pandas-dev/pandas/issues/43925))

+   `DataFrame.to_sql()` 现在返回写入行数的 `int` 值([GH 23998](https://github.com/pandas-dev/pandas/issues/23998))  ### 改进的警告消息

以前,警告消息可能指向 pandas 库内的行。运行脚本 `setting_with_copy_warning.py`

```py
import pandas as pd

df = pd.DataFrame({'a': [1, 2, 3]})
df[:2].loc[:, 'a'] = 5 

使用 pandas 1.3 导致:

.../site-packages/pandas/core/indexing.py:1951: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame. 

这使得确定警告的生成位置变得困难。现在 pandas 将检查调用堆栈,报告产生警告的 pandas 库之外的第一行。上述脚本的输出现在是:

setting_with_copy_warning.py:4: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame. 

索引可以持有任意的 ExtensionArrays

直到现在,将自定义的 ExtensionArray 传递给 pd.Index 会将数组转换为 object dtype。现在 Index 可以直接持有任意的 ExtensionArrays (GH 43930).

先前的行为

In [1]: arr = pd.array([1, 2, pd.NA])

In [2]: idx = pd.Index(arr) 

在旧行为中,idx 将是 object-dtype:

先前的行为

In [1]: idx
Out[1]: Index([1, 2, <NA>], dtype='object') 

使用新的行为,我们保留了原始的 dtype:

新行为

In [3]: idx
Out[3]: Index([1, 2, <NA>], dtype='Int64') 

这个的一个例外是 SparseArray,它将继续到 pandas 2.0 之前转换为 numpy dtype。此后它将像其他 ExtensionArrays 一样保留其 dtype。

样式化

Styler 在 1.4.0 版本中有了进一步的发展。以下是一般性增强:

  • 添加了索引的样式和格式,使用 Styler.apply_index()Styler.applymap_index()Styler.format_index()。这些方法与已用于样式化和格式化数据值的方法的签名相同,并且适用于 HTML、LaTeX 和 Excel 格式 (GH 41893, GH 43101, GH 41993, GH 41995)
  • 新方法 Styler.hide() 废弃了 Styler.hide_index()Styler.hide_columns() (GH 43758)
  • 关键字参数 levelnames 已添加到 Styler.hide() (隐含地添加到已弃用的方法 Styler.hide_index()Styler.hide_columns())以便更多地控制多级索引和索引名称的可见性 (GH 25475, GH 43404, GH 43346)
  • Styler.export()Styler.use() 已更新,以处理从 v1.2.0 和 v1.3.0 中添加的所有功能 (GH 40675)
  • 全局选项在类别 pd.options.styler 下已扩展以配置默认的 Styler 属性,包括格式、编码和 HTML 和 LaTeX 渲染。请注意,以前 Styler 依赖于 display.html.use_mathjax,现已被 styler.html.mathjax 取代 (GH 41395)
  • 验证某些关键字参数,例如caption (GH 43368)
  • 如下记录的各种错误修复

此外,还有特定于 HTML 渲染的特定增强:

  • Styler.bar() 引入了额外的参数来控制对齐和显示 (GH 26070, GH 36419), 并且还验证了输入参数 widthheight (GH 42511)
  • Styler.to_html() 引入了关键字参数 sparse_index, sparse_columns, bold_headers, caption, max_rowsmax_columns (GH 41946, GH 43149, GH 42972)
  • Styler.to_html() 省略了隐藏表格元素的 CSS 样式规则,以提高性能(GH 43619)
  • 现在可以直接指定自定义 CSS 类,无需字符串替换(GH 43686)
  • 通过新的hyperlinks格式化关键字参数,可以自动呈现超链接(GH 45058)

还有一些特定于 LaTeX 的增强功能:

  • Styler.to_latex() 引入了关键字参数environment,还允许通过单独的 jinja2 模板指定特定的“longtable”条目(GH 41866)
  • 现在可以在 LaTeX 中进行简单的稀疏化,无需包含 multirow 包(GH 43369)
  • 通过关键字参数为MultiIndex行稀疏化添加了cline支持(GH 45138)

基于 pyarrow 的新 CSV 引擎进行多线程 CSV 读取

pandas.read_csv() 现在接受engine="pyarrow"(至少需要pyarrow 1.0.1)作为参数,允许在安装了 pyarrow 的多核机器上更快地解析 csv。查看 I/O 文档获取更多信息。(GH 23697, GH 43706)

滚动和扩展窗口的排名函数

RollingExpanding中添加了rank函数。新函数支持DataFrame.rank()methodascendingpct标志。method参数支持minmaxaverage排名方法。示例:

In [4]: s = pd.Series([1, 4, 2, 3, 5, 3])

In [5]: s.rolling(3).rank()
Out[5]: 
0    NaN
1    NaN
2    2.0
3    2.0
4    3.0
5    1.5
dtype: float64

In [6]: s.rolling(3).rank(method="max")
Out[6]: 
0    NaN
1    NaN
2    2.0
3    2.0
4    3.0
5    2.0
dtype: float64 

按组位置索引

现在可以指定相对于每个组末端的位置范围。

对于DataFrameGroupBy.head()SeriesGroupBy.head()DataFrameGroupBy.tail()SeriesGroupBy.tail(),现在负参数可以正确工作,并且分别相对于每个组的末尾和开始产生范围。之前,负参数会返回空框架。

In [7]: df = pd.DataFrame([["g", "g0"], ["g", "g1"], ["g", "g2"], ["g", "g3"],
 ...:                   ["h", "h0"], ["h", "h1"]], columns=["A", "B"])
 ...: 

In [8]: df.groupby("A").head(-1)
Out[8]: 
 A   B
0  g  g0
1  g  g1
2  g  g2
4  h  h0 

DataFrameGroupBy.nth()SeriesGroupBy.nth() 现在接受整数和切片的切片或列表。

In [9]: df.groupby("A").nth(slice(1, -1))
Out[9]: 
 A   B
1  g  g1
2  g  g2

In [10]: df.groupby("A").nth([slice(None, 1), slice(-1, None)])
Out[10]: 
 A   B
0  g  g0
3  g  g3
4  h  h0
5  h  h1 

DataFrameGroupBy.nth()SeriesGroupBy.nth() 现在接受索引表示法。

In [11]: df.groupby("A").nth[1, -1]
Out[11]: 
 A   B
1  g  g1
3  g  g3
5  h  h1

In [12]: df.groupby("A").nth[1:-1]
Out[12]: 
 A   B
1  g  g1
2  g  g2

In [13]: df.groupby("A").nth[:1, -1:]
Out[13]: 
 A   B
0  g  g0
3  g  g3
4  h  h0
5  h  h1 

DataFrame.from_dict 和 DataFrame.to_dict 有新的 'tight' 选项

使用DataFrame.from_dict()DataFrame.to_dict()方法,现在可以使用新的 'tight' 字典格式,该格式保留了MultiIndex条目和名称,并且可以与标准的 json 库一起使用,以生成DataFrame对象的紧凑表示形式(GH 4889)。

In [14]: df = pd.DataFrame.from_records(
 ....:    [[1, 3], [2, 4]],
 ....:    index=pd.MultiIndex.from_tuples([("a", "b"), ("a", "c")],
 ....:                                    names=["n1", "n2"]),
 ....:    columns=pd.MultiIndex.from_tuples([("x", 1), ("y", 2)],
 ....:                                      names=["z1", "z2"]),
 ....: )
 ....: 

In [15]: df
Out[15]: 
z1     x  y
z2     1  2
n1 n2 
a  b   1  3
 c   2  4

In [16]: df.to_dict(orient='tight')
Out[16]: 
{'index': [('a', 'b'), ('a', 'c')],
 'columns': [('x', 1), ('y', 2)],
 'data': [[1, 3], [2, 4]],
 'index_names': ['n1', 'n2'],
 'column_names': ['z1', 'z2']} 

其他增强功能

  • 当所有对象的 attrs 相同时,concat() 将保留 attrs,并在它们不同时丢弃 attrsGH 41828)。

  • 使用 as_index=FalseDataFrameGroupBy 操作现在能够正确地保留被分组列的 ExtensionDtype 类型 (GH 41373)。

  • DataFrame.plot.hist()DataFrame.plot.box() 中增加对 by 参数赋值的支持(GH 15079

  • Series.sample(), DataFrame.sample(), DataFrameGroupBy.sample(), 和 SeriesGroupBy.sample() 现在接受 np.random.Generator 作为 random_state 的输入。使用生成器将更加高效,特别是在 replace=False 的情况下(GH 38100

  • Series.ewm()DataFrame.ewm() 现在支持一个 method 参数,其中包含一个 'table' 选项,该选项在整个 DataFrame 上执行窗口操作。参见 窗口概述 以了解性能和功能优势(GH 42273

  • DataFrameGroupBy.cummin(), SeriesGroupBy.cummin(), DataFrameGroupBy.cummax(), 和 SeriesGroupBy.cummax() 现在支持参数 skipnaGH 34047

  • read_table() 现在支持参数 storage_optionsGH 39167

  • DataFrame.to_stata()StataWriter() 现在接受关键字参数 value_labels,以保存非分类列的标签(GH 38454)。

  • 依赖于基于 hashmap 的算法的方法,如 DataFrameGroupBy.value_counts()DataFrameGroupBy.count()factorize(),对于复数,忽略了虚部分(GH 17927)。

  • 添加了在 Python 3.9 中引入的 Series.str.removeprefix()Series.str.removesuffix(),用于从字符串类型的 Series 中移除前缀/后缀(GH 36944)。

  • 尝试使用 DataFrame.to_csv()DataFrame.to_html()DataFrame.to_excel()DataFrame.to_feather()DataFrame.to_parquet()DataFrame.to_stata()DataFrame.to_json()DataFrame.to_pickle()DataFrame.to_xml() 向缺失的父目录写入文件时,现在明确提到了缺失的父目录,对应的 Series 方法也是如此(GH 24306)。

  • 使用 .loc.iloc 进行索引现在支持 EllipsisGH 37750)。

  • IntegerArray.all()IntegerArray.any()FloatingArray.any()FloatingArray.all() 使用 Kleene 逻辑(GH 41967)。

  • DataFrame.to_stata()StataWriterStataWriter117StataWriterUTF8中添加了对可空布尔值和整数类型的支持(GH 40855)

  • DataFrame.__pos__()DataFrame.__neg__()现在保留ExtensionDtype数据类型(GH 43883)

  • 当无法导入可选依赖项时引发的错误现在包含原始异常,以便更容易进行调查(GH 43882)

  • 添加了ExponentialMovingWindow.sum()GH 13297)

  • Series.str.split()现在支持regex参数,明确指定模式是否为正则表达式。默认为NoneGH 43563, GH 32835, GH 25549)

  • DataFrame.dropna()现在接受单个标签作为subset以及类似数组的输入(GH 41021)

  • 添加了DataFrameGroupBy.value_counts()GH 43564)

  • read_csv()现在在engine="python"时接受callable函数作为on_bad_lines,用于自定义处理错误行(GH 5686)

  • 添加了ExcelWriter参数if_sheet_exists="overlay"选项(GH 40231)

  • read_excel()现在接受一个decimal参数,允许用户在将字符串列解析为数字时指定小数点(GH 14403)

  • DataFrameGroupBy.mean(), SeriesGroupBy.mean(), DataFrameGroupBy.std(), SeriesGroupBy.std(), DataFrameGroupBy.var(), SeriesGroupBy.var(), DataFrameGroupBy.sum(), 和 SeriesGroupBy.sum() 现在支持 Numba 执行,带有 engine 关键字(GH 43731, GH 44862, GH 44939

  • Timestamp.isoformat() 现在处理基本 datetime 类的 timespec 参数(GH 26131

  • NaT.to_numpy() 现在遵循 dtype 参数,因此可以返回 np.timedelta64GH 44460

  • 新选项 display.max_dir_items 自定义添加到 Dataframe.__dir__() 的列数,并建议用于制表完成(GH 37996

  • 将“六月节国庆日”添加到 USFederalHolidayCalendar 中(GH 44574

  • Rolling.var()Expanding.var()Rolling.std()Expanding.std() 现在支持 Numba 执行,使用 engine 关键字(GH 44461

  • Series.info() 已添加,以兼容 DataFrame.info()GH 5167

  • 实现了 IntervalArray.min()IntervalArray.max(),因此 minmax 现在适用于带有 IntervalDtypeIntervalIndexSeriesDataFrameGH 44746

  • UInt64Index.map() 现在在可能的情况下保留 dtypeGH 44609

  • read_json() 现在可以解析无符号长长整型(GH 26068

  • DataFrame.take() 现在在为索引器传递标量时引发 TypeErrorGH 42875

  • is_list_like() 现在将鸭式数组识别为类似列表,除非 .ndim == 0GH 35131

  • 当使用 orient='table' 导出 DataFrame 时,ExtensionDtypeExtensionArray 现在(反)序列化使用 DataFrame.to_json()GH 20612GH 44705

  • DataFrame.to_pickle()/read_pickle()等函数添加对Zstandard压缩的支持(GH 43925)

  • DataFrame.to_sql() 现在返回写入行数的intGH 23998

显著的错误修复

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

不一致的日期字符串解析

to_datetime()dayfirst 选项不是严格的,这可能导致意外行为:

In [17]: pd.to_datetime(["31-12-2021"], dayfirst=False)
Out[17]: DatetimeIndex(['2021-12-31'], dtype='datetime64[ns]', freq=None) 

现在,如果日期字符串无法根据给定的 dayfirst 值进行解析(例如31-12-2012是一个分隔的日期字符串),则会发出警告。 ### 在 concat 中忽略具有空或全部 NA 列的 dtypes

此行为变更已在 pandas 1.4.3 中撤销。

当使用concat()连接两个或多个DataFrame对象时,如果其中一个 DataFrame 为空或具有全部 NA 值,则在查找连接 dtype 时有时会忽略其 dtype。现在,这些都是一致地被忽略(GH 43507)。

In [3]: df1 = pd.DataFrame({"bar": [pd.Timestamp("2013-01-01")]}, index=range(1))
In [4]: df2 = pd.DataFrame({"bar": np.nan}, index=range(1, 2))
In [5]: res = pd.concat([df1, df2]) 

以前,在 df2 中的 float-dtype 会被忽略,因此结果 dtype 会是 datetime64[ns]。因此,np.nan 会被转换为 NaT

之前的行为:

In [6]: res
Out[6]:
 bar
0 2013-01-01
1        NaT 

现在,float-dtype 被尊重。由于这些 DataFrame 的常见 dtype 是 object,所以np.nan被保留。

新行为:

In [6]: res
Out[6]:
 bar
0  2013-01-01 00:00:00
1                  NaN 
```  ### 在 value_counts 和 mode 中不再强制将空值转换为 NaN 值

`Series.value_counts()` 和 `Series.mode()` 不再将 `None`、`NaT` 和其他空值强制转换为 `np.object_`-dtype 的 NaN 值。此行为现在与`unique`、`isin`和其他行为一致([GH 42688](https://github.com/pandas-dev/pandas/issues/42688))。

```py
In [18]: s = pd.Series([True, None, pd.NaT, None, pd.NaT, None])

In [19]: res = s.value_counts(dropna=False) 

以前,所有空值都被替换为 NaN 值。

之前的行为:

In [3]: res
Out[3]:
NaN     5
True    1
dtype: int64 

现在,空值不再被篡改。

新行为:

In [20]: res
Out[20]: 
None    3
NaT     2
True    1
Name: count, dtype: int64 
```  ### 在 read_csv 中的 mangle_dupe_cols 不再重命名与目标名称冲突的唯一列

`read_csv()`不再重命名与重复列目标名称冲突的唯一列标签。已存在的列将被跳过,即目标列名将使用下一个可用索引([GH 14704](https://github.com/pandas-dev/pandas/issues/14704))。

```py
In [21]: import io

In [22]: data = "a,a,a.1\n1,2,3"

In [23]: res = pd.read_csv(io.StringIO(data)) 

以前,第二列称为a.1,而第三列也被重命名为a.1.1

先前行为

In [3]: res
Out[3]:
 a  a.1  a.1.1
0   1    2      3 

现在在更改第二列名称时,重命名检查是否已存在a.1,并跳过此索引。第二列改名为a.2

新行为

In [24]: res
Out[24]: 
 a  a.2  a.1
0  1    2    3 
```  ### unstack 和 pivot_table 不再为超过 int32 限制的结果引发 ValueError

以前`DataFrame.pivot_table()`和`DataFrame.unstack()`如果操作可能产生超过`2**31 - 1`个元素的结果,将引发`ValueError`。现在,此操作会引发一个`errors.PerformanceWarning`([GH 26314](https://github.com/pandas-dev/pandas/issues/26314))。

*先前行为*:

```py
In [3]: df = DataFrame({"ind1": np.arange(2 ** 16), "ind2": np.arange(2 ** 16), "count": 0})
In [4]: df.pivot_table(index="ind1", columns="ind2", values="count", aggfunc="count")
ValueError: Unstacked DataFrame is too big, causing int32 overflow 

新行为

In [4]: df.pivot_table(index="ind1", columns="ind2", values="count", aggfunc="count")
PerformanceWarning: The following operation may generate 4294967296 cells in the resulting pandas object. 
```  ### groupby.apply 一致的 transform 检测

`DataFrameGroupBy.apply()`和`SeriesGroupBy.apply()`被设计为灵活,允许用户执行聚合、转换、过滤,并使用用户定义的可能不属于这些类别的函数。作为其中的一部分,apply 将尝试检测操作是否是 transform,在这种情况下,结果将与输入具有相同的索引。为了确定操作是否是 transform,pandas 比较输入的索引和结果的索引,并确定是否已经发生了变异。在 pandas 1.3 中,不同的代码路径使用了不同的“变异”定义:有些会使用 Python 的`is`,而其他只会测试直到相等。

这种不一致性已经被移除,pandas 现在测试直到相等。

```py
In [25]: def func(x):
 ....:    return x.copy()
 ....: 

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

In [27]: df
Out[27]: 
 a  b  c
0  1  3  5
1  2  4  6 

先前行为

In [3]: df.groupby(['a']).apply(func)
Out[3]:
 a  b  c
a
1 0  1  3  5
2 1  2  4  6

In [4]: df.set_index(['a', 'b']).groupby(['a']).apply(func)
Out[4]:
 c
a b
1 3  5
2 4  6 

在上述示例中,第一个使用了 pandas 使用is并确定func不是一个 transform 的代码路径,而第二个测试直到相等并确定func是一个 transform。在第一种情况下,结果的索引与输入的不同。

新行为

In [5]: df.groupby(['a']).apply(func)
Out[5]:
 a  b  c
0  1  3  5
1  2  4  6

In [6]: df.set_index(['a', 'b']).groupby(['a']).apply(func)
Out[6]:
 c
a b
1 3  5
2 4  6 

现在在这两种情况下确定func是一个 transform。在每种情况下,结果与输入具有相同的索引。### 不一致的日期字符串解析

to_datetime()dayfirst选项不是严格的,这可能导致意外的行为:

In [17]: pd.to_datetime(["31-12-2021"], dayfirst=False)
Out[17]: DatetimeIndex(['2021-12-31'], dtype='datetime64[ns]', freq=None) 

现在,如果日期字符串无法根据给定的dayfirst值解析为分隔的日期字符串(例如31-12-2012),则会发出警告。

在 concat 中忽略空列或所有 NA 列的 dtype

注意

这种行为变化已在 pandas 1.4.3 中被撤销。

当使用concat()来连接两个或多个DataFrame对象时,如果其中一个 DataFrame 为空或具有所有 NA 值,当查找连接后的 dtype 时,有时会忽略其 dtype。现在这些一致性被忽略了(GH 43507)。

In [3]: df1 = pd.DataFrame({"bar": [pd.Timestamp("2013-01-01")]}, index=range(1))
In [4]: df2 = pd.DataFrame({"bar": np.nan}, index=range(1, 2))
In [5]: res = pd.concat([df1, df2]) 

以前,在df2中的 float-dtype 会被忽略,因此结果 dtype 将是datetime64[ns]。因此,np.nan将被转换为NaT

之前的行为:

In [6]: res
Out[6]:
 bar
0 2013-01-01
1        NaT 

现在 float-dtype 受到尊重。由于这些 DataFrames 的常见 dtype 是 object,np.nan被保留。

新行为:

In [6]: res
Out[6]:
 bar
0  2013-01-01 00:00:00
1                  NaN 

现在在 value_counts 和 mode 中不再将空值强制转换为 NaN 值

Series.value_counts()Series.mode()不再将NoneNaT和其他空值强制转换为np.object_-dtype 的 NaN 值。这种行为现在与uniqueisin和其他行为一致(GH 42688)。

In [18]: s = pd.Series([True, None, pd.NaT, None, pd.NaT, None])

In [19]: res = s.value_counts(dropna=False) 

以前,所有空值都被替换为 NaN 值。

之前的行为:

In [3]: res
Out[3]:
NaN     5
True    1
dtype: int64 

现在空值不再被搅乱。

新行为:

In [20]: res
Out[20]: 
None    3
NaT     2
True    1
Name: count, dtype: int64 

在 read_csv 中的 mangle_dupe_cols 不再重命名与目标名称冲突的唯一列

read_csv()不再重命名与重复列的目标名称冲突的唯一列标签。已存在的列被跳过,即为目标列名使用下一个可用索引(GH 14704)。

In [21]: import io

In [22]: data = "a,a,a.1\n1,2,3"

In [23]: res = pd.read_csv(io.StringIO(data)) 

以前,第二列被称为a.1,而第三列也被重命名为a.1.1

之前的行为:

In [3]: res
Out[3]:
 a  a.1  a.1.1
0   1    2      3 

现在在重命名时会检查a.1是否已经存在,当更改第二列的名称时会跳过此索引。第二列改名为a.2

新行为:

In [24]: res
Out[24]: 
 a  a.2  a.1
0  1    2    3 

unstack 和 pivot_table 不再因结果超过 int32 限制而引发 ValueError

以前 DataFrame.pivot_table()DataFrame.unstack() 如果操作可以产生超过 2**31 - 1 元素的结果,将引发 ValueError。此操作现在引发一个 errors.PerformanceWarning (GH 26314)。

先前的行为:

In [3]: df = DataFrame({"ind1": np.arange(2 ** 16), "ind2": np.arange(2 ** 16), "count": 0})
In [4]: df.pivot_table(index="ind1", columns="ind2", values="count", aggfunc="count")
ValueError: Unstacked DataFrame is too big, causing int32 overflow 

新行为:

In [4]: df.pivot_table(index="ind1", columns="ind2", values="count", aggfunc="count")
PerformanceWarning: The following operation may generate 4294967296 cells in the resulting pandas object. 

groupby.apply 一致的转换检测

DataFrameGroupBy.apply()SeriesGroupBy.apply() 被设计成灵活的,允许用户执行聚合、转换、过滤,并且可以使用用户定义的函数,这些函数可能不属于任何这些类别。作为此功能的一部分,apply 将尝试检测操作是否是一个转换,在这种情况下,结果将与输入具有相同的索引。为了确定操作是否是一个转换,pandas 将输入的索引与结果的索引进行比较,并确定是否已经被改变。在 pandas 1.3 中,不同的代码路径使用不同的“改变”的定义:一些使用 Python 的 is,而其他则只测试到相等为止。

这种不一致性已经被移除,pandas 现在测试到相等为止。

In [25]: def func(x):
 ....:    return x.copy()
 ....: 

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

In [27]: df
Out[27]: 
 a  b  c
0  1  3  5
1  2  4  6 

先前的行为:

In [3]: df.groupby(['a']).apply(func)
Out[3]:
 a  b  c
a
1 0  1  3  5
2 1  2  4  6

In [4]: df.set_index(['a', 'b']).groupby(['a']).apply(func)
Out[4]:
 c
a b
1 3  5
2 4  6 

在上面的示例中,第一个使用的代码路径中 pandas 使用 is 并确定 func 不是一个转换,而第二个则测试到相等,并确定 func 是一个转换。在第一种情况下,结果的索引与输入的不同。

新行为:

In [5]: df.groupby(['a']).apply(func)
Out[5]:
 a  b  c
0  1  3  5
1  2  4  6

In [6]: df.set_index(['a', 'b']).groupby(['a']).apply(func)
Out[6]:
 c
a b
1 3  5
2 4  6 

现在在两种情况下都确定 func 是一个转换。在每种情况下,结果与输入具有相同的索引。

不兼容的后向 API 更改

增加 Python 的最低版本

pandas 1.4.0 支持 Python 3.8 及更高版本。### 增加依赖项的最低版本

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

最低版本 必需 已更改
numpy 1.18.5 X X
pytz 2020.1 X X
python-dateutil 2.8.1 X X
bottleneck 1.3.1 X
numexpr 2.7.1 X
pytest (dev) 6.0
mypy (dev) 0.930 X

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

Package Minimum Version Changed
beautifulsoup4 4.8.2 X
fastparquet 0.4.0
fsspec 0.7.4
gcsfs 0.6.0
lxml 4.5.0 X
matplotlib 3.3.2 X
numba 0.50.1 X
openpyxl 3.0.3 X
pandas-gbq 0.14.0 X
pyarrow 1.0.1 X
pymysql 0.10.1 X
pytables 3.6.1 X
s3fs 0.4.0
scipy 1.4.1 X
sqlalchemy 1.4.0 X
tabulate 0.8.7
xarray 0.15.1 X
xlrd 2.0.1 X
xlsxwriter 1.2.2 X
xlwt 1.3.0

查看依赖项和可选依赖项以获取更多信息。### 其他 API 更改

  • Index.get_indexer_for()不再接受关键字参数(除了target);在过去,如果索引不唯一,这些参数将被静默忽略 (GH 42310)

  • 由于文档字符串的更改,DataFrame.to_string()min_rows参数的位置发生了变化(GH 44304)

  • 对于DataFrameSeries的缩减操作现在在传递skipna参数为None时会引发ValueError错误 (GH 44178)

  • read_csv()read_html()在其中一个标题行仅包含Unnamed:列时不再引发错误 (GH 13054)

  • 更改了USFederalHolidayCalendar中几个节日的name属性,以匹配官方联邦节日名称,具体如下:

    • “元旦”获得所有格撇号
    • “总统日”变成“华盛顿生日”
    • “马丁·路德·金·恩博士纪念日”现在是“马丁·路德·金·恩博士生日”
    • “7 月 4 日”现在是“独立日”
    • “感恩节”现在是“感恩节”
    • “圣诞节”现在是“圣诞节”
    • 添加了“六月节国家独立日”### Python 的最低版本提高

pandas 1.4.0 支持 Python 3.8 及更高版本。

增加了依赖项的最低版本

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

包名 最低版本 必需 更改
numpy 1.18.5 X X
pytz 2020.1 X X
python-dateutil 2.8.1 X X
bottleneck 1.3.1 X
numexpr 2.7.1 X
pytest (dev) 6.0
mypy (dev) 0.930 X

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

包名 最低版本 更改
beautifulsoup4 4.8.2 X
fastparquet 0.4.0
fsspec 0.7.4
gcsfs 0.6.0
lxml 4.5.0 X
matplotlib 3.3.2 X
numba 0.50.1 X
openpyxl 3.0.3 X
pandas-gbq 0.14.0 X
pyarrow 1.0.1 X
pymysql 0.10.1 X
pytables 3.6.1 X
s3fs 0.4.0
scipy 1.4.1 X
sqlalchemy 1.4.0 X
tabulate 0.8.7
xarray 0.15.1 X
xlrd 2.0.1 X
xlsxwriter 1.2.2 X
xlwt 1.3.0

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

其他 API 变更

  • Index.get_indexer_for() 不再接受关键字参数(除了target);过去如果索引不唯一,这些参数将被静默忽略(GH 42310

  • DataFrame.to_string()min_rows参数位置的变化是由于文档字符串的更改导致的(GH 44304

  • 对于DataFrameSeries的缩减操作现在在传递skipna参数为None时引发ValueError错误(GH 44178

  • read_csv()read_html() 在其中一个标题行只包含Unnamed:列时不再引发错误(GH 13054

  • USFederalHolidayCalendar 中几个节日的 name 属性更改为与官��联邦节日名称匹配:

    • “元旦” 获得所有格符号
    • “总统日” 变为 “华盛顿生日”
    • “马丁·路德·金·恩日” 现在是 “马丁·路德·金生日”
    • “7 月 4 日” 现在是 “独立日”
    • “感恩节” 现在是 “感恩节”
    • “圣诞节” 现在是 “圣诞节”
    • 添加 “六月节国庆日”

弃用

弃用的 Int64Index、UInt64Index 和 Float64Index

Int64IndexUInt64IndexFloat64Index已被弃用,推荐使用基础Index类,并将在 Pandas 2.0 中移除(GH 43028)。

若要构建数值索引,可以使用基础Index类,而不是指定数据类型(这也适用于较旧的 pandas 版本):

# replace
pd.Int64Index([1, 2, 3])
# with
pd.Index([1, 2, 3], dtype="int64") 

若要检查索引对象的数据类型,可以用检查 dtype 替换 isinstance 检查:

# replace
isinstance(idx, pd.Int64Index)
# with
idx.dtype == "int64" 

目前,为了保持向后兼容性,对 Index 的调用将继续在给定数值数据时返回 Int64IndexUInt64IndexFloat64Index,但在未来,将返回一个 Index

当前行为

In [1]: pd.Index([1, 2, 3], dtype="int32")
Out [1]: Int64Index([1, 2, 3], dtype='int64')
In [1]: pd.Index([1, 2, 3], dtype="uint64")
Out [1]: UInt64Index([1, 2, 3], dtype='uint64') 

未来行为

In [3]: pd.Index([1, 2, 3], dtype="int32")
Out [3]: Index([1, 2, 3], dtype='int32')
In [4]: pd.Index([1, 2, 3], dtype="uint64")
Out [4]: Index([1, 2, 3], dtype='uint64') 
```  ### 弃用的 DataFrame.append 和 Series.append

`DataFrame.append()` 和 `Series.append()` 已被弃用,将在未来版本中移除。请使用 `pandas.concat()` 替代([GH 35407](https://github.com/pandas-dev/pandas/issues/35407))。

*弃用语法*

```py
In [1]: pd.Series([1, 2]).append(pd.Series([3, 4])
Out [1]:
<stdin>:1: FutureWarning: The series.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
0    1
1    2
0    3
1    4
dtype: int64

In [2]: df1 = pd.DataFrame([[1, 2], [3, 4]], columns=list('AB'))
In [3]: df2 = pd.DataFrame([[5, 6], [7, 8]], columns=list('AB'))
In [4]: df1.append(df2)
Out [4]:
<stdin>:1: FutureWarning: The series.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
 A  B
0  1  2
1  3  4
0  5  6
1  7  8 

推荐语法

In [28]: pd.concat([pd.Series([1, 2]), pd.Series([3, 4])])
Out[28]: 
0    1
1    2
0    3
1    4
dtype: int64

In [29]: df1 = pd.DataFrame([[1, 2], [3, 4]], columns=list('AB'))

In [30]: df2 = pd.DataFrame([[5, 6], [7, 8]], columns=list('AB'))

In [31]: pd.concat([df1, df2])
Out[31]: 
 A  B
0  1  2
1  3  4
0  5  6
1  7  8 
```  ### 其他弃用

+   弃用 `Index.is_type_compatible()`([GH 42113](https://github.com/pandas-dev/pandas/issues/42113))

+   弃用 `method` 参数在 `Index.get_loc()` 中,使用 `index.get_indexer([label], method=...)` 替代([GH 42269](https://github.com/pandas-dev/pandas/issues/42269))

+   当索引为不包含键的 `Float64Index`、不包含键的 `IntervalIndex` 或不包含键的具有不包含键的 `Float64Index` 级别的 `MultiIndex` 时,已弃用在 `Series.__setitem__()` 中将整数键视为位置参数的处理方式([GH 33469](https://github.com/pandas-dev/pandas/issues/33469))

+   弃用了将`numpy.datetime64`对象视为 UTC 时间的功能,当传递给带有时区的`Timestamp`构造函数时。在将来的版本中,这些对象将被视为墙上时间。要保留旧的行为,请使用`Timestamp(dt64).tz_localize("UTC").tz_convert(tz)`([GH 24559](https://github.com/pandas-dev/pandas/issues/24559))

+   弃用了在使用`MultiIndex`的层级上通过序列索引时忽略缺失标签的功能([GH 42351](https://github.com/pandas-dev/pandas/issues/42351))

+   创建不带`dtype`的空`Series`现在将引发更明显的`FutureWarning`而不是`DeprecationWarning`([GH 30017](https://github.com/pandas-dev/pandas/issues/30017))

+   弃用了在`Index.get_slice_bound()`、`Index.slice_indexer()`和`Index.slice_locs()`中的`kind`参数;在将来的版本中,传递`kind`将引发错误([GH 42857](https://github.com/pandas-dev/pandas/issues/42857))

+   弃用了在`Rolling`、`Expanding`和`EWM`聚合中丢弃无关列的功能([GH 42738](https://github.com/pandas-dev/pandas/issues/42738))

+   弃用了使用非唯一`Index`重新索引的功能`Index.reindex()`([GH 42568](https://github.com/pandas-dev/pandas/issues/42568))

+   弃用了`Styler.render()`,推荐使用`Styler.to_html()`([GH 42140](https://github.com/pandas-dev/pandas/issues/42140))

+   弃用了`Styler.hide_index()`和`Styler.hide_columns()`,推荐使用`Styler.hide()`([GH 43758](https://github.com/pandas-dev/pandas/issues/43758))

+   弃用了在`DataFrame.ewm()`中将字符串列标签传递给`times`的功能([GH 43265](https://github.com/pandas-dev/pandas/issues/43265))

+   弃用了`DataFrame.between_time()`中的`include_start`和`include_end`参数;在未来版本中传递`include_start`或`include_end`将引发异常([GH 40245](https://github.com/pandas-dev/pandas/issues/40245))

+   弃用了对`read_csv()`、`read_table()`和`read_excel()`中的`squeeze`参数。用户应该使用`.squeeze("columns")`在之后压缩`DataFrame`([GH 43242](https://github.com/pandas-dev/pandas/issues/43242))

+   弃用了`SparseArray`构造中的`index`参数([GH 23089](https://github.com/pandas-dev/pandas/issues/23089))

+   弃用了`date_range()`和`bdate_range()`中的`closed`参数,改为使用`inclusive`参数;在未来版本中传递`closed`将引发异常([GH 40245](https://github.com/pandas-dev/pandas/issues/40245))

+   弃用了`Rolling.validate()`、`Expanding.validate()`和`ExponentialMovingWindow.validate()`([GH 43665](https://github.com/pandas-dev/pandas/issues/43665))

+   在`Series.transform`和`DataFrame.transform`中,对于使用字典时引发`TypeError`的列,弃用了静默删除行为([GH 43740](https://github.com/pandas-dev/pandas/issues/43740))

+   在`Series.aggregate()`、`DataFrame.aggregate()`、`Series.groupby.aggregate()`和`DataFrame.groupby.aggregate()`中,对于使用列表时引发`TypeError`、`DataError`和部分`ValueError`的列,弃用了静默删除行为([GH 43740](https://github.com/pandas-dev/pandas/issues/43740))

+   当将时区感知值设置到时区不匹配的`Series`或`DataFrame`列时,弃用了强制转换行为。先前会转换为对象 dtype。在未来的版本中,插入的值将被转换为系列或列的现有时区([GH 37605](https://github.com/pandas-dev/pandas/issues/37605))

+   当将具有不匹配时区的项目传递给`DatetimeIndex.insert()`、`DatetimeIndex.putmask()`、`DatetimeIndex.where()`、`DatetimeIndex.fillna()`、`Series.mask()`、`Series.where()`、`Series.fillna()`、`Series.shift()`、`Series.replace()`、`Series.reindex()`(以及`DataFrame`的列类似项)时,弃用了转换行为。过去,这会将其转换为对象`dtype`。在将来的版本中,这些将会将传递的项目转换为索引或系列的时区([GH 37605](https://github.com/pandas-dev/pandas/issues/37605), [GH 44940](https://github.com/pandas-dev/pandas/issues/44940))

+   在`read_csv()`和`read_table()`中弃用`prefix`关键字参数,在将来的版本中将删除该参数([GH 43396](https://github.com/pandas-dev/pandas/issues/43396))

+   在`concat()`中,弃用对`sort`传递非布尔值的方式([GH 41518](https://github.com/pandas-dev/pandas/issues/41518))

+   对于`read_fwf()`除了`filepath_or_buffer`之外,弃用将参数作为位置参数传递的方法([GH 41485](https://github.com/pandas-dev/pandas/issues/41485))

+   对于`read_xml()`除了`path_or_buffer`之外,弃用将参数作为位置参数传递的方法([GH 45133](https://github.com/pandas-dev/pandas/issues/45133))

+   对于`DataFrame.mad()`和`Series.mad()`,弃用传递`skipna=None`的方式,改为传递`skipna=True`([GH 44580](https://github.com/pandas-dev/pandas/issues/44580))

+   弃用带有字符串“now”的`to_datetime()`的行为,使用`utc=False`;在将来的版本中,这将匹配`Timestamp("now")`,进而匹配`Timestamp.now()`返回的本地时间([GH 18705](https://github.com/pandas-dev/pandas/issues/18705))

+   弃用`DateOffset.apply()`的行为,改用`offset + other`([GH 44522](https://github.com/pandas-dev/pandas/issues/44522))

+   已弃用`Index.copy()`中的参数`names`([GH 44916](https://github.com/pandas-dev/pandas/issues/44916))

+   现在为`DataFrame.to_latex()`显示弃用警告,指示参数签名可能会在将来的版本中更改,并模拟更多地模拟`Styler.to_latex()`的参数([GH 44411](https://github.com/pandas-dev/pandas/issues/44411))

+   在布尔型和数值型之间的对象之间的`concat()`行为已弃用;在将来的版本中,这些将转换为对象 dtype,而不是将布尔值强制转换为数值值([GH 39817](https://github.com/pandas-dev/pandas/issues/39817))

+   已弃用`Categorical.replace()`,请使用`Series.replace()`([GH 44929](https://github.com/pandas-dev/pandas/issues/44929))

+   已弃用将`set`或`dict`作为`DataFrame.loc.__setitem__()`、`DataFrame.loc.__getitem__()`、`Series.loc.__setitem__()`、`Series.loc.__getitem__()`、`DataFrame.__getitem__()`、`Series.__getitem__()`和`Series.__setitem__()`的索引器进行传递([GH 42825](https://github.com/pandas-dev/pandas/issues/42825))

+   已弃用使用布尔键的`Index.__getitem__()`;使用`index.values[key]`获取旧行为([GH 44051](https://github.com/pandas-dev/pandas/issues/44051))

+   已弃用在`DataFrame.where()`中逐列进行降级处理的整数类型([GH 44597](https://github.com/pandas-dev/pandas/issues/44597))

+   已弃用`DatetimeIndex.union_many()`,请使用`DatetimeIndex.union()`([GH 44091](https://github.com/pandas-dev/pandas/issues/44091))

+   已弃用`Groupby.pad()`,推荐使用`Groupby.ffill()`([GH 33396](https://github.com/pandas-dev/pandas/issues/33396))

+   已弃用`Groupby.backfill()`,推荐使用`Groupby.bfill()`([GH 33396](https://github.com/pandas-dev/pandas/issues/33396))

+   已弃用`Resample.pad()`,推荐使用`Resample.ffill()`([GH 33396](https://github.com/pandas-dev/pandas/issues/33396))

+   已弃用`Resample.backfill()`,推荐使用`Resample.bfill()`([GH 33396](https://github.com/pandas-dev/pandas/issues/33396))

+   在`DataFrame.rank()`中已弃用`numeric_only=None`;在将来的版本中,`numeric_only`必须是`True`或`False`(默认值)([GH 45036](https://github.com/pandas-dev/pandas/issues/45036))

+   弃用了 `Timestamp.utcfromtimestamp()` 的行为,在未来将返回一个带有时区信息的 UTC `Timestamp` ([GH 22451](https://github.com/pandas-dev/pandas/issues/22451))

+   弃用了 `NaT.freq()` ([GH 45071](https://github.com/pandas-dev/pandas/issues/45071))

+   当传递包含 `NaN` 的浮点数据和一个整数数据类型时,`Series` 和 `DataFrame` 构造的弃用行为将在未来版本中引发错误 ([GH 40110](https://github.com/pandas-dev/pandas/issues/40110))

+   弃用了当 `name=None` 时忽略 `name` 参数的 `Series.to_frame()` 和 `Index.to_frame()` 的行为。目前,这意味着保留现有名称,但在未来,显式传递 `name=None` 将在生成的 DataFrame 中将 `None` 设置为列的名称 ([GH 44212](https://github.com/pandas-dev/pandas/issues/44212))  ### 弃用 Int64Index、UInt64Index 和 Float64Index

`Int64Index`、`UInt64Index` 和 `Float64Index` 已被弃用,推荐使用基础 `Index` 类,并将在 Pandas 2.0 中移除 ([GH 43028](https://github.com/pandas-dev/pandas/issues/43028)).

为构造数值索引,您可以使用基础 `Index` 类,而不是指定数据类型(这也适用于较旧的 pandas 版本):

```py
# replace
pd.Int64Index([1, 2, 3])
# with
pd.Index([1, 2, 3], dtype="int64") 

为了检查索引对象的数据类型,您可以用检查 dtype 替换 isinstance 检查:

# replace
isinstance(idx, pd.Int64Index)
# with
idx.dtype == "int64" 

目前,为了保持向后兼容性,对 Index 的调用将继续在给定数值数据时返回 Int64IndexUInt64IndexFloat64Index,但在未来,将返回一个 Index

当前行为:

In [1]: pd.Index([1, 2, 3], dtype="int32")
Out [1]: Int64Index([1, 2, 3], dtype='int64')
In [1]: pd.Index([1, 2, 3], dtype="uint64")
Out [1]: UInt64Index([1, 2, 3], dtype='uint64') 

未来行为:

In [3]: pd.Index([1, 2, 3], dtype="int32")
Out [3]: Index([1, 2, 3], dtype='int32')
In [4]: pd.Index([1, 2, 3], dtype="uint64")
Out [4]: Index([1, 2, 3], dtype='uint64') 

弃用 DataFrame.append 和 Series.append

DataFrame.append()Series.append() 已被弃用,并将在未来版本中移除。请改用 pandas.concat() 代替 (GH 35407).

弃用的语法

In [1]: pd.Series([1, 2]).append(pd.Series([3, 4])
Out [1]:
<stdin>:1: FutureWarning: The series.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
0    1
1    2
0    3
1    4
dtype: int64

In [2]: df1 = pd.DataFrame([[1, 2], [3, 4]], columns=list('AB'))
In [3]: df2 = pd.DataFrame([[5, 6], [7, 8]], columns=list('AB'))
In [4]: df1.append(df2)
Out [4]:
<stdin>:1: FutureWarning: The series.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
 A  B
0  1  2
1  3  4
0  5  6
1  7  8 

推荐的语法

In [28]: pd.concat([pd.Series([1, 2]), pd.Series([3, 4])])
Out[28]: 
0    1
1    2
0    3
1    4
dtype: int64

In [29]: df1 = pd.DataFrame([[1, 2], [3, 4]], columns=list('AB'))

In [30]: df2 = pd.DataFrame([[5, 6], [7, 8]], columns=list('AB'))

In [31]: pd.concat([df1, df2])
Out[31]: 
 A  B
0  1  2
1  3  4
0  5  6
1  7  8 

其他弃用

  • 弃用了 Index.is_type_compatible() (GH 42113)

  • 废弃了 Index.get_loc() 中的 method 参数,请改用 index.get_indexer([label], method=...)GH 42269)。

  • 废弃了在 Series.__setitem__() 中将整数键视为位置键的处理方式,当索引是不包含键的 Float64Index,一个不包含键的 IntervalIndex 或一个具有不包含键的前导 Float64Index 级别的 MultiIndex 时(GH 33469)。

  • 废弃了将 numpy.datetime64 对象视为 UTC 时间传递给 Timestamp 构造函数时的处理方式。在将来的版本中,这些将被视为墙上时间。要保留旧行为,请使用 Timestamp(dt64).tz_localize("UTC").tz_convert(tz)GH 24559)。

  • 废弃了在 MultiIndex 层级上使用标签序列进行索引时忽略缺失标签的操作(GH 42351)。

  • 创建一个没有 dtype 的空 Series 现在将引发更明显的 FutureWarning 而不是 DeprecationWarningGH 30017)。

  • 废弃了 Index.get_slice_bound()Index.slice_indexer()Index.slice_locs() 中的 kind 参数;在将来的版本中传递 kind 将引发错误(GH 42857)。

  • 废弃了在 RollingExpandingEWM 聚合中放弃无用列的操作(GH 42738)。

  • 废弃了具有非唯一性的 Index.reindex(),请使用 IndexGH 42568)。

  • 废弃了 Styler.render(),推荐使用 Styler.to_html()GH 42140)。

  • 废弃了Styler.hide_index()Styler.hide_columns(),推荐使用Styler.hide()GH 43758

  • 废弃了在DataFrame.ewm()中将字符串列标签传递给times的做法(GH 43265

  • 废弃了DataFrame.between_time()中的include_startinclude_end参数;在将来的版本中,传递include_startinclude_end将会引发错误(GH 40245

  • 废弃了read_csv()read_table()read_excel()中的squeeze参数。用户应该之后使用.squeeze("columns")来压缩DataFrameGH 43242

  • 废弃了SparseArray构造函数中的index参数(GH 23089

  • 废弃了date_range()bdate_range()中的closed参数,推荐使用inclusive参数;在将来的版本中,传递closed将会引发错误(GH 40245

  • 废弃了Rolling.validate()Expanding.validate()ExponentialMovingWindow.validate()GH 43665

  • 废弃了在使用字典时,Series.transformDataFrame.transform中引发TypeError的列的静默删除(GH 43740

  • 在使用列表时,当Series.aggregate()DataFrame.aggregate()Series.groupby.aggregate()DataFrame.groupby.aggregate()中出现TypeErrorDataError和某些情况下的ValueError时,弃用了对引发异常的列进行静默丢弃的行为(GH 43740

  • 当将带有时区信息的值设置到时区不匹配的SeriesDataFrame列时,弃用了强制转换行为。以前会转换为对象数据类型。在未来的版本中,插入的值将被转换为系列或列的现有时区(GH 37605

  • 当将带有不匹配时区的项目传递给DatetimeIndex.insert()DatetimeIndex.putmask()DatetimeIndex.where()DatetimeIndex.fillna()Series.mask()Series.where()Series.fillna()Series.shift()Series.replace()Series.reindex()(以及DataFrame列的类似情况)时,弃用了强制转换行为。过去会转换为对象dtype。在未来的版本中,这些将会将传递的项目转换为索引或系列的时区(GH 37605GH 44940)

  • read_csv()read_table()中弃用了prefix关键字参数,在未来版本中将删除该参数(GH 43396

  • concat()中弃用了将非布尔参数传递给sortGH 41518

  • read_fwf()中弃用了将参数作为位置参数传递给filepath_or_buffer之外的其他参数(GH 41485

  • 废弃了除path_or_buffer之外的read_xml()方法的位置参数传递方式(GH 45133

  • 废弃了为DataFrame.mad()Series.mad()传递skipna=None的方式,改为传递skipna=TrueGH 44580

  • 废弃了带有字符串“now”的to_datetime()方法的行为,其中utc=False;在将来的版本中,这将与Timestamp("now")匹配,进而匹配Timestamp.now()返回的本地时间(GH 18705

  • 废弃了DateOffset.apply()方法,改用offset + other代替(GH 44522

  • 废弃了Index.copy()方法的names参数(GH 44916

  • 现在为DataFrame.to_latex()显示了一个废弃警告,指示参数签名可能会改变,并在未来版本中模拟更多Styler.to_latex()的参数(GH 44411

  • 废弃了在布尔类型和数值类型之间进行concat()的行为;在将来的版本中,这些将转换为对象类型,而不是将布尔值强制转换为数值(GH 39817

  • 废弃了Categorical.replace()方法,改用Series.replace()代替(GH 44929

  • 废弃了将setdict作为索引器传递给DataFrame.loc.__setitem__()DataFrame.loc.__getitem__()Series.loc.__setitem__()Series.loc.__getitem__()DataFrame.__getitem__()Series.__getitem__()Series.__setitem__()的方式(GH 42825

  • 废弃了使用布尔键的Index.__getitem__()方法;使用index.values[key]来获取旧的行为(GH 44051

  • 废弃了DataFrame.where()方法中按列逐列进行降级转换的整数类型参数(GH 44597

  • 弃用DatetimeIndex.union_many(),请使用DatetimeIndex.union()代替(GH 44091

  • 弃用Groupby.pad(),改用Groupby.ffill()GH 33396

  • 弃用Groupby.backfill(),改用Groupby.bfill()GH 33396

  • 弃用Resample.pad(),改用Resample.ffill()GH 33396

  • 弃用Resample.backfill(),改用Resample.bfill()GH 33396

  • 弃用DataFrame.rank()中的numeric_only=None;在将来的版本中,numeric_only必须是TrueFalse(默认值)(GH 45036

  • 弃用Timestamp.utcfromtimestamp()的行为,在未来将返回一个带有时区的 UTC TimestampGH 22451

  • 弃用NaT.freq()GH 45071

  • 弃用当传递包含NaN的浮点数据和一个整数 dtype 时,SeriesDataFrame构造的行为将忽略 dtype 参数;在将来的版本中,这将引发错误(GH 40110

  • 弃用Series.to_frame()Index.to_frame()的行为,当name=None时忽略name参数。目前,这意味着保留现有名称,但在将来,显式传递name=None将在生成的 DataFrame 中将None设置为列的名称(GH 44212

性能改进

  • DataFrameGroupBy.sample()SeriesGroupBy.sample()中的性能改进,特别是在提���weights参数时(GH 34483

  • 在将非字符串数组转换为字符串数组时提高了性能(GH 34483

  • 对用户定义函数进行了性能提升,包括DataFrameGroupBy.transform()SeriesGroupBy.transform()GH 41598

  • 在构建DataFrame对象时提高了性能(GH 42631GH 43142GH 43147GH 43307GH 43144GH 44826

  • 当提供了fill_value参数时,在DataFrameGroupBy.shift()SeriesGroupBy.shift()中提高了性能(GH 26615

  • 在没有缺失值的数据上,通过method=pearsonDataFrame.corr()进行了性能提升(GH 40956

  • 在一些DataFrameGroupBy.apply()SeriesGroupBy.apply()操作中提高了性能(GH 42992GH 43578)

  • read_stata()中提高了性能(GH 43059GH 43227

  • read_sas()中提高了性能(GH 43333

  • to_datetime() 中使用 uint 数据类型的性能改进(GH 42606

  • to_datetime() 中将 infer_datetime_format 设置为 True 的性能改进(GH 43901

  • Series.sparse.to_coo() 的性能改进(GH 42880

  • 使用 UInt64Index 进行索引的性能改进(GH 43862

  • 使用 Float64Index 进行索引的性能改进(GH 43705

  • 使用非唯一 Index 进行索引的性能改进(GH 43792

  • 使用列表式索引器在 MultiIndex 上进行索引的性能改进(GH 43370

  • 索引中使用 MultiIndex 索引器的性能改进(GH 43370

  • DataFrameGroupBy.quantile()SeriesGroupBy.quantile() 的性能改进(GH 43469, GH 43725

  • DataFrameGroupBy.count()SeriesGroupBy.count() 的性能改进(GH 43730, GH 43694

  • DataFrameGroupBy.any()SeriesGroupBy.any()DataFrameGroupBy.all()SeriesGroupBy.all()中的性能改进(GH 43675GH 42841)

  • DataFrameGroupBy.std()SeriesGroupBy.std()中的性能改进(GH 43115GH 43576)

  • DataFrameGroupBy.cumsum()SeriesGroupBy.cumsum()中的性能改进(GH 43309)

  • SparseArray.min()SparseArray.max()不再需要转换为密集数组(GH 43526

  • 使用step=1slice索引进入SparseArray不再需要转换为密集数组(GH 43777)

  • 使用allow_fill=False改进SparseArray.take()的性能(GH 43654)

  • Rolling.mean()Expanding.mean()Rolling.sum()Expanding.sum()Rolling.max()Expanding.max()Rolling.min()Expanding.min() 使用 engine="numba" 的性能改进(GH 43612, GH 44176, GH 45170

  • pandas.read_csv() 在文件编码为 UTF-8 时使用 memory_map=True 的性能提升(GH 43787

  • RangeIndex.sort_values() 的性能改进覆盖 Index.sort_values()GH 43666

  • RangeIndex.insert() 的性能改进(GH 43988

  • Index.insert() 的性能改进(GH 43953

  • DatetimeIndex.tolist() 的性能改进(GH 43823

  • DatetimeIndex.union() 的性能改进(GH 42353

  • Series.nsmallest() 的性能改进(GH 43696

  • DataFrame.insert() 的性能改进 (GH 42998)

  • DataFrame.dropna() 的性能改进 (GH 43683)

  • DataFrame.fillna() 的性能改进 (GH 43316)

  • DataFrame.values() 的性能改进 (GH 43160)

  • DataFrame.select_dtypes() 的性能改进 (GH 42611)

  • DataFrame 的性能改进 (GH 43185, GH 43243, GH 43311, GH 43609)

  • Series.unstack()DataFrame.unstack() 的性能改进 (GH 43335, GH 43352, GH 42704, GH 43025)

  • Series.to_frame() 的性能改进 (GH 43558)

  • Series.mad() 的性能改进 (GH 43010)

  • merge() 的性能改进 (GH 43332)

  • 当索引列为日期时间且已格式化时,to_csv() 的性能改进 (GH 39413)

  • to_csv() 在包含大量未使用级别的 MultiIndex 时的性能改进 (GH 37484)

  • read_csv() 中的性能改进,当 index_col 设定为数字列时 (GH 44158)

  • concat() 中的性能改进 (GH 43354)

  • SparseArray.__getitem__() 中的性能改进 (GH 23122)

  • 在从类似数组对象(如 Pytorch 张量)构造 DataFrame 时的性能改进 (GH 44616)

Bug 修复

Categorical

  • 在设置 dtype 不兼容的值到 Categorical(或由 Categorical 支持的 SeriesDataFrame)时的 Bug,引发 ValueError 而不是 TypeError (GH 41919)

  • Categorical.searchsorted() 中的 Bug,当传递不兼容的 dtype 值时引发 KeyError 而不是 TypeError (GH 41919)

  • Categorical.astype() 中的 Bug,将日期时间和 Timestamp 强制转换为 dtype object 的 int (GH 44930)

  • Series.where() 中的 Bug,当传递不兼容的 dtype 值时引发 ValueError 而不是 TypeError (GH 41919)

  • Categorical.fillna() 中的 Bug,当传递不兼容的 dtype 值时引发 ValueError 而不是 TypeError (GH 41919)

  • Categorical.fillna() 中的 Bug,当用非类别元组填充时引发 ValueError 而不是 TypeError (GH 41919)

Datetimelike

  • DataFrame 构造函数中的 Bug,不必要地复制非日期时间样式的 2D 对象数组 (GH 39272)

  • to_datetime()中的 Bug,使用 formatpandas.NA 会引发 ValueError (GH 42957)

  • to_datetime() 在给定的 dayfirst 选项无法被尊重时会默默地交换 MM/DD/YYYYDD/MM/YYYY 格式,如果给定的是分隔的日期字符串(例如 31-12-2012),现在将会引发警告 (GH 12585)

  • start = end 且一侧关闭时,date_range()bdate_range() 未返回正确的右边界(GH 43394

  • 在对带有 DatetimeArrayTimedeltaArrayDatetimeIndexTimedeltaIndex 进行原地加法和减法时存在的错误(GH 43904

  • 在时区感知的 DatetimeIndex 上调用 np.isnannp.isfinitenp.isinf 时不正确地引发 TypeErrorGH 43917

  • 从混合时区的日期时间字符串构造Series时存在的错误,部分推断日期时间值不正确(GH 40111

  • Tick 对象和 np.timedelta64 对象相加时存在的错误,不正确地引发异常而不是返回 TimedeltaGH 44474

  • np.maximum.reducenp.minimum.reduce 现在在操作带有 datetime64[ns]timedelta64[ns] 数据类型的 SeriesDataFrameIndex 时,正确返回 TimestampTimedelta 对象(GH 43923

  • np.timedelta64 对象添加到 BusinessDayCustomBusinessDay 对象时不正确地引发异常(GH 44532

  • 在向带有 dtype='object'Index 中插入 np.datetime64np.timedelta64tuple 时,存在的错误,负 loc 添加 None 并替换现有值(GH 44509

  • Timestamp.to_pydatetime() 中存在的错误,未能保留 fold 属性(GH 45087

  • 使用 DatetimeTZDtypeSeries.mode() 错误地返回时区无关,并且使用 PeriodDtype 错误地引发错误 (GH 41927)

  • 在使用与 datetime 类似的 dtype 时,reindex() 中的固定回归引发错误(或者在使用 datetime.date 作为填充值时未引发停用警告)现已修复 (GH 42921)

  • DateOffset 的加法存在 Bug,其中 offset.nanoseconds 不会包含在结果中 (GH 43968, GH 36589)

  • Timestamp.fromtimestamp() 中的 Bug 不支持 tz 参数 (GH 45083)

  • 从具有不匹配的索引 dtypes 的 Series 字典构造 DataFrame 中存在 Bug,有时取决于传递的字典的顺序会引发错误 (GH 44091)

  • 在某些 DST 过渡期间,Timestamp 的哈希存在 Bug 导致分段错误 (GH 33931GH 40817)

Timedelta

  • 在所有-NaT TimeDeltaIndexSeriesDataFrame 列的除法中,使用对象 dtype 数组的失败推断结果为 timedelta64-dtype 的 Bug (GH 39750)

  • 用标量执行 timedelta64[ns] 数据的 floor division 返回垃圾值的 Bug (GH 44466)

  • Timedelta 中的 Bug 现在正确地考虑了任何 kwarg 的纳秒贡献 (GH 43764, GH 45227)

时区

  • infer_datetime_format=True 的情况下,to_datetime() 无法正确解析零 UTC 偏移(Z)的 Bug (GH 41047)

  • 在带有 CategoricalIndexSeries 中,Series.dt.tz_convert() 会重置索引,这是一个错误(GH 43080

  • 在减去两个具有不匹配时区的时区感知对象时,TimestampDatetimeIndex 会错误地引发 TypeErrorGH 31793

数字

  • 对整数列表或元组进行地板除法时出现错误,会引发Series异常升高(GH 44674

  • method="first" 时,DataFrame.rank()object 列上引发 ValueErrorGH 41931

  • na_option="bottom"na_option="top 使用时,DataFrame.rank() 将缺失值和极端值视为相等(例如 np.nannp.inf),导致结果错误(GH 41931

  • 当选项 compute.use_numexpr 设为 False 时,仍然使用numexpr引擎会出现错误(GH 32556

  • _constructor() 属性是子类本身之外的可调用时,在与子类进行 DataFrame 算术运算时出现错误(GH 43201

  • 在涉及 RangeIndex 的算术运算中,结果的 name 会出现错误(GH 43962

  • 在操作涉及具有匹配 NA 或匹配元组名称的操作数的 Series 时,结果可能会有错误的 nameGH 44459

  • IntegerDtypeBooleanDtype 数组与 NA 标量进行除法时,会出现错误(GH 44685

  • 将具有 FloatingDtypeSeries 与 timedelta 类型的标量相乘时,会出现错误(GH 44772

转换

  • 当传递一个列表,其中既包含足够小以转换为 int64 的正整数,又包含 int64 无法容纳的整数时,UInt64Index构造器中的错误(GH 42201

  • int64类型时,Series构造器对缺失值返回0,对bool类型返回False的错误(GH 43017GH 43018

  • 从包含Series对象的PandasArray构造一个DataFrame时的错误,行为与等效的np.ndarray不同(GH 43986

  • IntegerDtype不允许从字符串 dtype 进行强制转换的错误(GH 25472

  • 使用arg:xr.DataArray和指定unit="ns"时,to_datetime()引发TypeError的错误(GH 44053

  • 当子类没有重载_constructor_sliced()时,DataFrame.convert_dtypes()中的错误未返回正确的类型(GH 43201

  • DataFrame.astype()中的错误未从原始DataFrame传播attrsGH 44414

  • DataFrame.convert_dtypes()中的错误导致columns.names丢失(GH 41435

  • 从 pyarrow 数据构造IntegerArray失败时未验证 dtype 的错误(GH 44891

  • Series.astype()中的错误不允许从PeriodDtype转换为datetime64 dtype,与PeriodIndex行为不一致(GH 45038

字符串

  • 在不安装 pyarrow 时,检查string[pyarrow] dtype 的错误错误地引发ImportErrorGH 44276

区间

  • 在使用IntervalDtypeSeries.where()中存在 Bug,当where调用不应该替换任何内容时,错误地引发异常 (GH 44181)

索引

  • 在提供了 levelSeries.rename()中存在 Bug,与MultiIndex一起使用 (GH 43659)

  • 当对象的Index的长度大于一但只有一个唯一值时,在DataFrame.truncate()Series.truncate()中存在 Bug (GH 42365)

  • 当使用一个元组进行索引,其中一个级别也是一个元组时,在Series.loc()DataFrame.loc()中存在一个 Bug,导致出现 MultiIndex (GH 27591)

  • 当第一个级别只包含 np.nan 值的MultiIndex中使用Series.loc()存在 Bug (GH 42055)

  • 当在带有DatetimeIndexSeriesDataFrame上通过字符串进行索引时存在一个 Bug,返回类型取决于索引是否单调(GH 24892

  • 当索引在一个包含日期时间类字符串的元组中时,在MultiIndex上存在 Bug,未能删除标量级别 (GH 42476)

  • 当传递一个升序值时,在DataFrame.sort_values()Series.sort_values()中存在 Bug,未能引发或错误引发ValueError (GH 41634)

  • 使用布尔索引更新 pandas.Series 的值时出现的错误,该布尔索引是通过使用 pandas.DataFrame.pop() 创建的 (GH 42530)

  • 当索引包含多个 np.nan 时,Index.get_indexer_non_unique() 中的错误 (GH 35392)

  • DataFrame.query() 中的错误未能处理反引号列名中的度符号,例如 Temp(°C),在查询 DataFrame 时使用表达式导致错误 (GH 42826)

  • DataFrame.drop() 中的错误,当引发 KeyError 时,错误消息没有显示带有逗号的丢失标签 (GH 42881)

  • 当安装了 numexpr 包时,查询字符串中的方法调用会导致 DataFrame.query() 中的错误 (GH 22435)

  • DataFrame.nlargest()Series.nlargest() 中的错误,排序结果不包括包含 np.nan 的索引 (GH 28984)

  • 在非唯一对象数据类型 Index 上进行索引时的错误,使用 NA 标量(例如 np.nan) (GH 43711)

  • DataFrame.__setitem__() 中的错误,当新的数据类型和旧的数据类型匹配时,错误地写入现有列的数组而不是设置新数组 (GH 43406)

  • 将浮点数值设置到整数类型的 Series 中时,如果这些值可以无损转换为整数,则设置不会在原地生效 (GH 44316)

  • Series.__setitem__() 中,对象数据类型的错误,当设置一个大小和 dtype=’datetime64[ns]’ 或 dtype=’timedelta64[ns]’ 匹配的数组时,错误地将日期时间/时间增量转换为整数 (GH 43868)

  • DataFrame.sort_index()中的错误,当ignore_index=True时,如果索引已经排序,则不会被尊重(GH 43591

  • Index.get_indexer_non_unique()中的错误,当索引包含多个np.datetime64("NaT")np.timedelta64("NaT")时(GH 43869

  • 在将标量Interval值设置到具有IntervalDtypeSeries中时出现的错误,当标量的边是浮点数而值的边是整数时(GH 44201

  • 在将可以解析为日期时间的字符串-backed Categorical 值设置为由DatetimeArray支持的DatetimeArraySeriesDataFrame列时出现的错误,无法解析这些字符串(GH 44236

  • Series.__setitem__()中的错误,当整数数据类型不是int64时,使用range对象设置时会不必要地向上转换为int64GH 44261

  • Series.__setitem__()中的错误,使用布尔掩码索引器设置长度为 1 的类似列表值时,会错误地广播该值(GH 44265

  • Series.reset_index()中的错误,在dropinplace设置为True时不忽略name参数(GH 44575

  • DataFrame.loc.__setitem__()DataFrame.iloc.__setitem__()中出现的错误,混合数据类型有时无法就地操作(GH 44345

  • DataFrame.loc.__getitem__()中的错误,当使用布尔键选择单个列时错误地引发KeyErrorGH 44322)。

  • 在设置DataFrame.iloc()时出现的错误,当只有一个ExtensionDtype列并设置 2D 值时,例如df.iloc[:] = df.values,会错误地引发问题(GH 44514

  • 使用 DataFrame.iloc() 设置单个 ExtensionDtype 列和元组数组作为索引器时,设置值时出现 Bug(GH 44703

  • 使用 lociloc 在具有负步长的切片上对列进行索引时,ExtensionDtype 列中的 Bug 不正确地引发错误(GH 44551

  • DataFrame.loc.__setitem__() 中的 Bug 在索引器完全为 False 时更改了 dtype(GH 37550

  • IntervalIndex.get_indexer_non_unique() 中的 Bug 返回布尔掩码而不是整数数组,用于非唯一和非单调索引(GH 44084

  • IntervalIndex.get_indexer_non_unique() 中的 Bug 未正确处理 dtype 为 'object' 且带有 NaN 的目标(GH 44482

  • 修复了单列 np.matrix 添加到 DataFrame 时不再强制转换为 1d np.ndarray 的回归问题(GH 42376

  • 使用整数的 CategoricalIndexSeries.__getitem__() 中的 Bug 将整数列表视为位置索引器,与单个标量整数的行为不一致(GH 15470, GH 14865

  • 在将浮点数或整数设置为整数类型的 Series 时,Series.__setitem__() 中的 Bug 在必要时未进行上转以保留精度(GH 45121

  • DataFrame.iloc.__setitem__() 中的 Bug 忽略了轴参数(GH 45032

缺失

  • DataFrame.fillna() 中使用 limit 但没有 method 时,忽略了 axis='columns'axis = 1GH 40989, GH 17399

  • 在使用类似字典的 value 和重复列名时,DataFrame.fillna() 中的 Bug 未替换缺失值(GH 43476)

  • 使用字典中的 np.datetime64 作为值并且 dtype='timedelta64[ns]' 构建 DataFrame 时出现 Bug,或者反之,不正确地转换而不是引发错误(GH 44428

  • Series.interpolate()DataFrame.interpolate() 中存在错误,使用 inplace=True 时没有直接在底层数组中写入数据(GH 44749

  • Index.fillna() 中存在错误,当存在 NA 值并且指定了 downcast 参数时,错误地返回未填充的 Index。现在会引发 NotImplementedError;不要传递 downcast 参数(GH 44873

  • DataFrame.dropna() 中存在错误,即使没有删除任何条目,也会更改 IndexGH 41965

  • Series.fillna() 中存在错误,对于对象类型错误地忽略了 downcast="infer"GH 44241

多级索引

  • MultiIndex.get_loc() 中存在错误,当第一级别是 DatetimeIndex 且传递了字符串键时出错(GH 42465

  • 在通过 level 传递到 MultiIndex.reindex() 中的 level 对应于 ExtensionDtype 级别时存在错误(GH 42043

  • MultiIndex.get_loc() 中存在错误,在嵌套元组上引发 TypeError 而不是 KeyErrorGH 42440

  • MultiIndex.union() 中存在错误,设置了错误的 sortorder,导致后续使用切片的索引操作出错(GH 44752

  • MultiIndex.putmask() 中存在错误,其他值也是 MultiIndexGH 43212

  • MultiIndex.dtypes() 中存在错误,重复级别名称只返回一个 dtype per name(GH 45174

输入/输出

  • 尝试从 .xlsx 文件中读取图表工作表时,read_excel() 报告错误(GH 41448

  • json_normalize() 中的错误,在errors=ignore的情况下可能会在record_path的长度大于一时失败忽略meta的缺失值(GH 41876

  • 使用多标题输入和引用列名元组作为参数时,read_csv() 存在错误(GH 42446

  • colspecsnames 的长度差异导致不会报告ValueError错误时,read_fwf() 存在错误(GH 40830

  • 在将普通 Python 对象序列化为 JSON 时,Series.to_json()DataFrame.to_json() 中跳过了一些属性(GH 42768, GH 33043

  • 从 sqlalchemy 的 Row 对象构造 DataFrame 时,列标题被丢弃(GH 40682

  • 在不正确推断数值类型的情况下,反序列化具有对象数据类型的 Index 时存在错误(GH 43188

  • 在读取不等长度的多标题输入时,read_csv() 错误地引发IndexError错误(GH 43102

  • 在以块方式读取文件并且某些块的列数少于engine="c"的头部列数时,read_csv() 报告ParserError错误(GH 21211

  • 在期待文件路径名或类似文件对象时,read_csv() 的异常类由OSError更改为TypeErrorGH 43366

  • nrowsengine='python'指定时,read_csv()read_fwf()在指定了所有skiprows时会忽略除第一行外的所有行(GH 44021GH 10261)。

  • 在设置了keep_date_col=True时,read_csv()会保留原始列的对象格式(GH 13378)。

  • 在处理非 numpy 数据类型(特别是category)时,read_json()存在错误(GH 21892GH 33205)。

  • json_normalize()中,多字符sep参数错误地被前缀添加到每个键上(GH 43831)。

  • json_normalize()中,读取缺失多级元数据的数据时,不遵守errors="ignore"GH 44312)。

  • engine="python"情况下,read_csv()在将header设置为None时,使用第二行来猜测隐式索引(GH 22144)。

  • engine="c"时,read_csv()在给定names时无法识别错误行(GH 22144)。

  • float_precision="round_trip"时,read_csv()不会跳过初始/尾随空格(GH 43713)。

  • 当 Python 没有构建 lzma 模块时存在错误:即使没有使用 lzma 功能,也会在导入 pandas 时引发警告(GH 43495)。

  • read_csv()中,当为index_col设置 dtype 时无效(GH 9435)。

  • yaml.dump(frame)转储/加载DataFrame存在漏洞(GH 42748)。

  • namesheader长但等于engine="python"的数据行时,read_csv()引发ValueErrorGH 38453

  • ExcelWriter中存在错误,engine_kwargs未传递给所有引擎(GH 43442

  • parse_datesMultiIndex列一起使用时,read_csv()引发ValueErrorGH 8991

  • \n被指定为delimitersep时,read_csv()中未引发ValueError,这与lineterminator冲突(GH 43528

  • 在将分类Series中的日期时间转换为整数时,to_csv()中存在错误(GH 40754

  • 在日期解析失败后,read_csv()中的错误将列转换为数值类型(GH 11019

  • 在尝试进行日期转换之前,read_csv()中的错误未将NaN值替换为np.nanGH 26203

  • 读取read_csv()时引发AttributeError,尝试从可空整数类型推断索引列的数据类型时出现错误(GH 44079

  • to_csv()中存在的错误总是将具有不同格式的日期时间列强制转换为相同的格式(GH 21734

  • DataFrame.to_csv()Series.to_csv()设置compression'zip'时不再创建包含以“.zip”结尾的文件的 zip 文件。相反,它们会更加智能地推断内部文件名(GH 39465

  • 当将布尔值和缺失值的混合列读取为浮点类型时,read_csv()中存在错误,导致缺失值变为 1.0 而不是 NaN(GH 42808GH 34120

  • to_xml() 中的错误,对具有扩展数组 dtype 的pd.NA引发错误(GH 43903

  • read_csv() 中的错误,在date_parserparse_dates=False同时传递解析器时,仍然调用解析(GH 44366

  • read_csv() 中的错误,在index_col不是第一列时,未正确设置MultiIndex列的名称(GH 38549

  • read_csv() 中的错误,当无法创建内存映射文件时,默默地忽略错误(GH 44766

  • read_csv() 中的错误,当传递以二进制模式打开的tempfile.SpooledTemporaryFile时(GH 44748

  • read_json() 中的错误,在尝试解析包含“😕/”的 json 字符串时引发ValueErrorGH 36271

  • read_csv() 中的错误,当engine="c"encoding_errors=None时导致段错误(GH 45180

  • read_csv() 中的错误,usecols 的无效值导致未关闭的文件句柄(GH 45384

  • DataFrame.to_json() 中的错误修复内存泄漏(GH 43877

期间

  • Period对象添加到np.timedelta64对象中时不正确地引发TypeError的错误(GH 44182

  • PeriodIndex.to_timestamp() 中的错误,当索引的freq="B"时,推断结果的freq="D"而不是freq="B"GH 44105

  • Period 构造函数不正确地允许np.timedelta64("NaT")GH 44507

  • 修复了PeriodIndex.to_timestamp()中的错误,为具有非连续数据的索引提供了不正确的值(GH 44100

  • 修复了Series.where()中的错误,使用PeriodDtype时在where调用不应替换任何内容时错误地引发异常(GH 45135

绘图

  • 当提供非数值数据时,DataFrame.boxplot()现在会引发ValueError,而不是晦涩的KeyErrorZeroDivisionError,与其他绘图函数如DataFrame.hist()保持一致(GH 43480)

分组/重采样/滚动

  • 修复了SeriesGroupBy.apply()中的错误,当底层Series为空时传递未识别的字符串参数未能引发TypeErrorGH 42021

  • 修复了Series.rolling.apply()DataFrame.rolling.apply()Series.expanding.apply()DataFrame.expanding.apply()中的错误,当engine="numba"时,*args会与用户传递的函数一起被缓存(GH 42287

  • 修复了DataFrameGroupBy.max()SeriesGroupBy.max()DataFrameGroupBy.min()SeriesGroupBy.min()中的错误,具有可空整数 dtype 的数据丢失精度(GH 41743)

  • 修复了DataFrame.groupby.rolling.var()中的错误,只会在第一组上计算滚动方差(GH 42442

  • 修复了DataFrameGroupBy.shift()SeriesGroupBy.shift()中的错误,如果fill_value不是None,则会返回分组列(GH 41556

  • SeriesGroupBy.nlargest()SeriesGroupBy.nsmallest()在输入Series排序且n大于或等于所有组大小时,索引不一致(GH 15272GH 16345GH 29129

  • pandas.DataFrame.ewm()中存在 bug,非float64类型的数据静默失败(GH 42452

  • pandas.DataFrame.rolling()在沿行(axis=1)操作时错误地省略了包含float16float32的列(GH 41779

  • Resampler.aggregate()中存在 bug,不允许使用命名聚合(GH 32803

  • Series.rolling()中存在 bug,当SeriesdtypeInt64时(GH 43016)

  • DataFrame.rolling.corr()中存在 bug,当DataFrame列是MultiIndex时(GH 21157

  • DataFrame.groupby.rolling()中指定on并调用__getitem__时存在 bug,随后会返回不正确的结果(GH 43355

  • DataFrameGroupBy.apply()SeriesGroupBy.apply()中存在 bug,使用基于时间的Grouper对象时,在分组向量包含NaT的极端情况下会错误地引发ValueErrorGH 43500GH 43515

  • 修复了带有complex dtype 时DataFrameGroupBy.mean()SeriesGroupBy.mean()失败的错误(GH 43701

  • 修复了当center=True且索引递减时,Series.rolling()DataFrame.rolling()对第一行未正确计算窗口边界的错误(GH 43927

  • 修复了带有不均匀纳秒的居中日期时间窗口的Series.rolling()DataFrame.rolling()中的错误(GH 43997

  • 修复了至少两次选择列时DataFrameGroupBy.mean()SeriesGroupBy.mean()引发KeyError的错误(GH 44924

  • 修复了DataFrameGroupBy.nth()SeriesGroupBy.nth()axis=1上失败的错误(GH 43926

  • 修复了如果索引包含重复项,则Series.rolling()DataFrame.rolling()在居中日期时间窗口上不尊重右边界的错误(GH 3944

  • 在使用返回不相等的起始和结束数组的 pandas.api.indexers.BaseIndexer 子类时,Series.rolling()DataFrame.rolling() 中的错误会导致段错误,而不是引发 ValueErrorGH 44470)

  • Groupby.nunique() 中的错误未遵守 observed=True 对于 categorical 分组列的要求(GH 45128)

  • DataFrameGroupBy.head()SeriesGroupBy.head()DataFrameGroupBy.tail()SeriesGroupBy.tail() 中的错误,在 dropna=True 时未删除带有 NaN 的组(GH 45089)

  • 在选择 GroupBy 对象中的子列后,在 GroupBy.__iter__() 中的错误,返回了所有列而不是所选的子集(GH 44821)

  • 在传递非单调数据时,Groupby.rolling() 中的错误未能正确引发 ValueErrorGH 43909)

  • 通过具有 categorical 数据类型且长度与分组轴不相等的 Series 进行分组时,引发 ValueError 的错误(GH 44179)

重塑

  • 在从多维 numpy.ndarray 创建 DataFrame 列时,改进了错误消息(GH 42463)

  • 在连接具有 Index 中存在重复项和多个键的 DataFrame 时,concat() 中的错误会创建具有重复级别条目的 MultiIndexGH 42651

  • 在具有重复索引和非精确 pandas.CategoricalIndex()Series 上的 pandas.cut() 中的错误(GH 42185GH 42425

  • DataFrame.append() 中的错误是在附加的列不匹配时未能保留 dtype(GH 43392

  • concat() 中的错误是 boolboolean 类型导致 object 类型而不是 boolean 类型(GH 42800

  • 在输入为分类 Seriescrosstab() 中的错误是有一个或两个 Series 中不存在的类别,并且 margins=True 时。以前缺失类别的边际值为 NaN。现在正确报告为 0(GH 43505

  • concat() 中的错误会在 objs 参数具有相同索引且 keys 参数包含重复项时失败(GH 43595

  • concat() 中的错误会忽略 sort 参数(GH 43375

  • 在具有 MultiIndex 作为列索引的 merge() 中的错误是在内部分配列时返回错误(GH 43734

  • 在输入为列表或元组时的 crosstab() 中的错误(GH 44076

  • DataFrame.append()中的 bug,在附加一组Series对象时未能保留index.nameGH 44109)

  • Dataframe.apply()方法中修复了元数据传播问题,进而修复了Dataframe.transform()Dataframe.nunique()Dataframe.mode()的相同问题(GH 28283)

  • concat()中的 bug,如果所有级别只包含缺失值,则将MultiIndex的级别转换为浮点数(GH 44900)

  • DataFrame.stack()中的 bug,ExtensionDtype列错误地引发异常(GH 43561)

  • merge()中的 bug,在使用 on 关键字连接不同命名索引时引发KeyErrorGH 45094)

  • Series.unstack()中的 bug,对象在结果列上执行不需要的类型推断(GH 44595)

  • MultiIndex.join()中存在的 bug,与重叠的IntervalIndex级别有关(GH 44096)

  • DataFrame.replace()Series.replace()中的 bug,基于regex参数结果的dtype不同(GH 44864)

  • DataFrame.pivot()中的 bug,在index=None时,如果DataFrame索引是MultiIndex时(GH 23955)

Sparse

  • DataFrame.sparse.to_coo()中的 bug,在列名不唯一时引发AttributeErrorGH 29564)

  • SparseArray.max()SparseArray.min()中的 bug,对于具有 0 个非空元素的数组引发ValueErrorGH 43527)

  • DataFrame.sparse.to_coo() 中存在错误,将非零填充值悄悄地转换为零 (GH 24817)

  • SparseArray 比较方法存在错误,与长度不匹配的数组操作数一起引发 AssertionError 或不明确的 ValueError,取决于输入 (GH 43863)

  • SparseArray 算术方法 floordivmod 存在错误,当除以零时与非稀疏 Series 的行为不匹配 (GH 38172)

  • SparseArray 一元方法以及 SparseArray.isna() 存在错误,不会重新计算索引 (GH 44955)

ExtensionArray

  • array() 中存在错误,未能保留 PandasArray (GH 43887)

  • NumPy ufuncs np.absnp.positivenp.negative 现在在调用具有相应 __abs__, __pos__, __neg__ 实现的 ExtensionArrays 时正确保留 dtype。特别是这对 TimedeltaArray 修复了 (GH 43899, GH 23316)

  • NumPy ufuncs np.minimum.reducenp.maximum.reducenp.add.reducenp.prod.reduce 现在在与 IntegerDtypeFloatDtypeSeries 结合使用时,而不是引发 NotImplementedError,正确地工作 (GH 43923, GH 44793)

  • 具有 IntegerDtypeFloatingDtype 的数组现在支持带有 out 关键字的 NumPy ufuncs (GH 45122)

  • 在使用扩展 dtype 的许多列时,避免关于分段 DataFramePerformanceWarning (GH 44098)

  • IntegerArrayFloatingArray 构造中存在错误,错误地将不匹配的 NA 值(例如 np.timedelta64("NaT"))强制转换为数值型 NA (GH 44514)

  • BooleanArray.__eq__()BooleanArray.__ne__() 存在错误,在与不兼容类型(如字符串)比较时引发 TypeError。这导致 DataFrame.replace() 有时会在包含可空布尔列时引发 TypeError (GH 44499)

  • array()中,当传递具有float16 dtype 的ndarray时,错误地引发异常(GH 44715)

  • BooleanArray上调用np.sqrt时出现错误,返回了格式错误的FloatingArrayGH 44715)

  • Series.where()中的 bug,当ExtensionDtype时,如果other是与Series dtype 不兼容的 NA 标量(例如,NaT与数值 dtype),则错误地转换为兼容的 NA 值(GH 44697)

  • Bug in Series.replace()中明确传递value=None被视为未传递value,且结果中不包含NoneGH 36984, GH 19998)

  • Series.replace()中的 bug,在无操作替换中执行不需要的下转换(GH 44498)

  • Series.replace()中的 bug,当可能时,未保留FloatDtypestring[python]string[pyarrow] dtype(GH 33484, GH 40732, GH 31644, GH 41215, GH 25438)

Styler

  • Styler中的 bug,初始化时uuid保留了一个浮动的下划线(GH 43037)

  • Styler.to_html()中的 bug,如果调用to_html方法时带有一些参数,则会更新Styler对象(GH 43034)

  • Styler.copy()中的 bug,之前未复制uuidGH 40675)

  • Styler.apply()中的 bug,返回Series对象的函数在对齐其索引标签方面未被正确处理(GH 13657, GH 42014)

  • 渲染空的DataFrame时的错误,带有命名的IndexGH 43305

  • 渲染单层MultiIndex时的错误(GH 43383

  • 当结合非稀疏渲染和Styler.hide_columns()Styler.hide_index()时的错误(GH 43464

  • 在使用Styler中的多个选择器设置表格样式时的错误(GH 44011

  • 行修剪和列修剪未能反映隐藏行的错误(GH 43703GH 44247

其他

  • DataFrame.astype()中的错误,具有非唯一列和Series dtype参数时(GH 44417

  • CustomBusinessMonthBegin.__add__()CustomBusinessMonthEnd.__add__())中的错误,在目标月的开始(结束)已经是工作日时未应用额外的offset参数(GH 41356

  • RangeIndex.union()与另一个具有匹配(偶数)step且开始差异严格小于step / 2RangeIndex的错误(GH 44019

  • RangeIndex.difference()中的错误,sort=Nonestep<0时未能排序(GH 44085

  • Series.replace()DataFrame.replace()中的错误,当value=None和 ExtensionDtypes 时(GH 44270GH 37899

  • FloatingArray.equals()中的错误,如果它们包含np.nan值,则未考虑两个数组相等(GH 44382

  • DataFrame.shift()中的错误,当axis=1ExtensionDtype列不兼容的fill_value被传递时错误地引发异常(GH 44564

  • DataFrame.shift()中的错误,在axis=1periods大于len(frame.columns)时,会产生一个无效的DataFrameGH 44978)

  • DataFrame.diff()中的错误,传递 NumPy 整数对象而不是int对象时(GH 44572)

  • Series.replace()中的错误,在使用包含np.nan值的Series时,使用regex=True会引发ValueErrorGH 43344)

  • DataFrame.to_records()中的错误,在缺少名称被替换为level_n时,使用了不正确的nGH 44818)

  • DataFrame.eval()中的错误,resolvers参数覆盖了默认的解析器(GH 34966)

  • Series.__repr__()DataFrame.__repr__()不再将索引中的所有空值替换为“NaN”,而是使用它们的真实字符串表示。仅对float("nan")使用“NaN”(GH 45263)

Categorical

  • 将与 dtype 不兼容的值设置到Categorical���或由Categorical支持的SeriesDataFrame)中时,引发ValueError而不是TypeError的错误(GH 41919)

  • Categorical.searchsorted()中的错误,在传递与 dtype 不兼容的值时,引发KeyError而不是TypeErrorGH 41919)

  • Categorical.astype()中的错误,将日期时间和Timestamp转换为object类型的整数(GH 44930)

  • Series.where()中的错误,在传递与 dtype 不兼容的值时,引发ValueError而不是TypeErrorGH 41919)

  • Categorical.fillna()中的错误,在传递与 dtype 不兼容的值时,引发ValueError而不是TypeErrorGH 41919)

  • Categorical.fillna() 中存在 Bug,当填充为非类别元组时,会引发 ValueError 而不是 TypeErrorGH 41919

日期时间样式

  • DataFrame 构造函数中,不必要地复制非日期时间对象数组(GH 39272

  • to_datetime() 中,使用 formatpandas.NA 时会引发 ValueErrorGH 42957

  • to_datetime() 在无法尊重给定的 dayfirst 选项时,会悄然地交换 MM/DD/YYYYDD/MM/YYYY 格式,如果给定的日期字符串有分隔符,则会发出警告(例如 31-12-2012)(GH 12585

  • date_range()bdate_range() 中存在的 Bug 在 start = end 且集合在一侧闭合时,不会返回正确的右边界(GH 43394

  • 在时区感知的 DatetimeIndexTimedeltaIndex 上进行就地加法和减法时存在 Bug,与 DatetimeArrayTimedeltaArray 结合使用时存在问题(GH 43904

  • 在时区感知的 DatetimeIndex 上调用 np.isnannp.isfinitenp.isinf 时存在 Bug,错误地引发 TypeErrorGH 43917

  • 使用混合时区的日期时间字符串构建 Series 时存在 Bug,部分推断日期时间值不正确(GH 40111

  • Tick 对象和 np.timedelta64 对象相加时存在 Bug,错误地引发而不是返回 TimedeltaGH 44474

  • np.maximum.reducenp.minimum.reduce 现在在对具有 datetime64[ns]timedelta64[ns] 数据类型的 SeriesDataFrameIndex 进行操作时,正确返回 TimestampTimedelta 对象(GH 43923)

  • np.timedelta64 对象添加到 BusinessDayCustomBusinessDay 对象中时出现错误(GH 44532)

  • Bug in Index.insert(),在将 np.datetime64np.timedelta64tuple 插入具有 dtype='object'Index 时,使用负 loc 添加 None 并替换现有值时出现问题(GH 44509)

  • Bug in Timestamp.to_pydatetime() 无法保留 fold 属性,导致失败(GH 45087)

  • Series.mode() 中,DatetimeTZDtype 不正确返回时区无关和 PeriodDtype 不正确引发错误(GH 41927)

  • 修复了 reindex() 中的回归问题,当使用与日期时间类似的数据类型时,使用不兼容的填充值会引发错误(或者在使用 datetime.date 作为填充值时没有引发弃用警告)(GH 42921)

  • DateOffset 添加与 Timestamp 的 bug 中,offset.nanoseconds 不会包含在结果中(GH 43968, GH 36589)

  • Bug in Timestamp.fromtimestamp(),不支持 tz 参数(GH 45083)

  • 用不匹配索引 dtypes 的 Series 字典构建 DataFrame 时,有时会根据传递的字典的顺序引发异常(GH 44091)

  • 在某些夏令时转换期间,Timestamp 的散列存在错误,导致分段错误(GH 33931GH 40817)

时间差

  • 在所有-NaT TimeDeltaIndexSeriesDataFrame 列与对象类型数组相除时,未能将结果推断为 timedelta64-dtype (GH 39750)

  • 用标量进行 timedelta64[ns] 数据的 floor 除时返回垃圾值(GH 44466)

  • Timedelta 中的错误现在正确考虑了任何 kwarg 的纳秒贡献(GH 43764, GH 45227)

时区

  • 使用 infer_datetime_format=Trueto_datetime() 在解析零 UTC 偏移量 (Z) 时出现错误(GH 41047)

  • Series.dt.tz_convert() 中,在具有 CategoricalIndexSeries 中重置索引(GH 43080)

  • 当减去两个具有不匹配时区的时区感知对象时,TimestampDatetimeIndex 错误地引发 TypeErrorGH 31793)

数值

  • 在将整数列表或元组与 Series 进行 floor 除时出现错误地引发异常(GH 44674)

  • DataFrame.rank() 中,当 object 列和 method="first" 时引发 ValueErrorGH 41931)

  • DataFrame.rank()中的错误,将缺失值和极端值视为相等(例如np.nannp.inf),导致在使用na_option="bottom"na_option="top"时产生不正确的结果 (GH 41931)

  • 当选项compute.use_numexpr设置为False时,仍然使用numexpr引擎中的错误 (GH 32556)

  • 在具有其_constructor()属性为子类本身以外的可调用对象的子类的DataFrame算术操作中出现错误 (GH 43201)

  • 涉及RangeIndex的算术操作中的错误,结果将具有不正确的name (GH 43962)

  • 涉及Series的算术操作中的错误,当操作数具有匹配的 NA 或匹配的元组名称时,结果可能具有不正确的name (GH 44459)

  • 使用IntegerDtypeBooleanDtype数组和 NA 标量进行除法时出现错误,错误地引发异常 (GH 44685)

  • 使用FloatingDtype乘以类似时间间隔的标量的Series中的错误,错误地引发异常 (GH 44772)

转换

  • 在传递既包含足够小以转换为 int64 的正整数又包含过大以保存在 int64 中的整数的列表时,在UInt64Index构造函数中出现错误 (GH 42201)

  • Series构造函数中的错误,在 dtype 为int64时返回缺失值为 0,dtype 为bool时返回False (GH 43017, GH 43018)

  • 从包含Series对象的PandasArray构建DataFrame时出现错误,行为与等效的np.ndarray不同 (GH 43986)

  • IntegerDtype中的错误,不允许从字符串 dtype 进行强制转换 (GH 25472)

  • to_datetime()中的错误,指定arg:xr.DataArrayunit="ns"会引发TypeError (GH 44053)

  • DataFrame.convert_dtypes() 中的 Bug,当子类没有重载 _constructor_sliced() 时未返回正确类型(GH 43201

  • DataFrame.astype() 中的 Bug,未从原始 DataFrame 传播 attrs 的 Bug(GH 44414

  • DataFrame.convert_dtypes() 中的 Bug,结果丢失了 columns.namesGH 41435

  • 从 pyarrow 数据构建 IntegerArray 时验证 dtype 失败的 Bug(GH 44891

  • Series.astype() 中的 Bug,不允许从 PeriodDtype 转换为 datetime64 dtype,与 PeriodIndex 的行为不一致(GH 45038

字符串

  • 检查 string[pyarrow] dtype 时,当未安装 pyarrow 时错误地引发 ImportError 的 Bug(GH 44276

区间

  • Series.where() 中的 Bug,使用 IntervalDtype 时,当 where 调用不应替换任何内容时错误地引发了异常(GH 44181

索引

  • 带有 MultiIndex 和提供了 levelSeries.rename() 中的 Bug(GH 43659

  • 当对象的 Index 的长度大于一但只有一个唯一值时,DataFrame.truncate()Series.truncate() 中的 Bug(GH 42365

  • 使用元组进行索引时,Series.loc()DataFrame.loc() 在具有 MultiIndex 的情况下存在 Bug,其中一个级别也是元组 (GH 27591)

  • 在具有只包含 np.nan 值的第一级别的 MultiIndex 中,使用 Series.loc() 存在 Bug (GH 42055)

  • 在具有 DatetimeIndexSeriesDataFrame 上进行索引时,在传递字符串时,返回类型取决于索引是否单调(monotonic)存在 Bug (GH 24892)

  • 在索引中,当索引器是包含日期时间样式字符串的元组时,未能删除标量级别,存在 Bug (GH 42476)

  • 在传递升序值时,在 DataFrame.sort_values()Series.sort_values() 中存在 Bug,未能引发 ValueError 或错误引发 ValueError (GH 41634)

  • 使用由 pandas.DataFrame.pop() 创建的布尔索引来更新 pandas.Series 的值时存在 Bug (GH 42530)

  • 索引包含多个np.nan时,在 Index.get_indexer_non_unique() 中存在的 Bug (GH 35392)

  • 在查询中,DataFrame.query() 中存在 Bug,不能处理带有度符号的反引号列名,例如 Temp(°C),用于查询 DataFrame 中的表达式 (GH 42826)

  • DataFrame.drop() 中的 Bug 当引发 KeyError 时,错误消息没有显示带有逗号的缺失标签 (GH 42881)

  • DataFrame.query() 中的 Bug 当查询字符串中的方法调用导致 numexpr 包安装时导致错误 (GH 22435)

  • DataFrame.nlargest()Series.nlargest() 中的 Bug 排序结果不包括包含 np.nan 的索引 (GH 28984)

  • 在非唯一对象数据类型的索引上进行索引的 Bug 在存在 NA 标量(例如np.nan)时 (GH 43711)

  • DataFrame.__setitem__() 中的 Bug 在新的数据类型和旧的数据类型匹配时,错误地写入现有列的数组,而不是在设置新数组时 (GH 43406)

  • 在将浮点数据类型的值设置到整数数据类型的 Series 中时,当这些值可以无损地转换为整数时,设置 inplace 失败的 Bug (GH 44316)

  • Series.__setitem__() 中的 Bug 在设置一个大小和数据类型匹配的数组时,数据类型为'datetime64[ns]'或'dtype='timedelta64[ns]' 的对象数据类型时,错误地将 datetime/timedeltas 转换为整数 (GH 43868)

  • DataFrame.sort_index() 中的 Bug 在索引已经排序时,ignore_index=True 不被尊重 (GH 43591)

  • Index.get_indexer_non_unique() 中的 Bug 当索引包含多个 np.datetime64("NaT")np.timedelta64("NaT") 时 (GH 43869)

  • 在具有 IntervalDtypeSeries 中将标量 Interval 值设置为浮点数,且值的边界为整数时的 Bug (GH 44201)

  • 在将可解析为日期时间的字符串设置为由 DatetimeArray 支持的 DatetimeArraySeriesDataFrame 列中时,字符串后端的 Categorical 值设置 Bug,解析失败(GH 44236)

  • Series.__setitem__() 中的 Bug,当整数类型不是 int64 时,使用 range 对象设置会不必要地升级为 int64GH 44261)

  • Series.__setitem__() 中的 Bug,使用布尔掩码索引器设置长度为 1 的类似列表值时不正确地广播该值(GH 44265)

  • Series.reset_index() 中的 Bug,当 dropinplace 被设置为 True 时,不会忽略 name 参数(GH 44575)

  • DataFrame.loc.__setitem__()DataFrame.iloc.__setitem__() 中的 Bug,混合 dtype 有时无法就地操作(GH 44345)

  • DataFrame.loc.__getitem__() 中的 Bug,在使用布尔键选择单个列时不正确地引发 KeyErrorGH 44322)

  • 使用单个 ExtensionDtype 列设置 2D 值(例如 df.iloc[:] = df.values)时,设置 DataFrame.iloc() 中的 Bug 不正确地引发异常(GH 44514)

  • 使用单个 ExtensionDtype 列和数组元组作为索引器设置值时,在 DataFrame.iloc() 中的 Bug(GH 44703)

  • 使用带有负步长的切片在具有 ExtensionDtype 列的列上进行 lociloc 索引时,引发异常(GH 44551)

  • DataFrame.loc.__setitem__() 中的 Bug,当索引器完全为 False 时改变 dtype(GH 37550)

  • IntervalIndex.get_indexer_non_unique() 中的 Bug,在索引非唯一且非单调的情况下,返回布尔掩码而不是整数数组(GH 44084)

  • IntervalIndex.get_indexer_non_unique() 中的 Bug,在处理 dtype 为 ‘object’ 且包含 NaN 的目标时没有正确处理(GH 44482)

  • 修复了一个回归,当将单列 np.matrix 添加到 DataFrame 时,不再将其强制转换为 1d np.ndarrayGH 42376

  • Series.__getitem__() 中的一个 Bug,当使用整数的 CategoricalIndex 处理整数列表时将其视为位置索引器,与处理单个标量整数的行为不一致(GH 15470, GH 14865

  • Series.__setitem__() 中的一个 Bug,当将浮点数或整数设置为整数类型的 Series 时,在必要时未进行上转换以保留精度(GH 45121

  • DataFrame.iloc.__setitem__() 中的一个 Bug,忽略了 axis 参数(GH 45032

缺失

  • DataFrame.fillna() 中的一个 Bug,使用 limit 且没有 method 时忽略 axis='columns'axis = 1GH 40989, GH 17399

  • DataFrame.fillna() 中的一个 Bug,在使用类似字典的 value 和重复列名时未替换缺失值(GH 43476

  • 构造一个具有字典 np.datetime64 作为值且 dtype='timedelta64[ns]'DataFrame,或反之,不正确地进行转换而不是引发错误(GH 44428

  • Series.interpolate()DataFrame.interpolate() 中的一个 Bug,使用 inplace=True 时未就地写入底层数组(GH 44749

  • Index.fillna() 存在 NA 值且指定了 downcast 参数时,错误地返回未填充的 Index。现在会引发 NotImplementedError;不要传递 downcast 参数(GH 44873

  • Bug in DataFrame.dropna(),即使没有删除条目,也会更改IndexGH 41965)

  • Bug in Series.fillna(),使用对象类型时错误地忽略了downcast="infer"GH 44241)

MultiIndex

  • Bug in MultiIndex.get_loc(),当第一级是DatetimeIndex且传递了字符串键时存在错误(GH 42465)

  • Bug in MultiIndex.reindex(),当传递与ExtensionDtype级别对应的level时存在错误(GH 42043)

  • Bug in MultiIndex.get_loc(),在嵌套元组上引发TypeError而不是KeyErrorGH 42440)

  • Bug in MultiIndex.union(),设置了错误的sortorder导致在使用切片进行后续索引操作时出错(GH 44752)

  • Bug in MultiIndex.putmask(),其中另一个值也是MultiIndex存在错误(GH 43212)

  • Bug in MultiIndex.dtypes(),重复的级别名称仅返回一个名称的 dtype(GH 45174)

I/O

  • Bug in read_excel(),尝试从 .xlsx 文件中读取图表表单(GH 41448)

  • Bug in json_normalize(),当record_path长度大于一时,errors=ignore可能无法忽略meta的缺失值(GH 41876)

  • Bug in read_csv(),使用多标题输入和引用列名的参数作为元组时存在错误(GH 42446)

  • Bug in read_fwf()colspecsnames长度不同未引发ValueError错误(GH 40830)

  • 修复了将纯 Python 对象序列化为 JSON 时,Series.to_json()DataFrame.to_json() 跳过某些属性的错误(GH 42768, GH 33043

  • 从 sqlalchemy 的 Row 对象构建 DataFrame 时会丢弃列标题(GH 40682

  • 修复了使用对象 dtype 反序列化 Index 时错误地推断数值 dtype 的错误(GH 43188

  • 修复了在读取不等长度的多标题输入时,read_csv() 错误地引发 IndexError 的错误(GH 43102

  • 在以块方式读取文件时,修复了 read_csv() 使用 engine="c" 时读取的某些块的列数少于标题的错误,会抛出 ParserErrorGH 21211

  • 修复了在期望文件路径名或类文件对象时,read_csv() 的异常类从 OSError 更改为 TypeError 的错误(GH 43366

  • 当为 engine='python' 指定 nrows 时,修复了 read_csv()read_fwf()engine='python'时忽略除第一个之外的所有 skiprows 的错误(GH 44021, GH 10261

  • 修复了read_csv()在设置keep_date_col=True时保持原始列为对象格式的错误(GH 13378

  • 修复了 read_json() 不正确处理非 numpy 数据类型(特别是 category)的错误(GH 21892, GH 33205

  • 修复了 json_normalize() 中多字符 sep 参数错误地被添加到每个键的错误(GH 43831

  • 在读取缺少多级元数据的数据时,json_normalize()不会遵守errors="ignore"的错误(GH 44312

  • header设置为Noneengine="python"时,read_csv()会使用第二行来猜测隐式索引的错误(GH 22144

  • 当为engine="c"指定names时,read_csv()未识别到坏行的错误(GH 22144

  • float_precision="round_trip"时,read_csv()存在的错误,未跳过初始/尾随空格(GH 43713

  • 当 Python 没有安装 lzma 模块时的错误:即使不使用 lzma 功能,导入 pandas 时也会引发警告(GH 43495

  • index_col中未应用 dtype 时,read_csv()存在的错误(GH 9435

  • 在使用yaml.dump(frame)导出/导入DataFrame时存在的错误(GH 42748

  • names长于header但等于数据行时,read_csv()engine="python"时引发ValueError的错误(GH 38453

  • ExcelWriter中,未将engine_kwargs传递给所有引擎的错误(GH 43442

  • parse_datesMultiIndex列一起使用时,read_csv()引发ValueError的错误(GH 8991

  • delimitersep指定为\n且与lineterminator冲突时,read_csv()未引发ValueError的错误(GH 43528

  • 将日期时间转换为整数时,to_csv()中分类Series存在的错误(GH 40754

  • 在日期解析失败后,read_csv() 中的一个 Bug 会将列转换为数字(GH 11019)。

  • 在尝试日期转换之前,read_csv() 中的一个 Bug 未用np.nan替换NaN值(GH 26203)。

  • 当尝试从可为空的整数类型推断索引列 dtype 时,read_csv() 中的一个 Bug 会引发AttributeErrorGH 44079)。

  • to_csv()中的一个 Bug 总是将具有不同格式的日期时间列强制转换为相同的格式(GH 21734)。

  • 当设置 compression'zip' 时,DataFrame.to_csv()Series.to_csv() 不再创建以“.zip”结尾的 zip 文件。相反,它们会更加智能地推断内部文件名(GH 39465)。

  • 当将布尔值和缺失值的混合列读取为浮点类型时,read_csv() 中的一个 Bug 会导致缺失值变为 1.0 而不是 NaN(GH 42808GH 34120)。

  • 对于带有扩展数组 dtype 的pd.NAto_xml()中的一个 Bug 会引发错误(GH 43903)。

  • 当同时在 date_parserparse_dates=False 中传递解析器时,read_csv() 仍会调用解析(GH 44366)。

  • 在使用read_csv()时,当index_col不是第一列时,未正确设置MultiIndex列的名称(GH 38549)。

  • 当无法创建内存映射文件时,read_csv() 中的一个 Bug 会静默地忽略错误(GH 44766)。

  • 当传递以二进制模式打开的 tempfile.SpooledTemporaryFile 时,read_csv() 中的一个 Bug 会出现问题(GH 44748)。

  • 在试图解析包含“😕/”的 json 字符串时,read_json() 引发 ValueErrorGH 36271

  • engine="c"encoding_errors=None 时,read_csv() 中出现错误,导致段错误(GH 45180

  • read_csv() 中,usecols 的无效值导致文件句柄未关闭(GH 45384

  • 修复 DataFrame.to_json() 的内存泄漏(GH 43877

Period

  • np.timedelta64 对象添加 Period 对象时出现错误,错误地引发 TypeErrorGH 44182

  • 当索引具有 freq="B" 时,在 PeriodIndex.to_timestamp() 中出现错误,推断其结果的 freq="D" 而不是 freq="B"GH 44105

  • 在构造函数中,Period 错误地允许 np.timedelta64("NaT")GH 44507

  • 对于具有非连续数据的索引,PeriodIndex.to_timestamp() 提供的值不正确(GH 44100

  • 在使用 PeriodDtypeSeries.where() 中出现错误,当 where 调用不应替换任何内容时错误引发异常(GH 45135

绘图

  • 在给定非数值数据时,DataFrame.boxplot() 现在引发 ValueError 而不是晦涩的 KeyErrorZeroDivisionError,与其他绘图函数如 DataFrame.hist() 保持一致(GH 43480

Groupby/resample/rolling

  • SeriesGroupBy.apply() 中出现错误,传递一个未被识别的字符串参数时,当基础 Series 为空时未能引发 TypeErrorGH 42021

  • Series.rolling.apply()DataFrame.rolling.apply()Series.expanding.apply()DataFrame.expanding.apply() 中的 bug,当 engine="numba" 时,*args 会被缓存与用户传递的函数一起(GH 42287

  • DataFrameGroupBy.max()SeriesGroupBy.max()DataFrameGroupBy.min()SeriesGroupBy.min() 中的 bug,带有可空整数类型会丢失精度(GH 41743

  • DataFrame.groupby.rolling.var() 中的 bug 会仅对第一组计算滚动方差(GH 42442

  • DataFrameGroupBy.shift()SeriesGroupBy.shift() 中的 bug,如果 fill_value 不是 None,将返回分组列(GH 41556

  • SeriesGroupBy.nlargest()SeriesGroupBy.nsmallest() 中的 bug,当输入 Series 已排序且 n 大于或等于所有分组大小时,索引不一致(GH 15272, GH 16345, GH 29129

  • pandas.DataFrame.ewm() 中的 bug,非 float64 类型会默默失败(GH 42452

  • pandas.DataFrame.rolling() 沿行操作(axis=1)的 bug 不正确地省略了包含 float16float32 的列(GH 41779

  • Resampler.aggregate() 中的 bug 不允许使用命名聚合函数(GH 32803

  • SeriesdtypeInt64时,Series.rolling()存在 Bug (GH 43016)

  • DataFrame的列为MultiIndex时,DataFrame.rolling.corr()存在 Bug (GH 21157)

  • 当指定on并调用__getitem__时,DataFrame.groupby.rolling()存在 Bug,随后会返回不正确的结果 (GH 43355)

  • 当时间为基础的 Grouper 对象中的分组向量包含 NaT 时,在一些极端情况下,DataFrameGroupBy.apply()SeriesGroupBy.apply() 存在 Bug,会不正确地引发 ValueError (GH 43500, GH 43515)

  • dtypecomplex时,DataFrameGroupBy.mean()SeriesGroupBy.mean()存在 Bug (GH 43701)

  • center=True且索引递减时,Series.rolling()DataFrame.rolling()未正确计算第一行的窗口边界 (GH 43927)

  • 对于不均匀的纳秒级日期时间窗口,带有中心时间的Series.rolling()DataFrame.rolling()存在 Bug (GH 43997)

  • 当至少两次选择列时,DataFrameGroupBy.mean()SeriesGroupBy.mean()中的 Bug 会引发KeyErrorGH 44924

  • axis=1时,DataFrameGroupBy.nth()SeriesGroupBy.nth()中的 Bug 失败(GH 43926

  • 当索引包含重复项时,Series.rolling()DataFrame.rolling()中的 Bug 不尊重居中的日期时间窗口的右边界(GH 3944

  • 当使用返回不相等的起始和结束数组的pandas.api.indexers.BaseIndexer子类时,Series.rolling()DataFrame.rolling()中的 Bug 会导致段错误,而不是引发ValueErrorGH 44470

  • [Groupby.nunique()中的 Bug 不尊重observed=True用于categorical分组列(GH 45128

  • dropna=True时,DataFrameGroupBy.head()SeriesGroupBy.head()DataFrameGroupBy.tail()SeriesGroupBy.tail()中的 Bug 不会删除具有NaN的组(GH 45089

  • 在选择 GroupBy 对象中的子列后,在 GroupBy.__iter__() 中的错误,返回了所有列而不是选择的子集 (GH 44821)

  • 当传递非单调数据时,在 Groupby.rolling() 中出现错误,未能正确引发 ValueError (GH 43909)

  • 当分组的 Series 具有 categorical 数据类型且长度与分组的轴不相等时,引发 ValueError 的错误 (GH 44179)

重塑

  • 当从多维度的 numpy.ndarray 创建 DataFrame 列时,改进了错误消息 (GH 42463)

  • 当连接具有重复索引和多个键的 DataFrame 时,concat() 创建重复级别条目的 MultiIndex (GH 42651) 时出现的错误

  • 在具有重复索引和非精确 pandas.CategoricalIndex()Series 上的 pandas.cut() 中出现的错误 (GH 42185, GH 42425)

  • 当附加的列不匹配时,DataFrame.append() 未能保留数据类型 (GH 43392)

  • boolboolean 数据类型的 concat() 中出现错误,导致 object 数据类型而不是 boolean 数据类型 (GH 42800)

  • 当输入是分类 Series 时,crosstab() 中的错误,其中一个或两个 Series 中不存在的类别,并且 margins=True。以前缺少类别的边缘值为 NaN。现在正确地报告为 0 (GH 43505)

  • concat() 存在错误,当 objs 参数都具有相同的索引且 keys 参数包含重复项时会失败(GH 43595

  • concat() 中存在错误,忽略了 sort 参数(GH 43375

  • merge() 中存在错误,使用 MultiIndex 作为列索引时,on 参数返回错误(GH 43734

  • crosstab() 中存在错误,当输入为列表或元组时会失败(GH 44076

  • DataFrame.append() 中存在错误,当追加一系列 Series 对象时未保留 index.nameGH 44109

  • 修复了 Dataframe.apply() 方法中的元数据传播,因此也修复了 Dataframe.transform()Dataframe.nunique()Dataframe.mode() 中的相同问题(GH 28283

  • concat() 中存在错误,如果所有级别只包含缺失值,则将 MultiIndex 的级别转换为浮点数(GH 44900

  • DataFrame.stack() 存在错误,ExtensionDtype 列错误地引发异常(GH 43561

  • merge() 中存在错误,在使用 on 关键字连接不同命名索引时引发 KeyErrorGH 45094

  • Series.unstack() 存在错误,对象对生成的列进行了不希望的类型推断(GH 44595

  • MultiIndex.join() 中存在错误,与重叠的 IntervalIndex 级别有关(GH 44096

  • DataFrame.replace()Series.replace() 中存在错误,基于 regex 参数结果的 dtype 不同(GH 44864

  • DataFrame.pivot()中的错误,当DataFrame索引为MultiIndex时,index=NoneGH 23955

Sparse

  • DataFrame.sparse.to_coo()中的错误,在列名不唯一时引发AttributeErrorGH 29564

  • SparseArray.max()SparseArray.min()中的错误,对于具有 0 个非空元素的数组引发ValueErrorGH 43527

  • DataFrame.sparse.to_coo()中的错误,将非零填充值悄悄地转换为零(GH 24817

  • SparseArray比较方法中的错误,当具有长度不匹配的类似数组的操作数时引发AssertionError或根据输入引发不明确的ValueErrorGH 43863

  • SparseArray算术方法floordivmod在除以零时的行为与非稀疏的Series行为不匹配的错误(GH 38172

  • SparseArray的一元方法以及SparseArray.isna()中的错误,不会重新计算索引(GH 44955

ExtensionArray

  • array()中的错误,未能保留PandasArrayGH 43887

  • 当在实现__abs__, __pos__, __neg__的 ExtensionArrays 上调用时,NumPy ufuncs np.abs, np.positive, np.negative现在正确地保留 dtype。特别是对于TimedeltaArray已修复此问题(GH 43899GH 23316

  • NumPy ufuncs np.minimum.reduce np.maximum.reduce, np.add.reduce, 和 np.prod.reduce现在在具有IntegerDtypeFloatDtypeSeries上正确工作,而不是引发NotImplementedErrorGH 43923GH 44793)

  • 现在支持具有IntegerDtypeFloatingDtype的数组的 NumPy ufuncs 中的out关键字(GH 45122

  • 当使用具有扩展 dtype 的许多列时,避免引发关于片段化DataFramePerformanceWarningGH 44098

  • 在构造IntegerArrayFloatingArray时存在错误,错误地将不匹配的 NA 值(例如np.timedelta64("NaT"))强制转换为数值 NA(GH 44514

  • 在与不兼容类型(如字符串)进行比较时,BooleanArray.__eq__()BooleanArray.__ne__()存在错误,导致引发TypeError。这导致DataFrame.replace()有时会引发TypeError,如果包括了可空布尔列的话(GH 44499

  • 在传递具有float16 dtype 的ndarray时,array()错误地引发异常(GH 44715

  • 在调用BooleanArray上的np.sqrt时存在错误,返回了一个格式不正确的FloatingArrayGH 44715

  • ExtensionDtype中,当other是与Series dtype 不兼容的 NA 标量时,Series.where()存在错误,错误地将其强制转换为兼容的 NA 值(例如,NaT与数字 dtype)(GH 44697

  • Series.replace()中存在错误,显式传递value=None时被视为未传递value,并且结果中不包含NoneGH 36984GH 19998

  • 在空操作替换中不必要地进行不希望的降级操作(GH 44498

  • 当可能时,Series.replace()中存在错误,未能保留FloatDtypestring[python]string[pyarrow] dtype(GH 33484GH 40732GH 31644GH 41215GH 25438

Styler

  • Styler中,初始化时uuid保持浮动下划线的错误(GH 43037

  • Styler.to_html()中,如果调用to_html方法时更新了Styler对象的错误(GH 43034

  • Styler.copy()中以前未复制uuid的错误(GH 40675

  • Styler.apply()中,返回Series对象的函数在对齐其索引标签方面未正确处理的错误(GH 13657GH 42014

  • 渲染空的带有命名IndexDataFrame时出现的错误(GH 43305

  • 渲染单层MultiIndex时出现的错误(GH 43383

  • 在非稀疏渲染和Styler.hide_columns()Styler.hide_index()组合时出现的错误(GH 43464

  • 在使用Styler中的多个选择器设置表格样式时出现的错误(GH 44011

  • 行修剪和列修剪未能反映隐藏行的错误(GH 43703GH 44247

其他

  • DataFrame.astype()中,具有非唯一列和Series dtype参数的错误(GH 44417

  • CustomBusinessMonthBegin.__add__()CustomBusinessMonthEnd.__add__())中,当目标月份的开始(结束)已经是工作日时未应用额外的offset参数的错误(GH 41356)

  • RangeIndex.union()中与另一个具有匹配(偶数)step且开始差异严格小于step / 2RangeIndex合并时出现的错误(GH 44019

  • RangeIndex.difference() 中存在 Bug,当 sort=Nonestep<0 时未能进行排序(GH 44085)

  • Series.replace()DataFrame.replace() 存在 Bug,当 value=None 且为 ExtensionDtypes 时(GH 44270, GH 37899)

  • FloatingArray.equals() 中存在 Bug,如果包含 np.nan 值,则未考虑两个数组是否相等(GH 44382)

  • DataFrame.shift() 存在 Bug,当 axis=1 且列为 ExtensionDtype 时,当传递不兼容的 fill_value 时错误地引发异常(GH 44564)

  • DataFrame.shift() 存在 Bug,当 axis=1periods 大于 len(frame.columns) 时产生无效的 DataFrameGH 44978)

  • DataFrame.diff() 存在 Bug,当传递 NumPy 整数对象而不是 int 对象时出现错误(GH 44572)

  • Series.replace() 存在 Bug,当使用 regex=TrueSeries 包含 np.nan 值时引发 ValueError 错误(GH 43344)

  • DataFrame.to_records() 存在 Bug,当缺失名称被 level_n 替换时,使用了不正确的 nGH 44818)

  • DataFrame.eval() 存在 Bug,resolvers 参数会覆盖默认的解析器(GH 34966)

  • Series.__repr__()DataFrame.__repr__() 不再将索引中的所有空值替换为“NaN”,而是使用它们的真实字符串表示。只有 float("nan") 才使用“NaN” (GH 45263)

贡献者

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

  • Abhishek R

  • Albert Villanova del Moral

  • Alessandro Bisiani +

  • Alex Lim

  • Alex-Gregory-1 +

  • Alexander Gorodetsky

  • Alexander Regueiro +

  • Alexey Györi

  • Alexis Mignon

  • Aleš Erjavec

  • Ali McMaster

  • Alibi +

  • Andrei Batomunkuev +

  • Andrew Eckart +

  • Andrew Hawyrluk

  • Andrew Wood

  • Anton Lodder +

  • Armin Berres +

  • Arushi Sharma +

  • Benedikt Heidrich +

  • Beni Bienz +

  • Benoît Vinot

  • Bert Palm +

  • Boris Rumyantsev +

  • Brian Hulette

  • Brock

  • Bruno Costa +

  • Bryan Racic +

  • Caleb Epstein

  • Calvin Ho

  • ChristofKaufmann +

  • Christopher Yeh +

  • Chuliang Xiao +

  • ClaudiaSilver +

  • DSM

  • Daniel Coll +

  • Daniel Schmidt +

  • Dare Adewumi

  • David +

  • David Sanders +

  • David Wales +

  • Derzan Chiang +

  • DeviousLab +

  • Dhruv B Shetty +

  • Digres45 +

  • Dominik Kutra +

  • Drew Levitt +

  • DriesS

  • EdAbati

  • Elle

  • Elliot Rampono

  • Endre Mark Borza

  • Erfan Nariman

  • Evgeny Naumov +

  • Ewout ter Hoeven +

  • Fangchen Li

  • Felix Divo

  • Felix Dulys +

  • Francesco Andreuzzi +

  • Francois Dion +

  • Frans Larsson +

  • Fred Reiss

  • GYvan

  • Gabriel Di Pardi Arruda +

  • Gesa Stupperich

  • Giacomo Caria +

  • Greg Siano +

  • Griffin Ansel

  • Hiroaki Ogasawara +

  • Horace +

  • Horace Lai +

  • Irv Lustig

  • Isaac Virshup

  • JHM Darbyshire (MBP)

  • JHM Darbyshire (iMac)

  • JHM Darbyshire +

  • Jack Liu

  • Jacob Skwirsk +

  • Jaime Di Cristina +

  • James Holcombe +

  • Janosh Riebesell +

  • Jarrod Millman

  • Jason Bian +

  • Jeff Reback

  • Jernej Makovsek +

  • Jim Bradley +

  • Joel Gibson +

  • Joeperdefloep +

  • Johannes Mueller +

  • John S Bogaardt +

  • John Zangwill +

  • Jon Haitz Legarreta Gorroño +

  • Jon Wiggins +

  • Jonas Haag +

  • Joris Van den Bossche

  • Josh Friedlander

  • José Duarte +

  • Julian Fleischer +

  • Julien de la Bruère-T

  • Justin McOmie

  • Kadatatlu Kishore +

  • Kaiqi Dong

  • Kashif Khan +

  • Kavya9986 +

  • Kendall +

  • Kevin Sheppard

  • Kiley Hewitt

  • Koen Roelofs +

  • Krishna Chivukula

  • KrishnaSai2020

  • Leonardo Freua +

  • Leonardus Chen

  • Liang-Chi Hsieh +

  • Loic Diridollou +

  • Lorenzo Maffioli +

  • Luke Manley +

  • LunarLanding +

  • Marc Garcia

  • Marcel Bittar +

  • Marcel Gerber +

  • Marco Edward Gorelli

  • Marco Gorelli

  • MarcoGorelli

  • Marvin +

  • Mateusz Piotrowski +

  • Mathias Hauser +

  • Matt Richards +

  • Matthew Davis +

  • Matthew Roeschke

  • Matthew Zeitlin

  • Matthias Bussonnier

  • Matti Picus

  • Mauro Silberberg +

  • Maxim Ivanov

  • Maximilian Carr +

  • MeeseeksMachine

  • Michael Sarrazin +

  • Michael Wang +

  • Michał Górny +

  • Mike Phung +

  • Mike Taves +

  • Mohamad Hussein Rkein +

  • NJOKU OKECHUKWU VALENTINE +

  • Neal McBurnett +

  • Nick Anderson +

  • Nikita Sobolev +

  • Olivier Cavadenti +

  • PApostol +

  • Pandas 开发团队

  • Patrick Hoefler

  • Peter

  • Peter Tillmann +

  • Prabha Arivalagan +

  • Pradyumna Rahul

  • Prerana Chakraborty

  • Prithvijit +

  • Rahul Gaikwad +

  • Ray Bell

  • Ricardo Martins +

  • Richard Shadrach

  • Robbert-jan ‘t Hoen +

  • Robert Voyer +

  • Robin Raymond +

  • Rohan Sharma +

  • Rohan Sirohia +

  • Roman Yurchak

  • Ruan Pretorius +

  • Sam James +

  • Scott Talbert

  • Shashwat Sharma +

  • Sheogorath27 +

  • Shiv Gupta

  • Shoham Debnath

  • Simon Hawkins

  • Soumya +

  • Stan West +

  • Stefanie Molin +

  • Stefano Alberto Russo +

  • Stephan Heßelmann

  • Stephen

  • Suyash Gupta +

  • Sven

  • Swanand01 +

  • Sylvain Marié +

  • TLouf

  • Tania Allard +

  • Terji Petersen

  • TheDerivator +

  • Thomas Dickson

  • Thomas Kastl +

  • Thomas Kluyver

  • Thomas Li

  • Thomas Smith

  • Tim Swast

  • Tim Tran +

  • Tobias McNulty +

  • Tobias Pitters

  • Tomoki Nakagawa +

  • Tony Hirst +

  • Torsten Wörtwein

  • V.I. Wood +

  • Vaibhav K +

  • Valentin Oliver Loftsson +

  • Varun Shrivastava +

  • Vivek Thazhathattil +

  • Vyom Pathak

  • Wenjun Si

  • William Andrea +

  • William Bradley +

  • Wojciech Sadowski +

  • Yao-Ching Huang +

  • Yash Gupta +

  • Yiannis Hadjicharalambous +

  • Yoshiki Vázquez Baeza

  • Yuanhao Geng

  • Yury Mikhaylov

  • Yvan Gatete +

  • Yves Delley +

  • Zach Rait

  • Zbyszek Królikowski +

  • Zero +

  • Zheyuan

  • Zhiyi Wu +

  • aiudirog

  • ali sayyah +

  • aneesh98 +

  • aptalca

  • arw2019 +

  • attack68

  • brendandrury +

  • bubblingoak +

  • calvinsomething +

  • claws +

  • deponovo +

  • dicristina

  • el-g-1 +

  • evensure +

  • fotino21 +

  • fshi01 +

  • gfkang +

  • github-actions[bot]

  • i-aki-y

  • jbrockmendel

  • jreback

  • juliandwain +

  • jxb4892 +

  • kendall smith +

  • lmcindewar +

  • lrepiton

  • maximilianaccardo +

  • michal-gh

  • neelmraman

  • partev

  • phofl +

  • pratyushsharan +

  • quantumalaviya +

  • rafael +

  • realead

  • rocabrera +

  • rosagold

  • saehuihwang +

  • salomondush +

  • shubham11941140 +

  • srinivasan +

  • stphnlyd

  • suoniq

  • trevorkask +

  • tushushu

  • tyuyoshi +

  • usersblock +

  • vernetya +

  • vrserpa +

  • willie3838 +

  • zeitlinv +

  • zhangxiaoxing +

posted @ 2024-06-26 10:34  绝不原创的飞龙  阅读(1)  评论(0编辑  收藏  举报