0.23.1 中的新特性(2018年6月12日)#

这是 0.23.x 系列的一个次要错误修复版本,包含一些小的回归修复和错误修复。我们建议所有用户升级到此版本。

警告

从2019年1月1日起,pandas 功能版本将仅支持 Python 3。详情请参阅放弃 Python 2.7

回归修复#

将 Series 与 datetime.date 进行比较

我们已撤销 0.23.0 中将包含日期时间的 Seriesdatetime.date 对象进行比较的更改(GH 21152)。在 pandas 0.22 及更早版本中,比较包含日期时间的 Series 和 datetime.date 对象会将 datetime.date 强制转换为 datetime 后再进行比较。这与 Python、NumPy 和 DatetimeIndex 不一致,它们从不认为 datetime 和 datetime.date 相等。

在 0.23.0 中,我们统一了 DatetimeIndex 和 Series 之间的操作,并在此过程中更改了日期时间 Series 与 datetime.date 之间的比较方式,且未发出警告。

我们已暂时恢复 0.22.0 的行为,因此日期时间和日期可能会再次比较相等,但将在未来版本中恢复 0.23.0 的行为。

总结一下,以下是 0.22.0、0.23.0、0.23.1 中的行为:

# 0.22.0... Silently coerce the datetime.date
>>> import datetime
>>> pd.Series(pd.date_range('2017', periods=2)) == datetime.date(2017, 1, 1)
0     True
1    False
dtype: bool

# 0.23.0... Do not coerce the datetime.date
>>> pd.Series(pd.date_range('2017', periods=2)) == datetime.date(2017, 1, 1)
0    False
1    False
dtype: bool

# 0.23.1... Coerce the datetime.date with a warning
>>> pd.Series(pd.date_range('2017', periods=2)) == datetime.date(2017, 1, 1)
/bin/python:1: FutureWarning: Comparing Series of datetimes with 'datetime.date'.  Currently, the
'datetime.date' is coerced to a datetime. In the future pandas will
not coerce, and the values not compare equal to the 'datetime.date'.
To retain the current behavior, convert the 'datetime.date' to a
datetime with 'pd.Timestamp'.
  #!/bin/python3
0     True
1    False
dtype: bool

此外,排序比较在未来将引发 TypeError

其他修复

  • 已恢复 to_sql() 执行多值插入的功能,因为这在某些情况下会导致回归(GH 21103)。未来这将可配置。

  • 修复了在时区感知数据中 DatetimeIndex.dateDatetimeIndex.time 属性的回归:DatetimeIndex.time 返回了时区感知时间而不是时区非感知时间(GH 21267),以及当输入日期具有非 UTC 时区时,DatetimeIndex.date 返回了不正确的日期(GH 21230)。

  • 修复了当 pandas.io.json.json_normalize() 在 JSON 嵌套级别中遇到 None 值时的回归,并确保不删除值为 None 的键(GH 21158, GH 21356)。

  • 当同时指定压缩和编码时,to_csv() 中的错误导致编码错误(GH 21241, GH 21118

  • 阻止 pandas 在使用 -OO 优化时导入的错误(GH 21071

  • value 的个别类别是可迭代对象且 value 也是一个可迭代对象时,Categorical.fillna() 中错误地引发 TypeError 的错误(GH 21097, GH 19788

  • 修复了构造函数在传入 dtype=str 时将 None 等 NA 值强制转换为字符串的回归(GH 21083

  • pivot_table() 中,当 pivot 的 index 包含缺失值的有序 Categorical 时,会产生不对齐结果的回归(GH 21133

  • 修复了在布尔索引/列上合并的回归(GH 21119)。

性能改进#

  • 改进了 CategoricalIndex.is_monotonic_increasing()CategoricalIndex.is_monotonic_decreasing()CategoricalIndex.is_monotonic() 的性能(GH 21025

  • 改进了 CategoricalIndex.is_unique() 的性能(GH 21107

错误修复#

分组/重采样/滚动操作

  • 当对具有重复列名的 DataFrame 应用多个聚合函数时,DataFrame.agg() 中的错误会导致堆栈溢出(GH 21063

  • GroupBy.ffill()GroupBy.bfill() 中存在的错误,由于实现中使用了非稳定排序,导致分组内的填充不总是按预期应用(GH 21207

  • GroupBy.rank() 中存在的错误,当指定 method='dense'pct=True 时,结果未能缩放到 100%

  • pandas.DataFrame.rolling()pandas.Series.rolling() 中存在的错误,其错误地接受了窗口大小为 0 而不是引发异常(GH 21286

数据类型特定

稀疏

  • SparseArray.shape 中存在的错误,之前它只返回 SparseArray.sp_values 的形状(GH 21126

索引

  • Series.reset_index() 中存在的错误,当使用无效的级别名称时,未引发适当的错误(GH 20925

  • interval_range() 中存在的错误,当使用浮点数 startend 指定 start/periodsend/periods 时(GH 21161

  • MultiIndex.set_names() 中存在的错误,当 MultiIndexnlevels == 1 时会引发错误(GH 21149

  • IntervalIndex 构造函数中存在的错误,从分类数据创建 IntervalIndex 未得到完全支持(GH 21243, GH 21253

  • MultiIndex.sort_index() 中存在的错误,无法保证在 level=1 时正确排序;这也导致了特定 DataFrame.stack() 操作中的数据错位(GH 20994, GH 20945, GH 21052

绘图

  • 新增关键字 (sharex, sharey) 用于开启/关闭由 pandas.DataFrame().groupby().boxplot() 生成的子图的 x/y 轴共享功能(GH 20968

I/O

  • 在指定 compression='zip' 的 I/O 方法中存在的错误,导致生成未压缩的 zip 归档文件(GH 17778, GH 21144

  • DataFrame.to_stata() 中存在的错误,阻止了将 DataFrame 导出到缓冲区和大多数类文件对象(GH 21041

  • read_stata()StataReader 中存在的错误,在 Python 3 上未能正确解码 Stata 14 文件(dta 版本 118)中的 utf-8 字符串(GH 21244

  • 在 I/O JSON read_json() 中存在的错误,当使用 orient='table' 读取空 JSON 模式并转换回 DataFrame 时导致错误(GH 21287

重塑

  • concat() 中存在的错误,当将 Series 与 numpy 标量和元组名称连接时会引发错误(GH 21015

  • concat() 警告消息中存在的错误,提供了关于未来行为的错误指导(GH 21101

其他

  • 在 IPython 中对 Index 进行 Tab 补全不再输出弃用警告(GH 21125

  • 阻止 pandas 在未安装 C++ 可再发行组件的 Windows 上使用的错误(GH 21106

贡献者#

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

  • Adam J. Stewart

  • Adam Kim +

  • Aly Sivji

  • Chalmer Lowe +

  • Damini Satya +

  • Dr. Irv

  • Gabe Fernando +

  • Giftlin Rajaiah

  • Jeff Reback

  • Jeremy Schendel +

  • Joris Van den Bossche

  • Kalyan Gokhale +

  • Kevin Sheppard

  • Matthew Roeschke

  • Max Kanter +

  • Ming Li

  • Pyry Kovanen +

  • Stefano Cianciulli

  • Tom Augspurger

  • Uddeshya Singh +

  • Wenhuan

  • William Ayd

  • chris-b1

  • gfyoung

  • h-vetinari

  • nprad +

  • ssikdar1 +

  • tmnhat2001

  • topper-123

  • zertrin +