0.23.1 版本新特性 (2018 年 6 月 12 日)#
这是 0.23.x 系列中的一个小型 bug 修复版本,包含一些回归修复和 bug 修复。我们建议所有用户升级到此版本。
警告
从 2019 年 1 月 1 日起,pandas 特性发布版本将仅支持 Python 3。更多信息请参阅 停止支持 Python 2.7。
v0.23.1 版本新特性
已修复的回归问题#
比较 Series 和 datetime.date
我们撤销了 0.23.0 版本中关于比较包含日期时间值的 Series
和一个 datetime.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.date
和DatetimeIndex.time
属性在处理时区感知数据时的回归问题:DatetimeIndex.time
返回了时区感知时间而非时区无关时间 (GH 21267) 以及DatetimeIndex.date
在输入日期具有非 UTC 时区时返回了错误的日期 (GH 21230)。修复了在 JSON 嵌套层级中使用
None
值调用pandas.io.json.json_normalize()
时的回归问题,以及不丢弃值为None
的键的问题 (GH 21158, GH 21356)。阻止 pandas 在启用 -OO 优化时导入的 Bug (GH 21071)
Categorical.fillna()
中的 Bug 导致在单个类别是可迭代对象且value
也是可迭代对象时错误地引发了TypeError
(GH 21097, GH 19788)修复了构造函数在传递
dtype=str
时将None
等 NA 值强制转换为字符串的回归问题 (GH 21083)pivot_table()
中的回归问题,当用于透视表的有序Categorical
带有缺失值时,结果会错位 (GH 21133)修复了在布尔索引/列上合并时的回归问题 (GH 21119)。
性能改进#
Bug 修复#
Groupby/resample/rolling
DataFrame.agg()
中的 Bug,在对具有重复列名的DataFrame
应用多个聚合函数时会导致堆栈溢出 (GH 21063)GroupBy.ffill()
和GroupBy.bfill()
中的 Bug,由于实现中使用了非稳定排序,分组内的填充操作并非总是按预期应用 (GH 21207)GroupBy.rank()
中的 Bug,在指定method='dense'
和pct=True
时,结果未能缩放到 100%pandas.DataFrame.rolling()
和pandas.Series.rolling()
中的 Bug,错误地接受了窗口大小为 0,而未引发错误 (GH 21286)
数据类型相关
Series.str.replace()
中的 Bug,该方法在 Python 3.5.2 上抛出TypeError
(GH 21078)pandas.testing.assert_index_equal()
中的 Bug,在比较两个CategoricalIndex
对象并指定参数check_categorical=False
时错误地引发了AssertionError
(GH 19776)
稀疏
SparseArray.shape
中的 Bug,之前仅返回SparseArray.sp_values
的形状 (GH 21126)
索引
Series.reset_index()
中的 Bug,对于无效的层级名称未引发相应的错误 (GH 20925)interval_range()
中的 Bug,在使用浮点数start
或end
指定start
/periods
或end
/periods
时出现 (GH 21161)MultiIndex.set_names()
中的 Bug,对于nlevels == 1
的MultiIndex
引发了错误 (GH 21149)IntervalIndex
构造函数中的 Bug,从分类数据创建IntervalIndex
未完全支持 (GH 21243, GH 21253)MultiIndex.sort_index()
中的 Bug,无法保证在使用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 方法中的 Bug,生成了未压缩的 zip 档案 (GH 17778, GH 21144)DataFrame.to_stata()
中的 Bug,阻止了将 DataFrame 导出到缓冲区和大多数类文件对象 (GH 21041)read_stata()
和StataReader
中的 Bug,未能从 Stata 14 文件 (dta 版本 118) 正确解码 Python 3 上的 utf-8 字符串 (GH 21244)I/O JSON
read_json()
中的 Bug,在使用orient='table'
读取空的 JSON schema 并转回DataFrame
时导致了错误 (GH 21287)
重塑
其他
贡献者#
共有 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 +