0.23.1 版本的新内容(2018年6月12日)#

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

警告

自2019年1月1日起,pandas 功能版本将仅支持 Python 3。更多信息请参见 Dropping Python 2.7

修复回归问题#

将系列与 datetime.date 进行比较

我们恢复了 0.23.0 版本中对持有日期时间的 Seriesdatetime.date 对象进行比较的更改 (GH 21152)。在 pandas 0.22 及更早版本中,比较持有日期时间的 Series 和 datetime.date 对象时,会将 datetime.date 强制转换为日期时间后再进行比较。这与 Python、NumPy 和 DatetimeIndex 不一致,后者从不认为日期时间和 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 返回了 tz-aware 时间而不是 tz-naive (GH 21267),并且当输入日期具有非UTC时区时,DatetimeIndex.date 返回了不正确的日期 (GH 21230)。

  • 修复了在 JSON 的嵌套级别中调用包含 None 值的 pandas.io.json.json_normalize() 时的回归问题,并且不会删除值为 None 的键 (GH 21158, GH 21356)。

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

  • 阻止 pandas 在 -OO 优化下可导入的错误 (GH 21071)

  • Categorical.fillna() 中的错误在 value 是可迭代且 value 是可迭代时,不正确地引发 TypeError (GH 21097, GH 19788)

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

  • pivot_table() 中的回归,其中对于枢轴的 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.agg() 中的一个错误,当对一个具有重复列名的 DataFrame 应用多个聚合函数时会导致堆栈溢出 (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)

  • start/periodsend/periods 与浮点数 startend 一起指定时,interval_range() 中的错误 (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' 的 IO 方法中的错误,产生了未压缩的 zip 存档 (GH 17778, GH 21144)

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

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

  • IO JSON 中的 read_json() 在以 orient='table' 读取空的 JSON 模式并返回 DataFrame 时导致了一个错误 (GH 21287)

重塑

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

  • concat() 警告信息中存在错误,提供了错误的行为指导 (GH 21101)

其他

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

  • 阻止在未安装C++可再发行组件的Windows上使用pandas的错误 (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 +