0.23.1 中的新特性(2018年6月12日)#
这是 0.23.x 系列的一个次要错误修复版本,包含一些小的回归修复和错误修复。我们建议所有用户升级到此版本。
警告
从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
。
其他修复
修复了在时区感知数据中
DatetimeIndex.date
和DatetimeIndex.time
属性的回归:DatetimeIndex.time
返回了时区感知时间而不是时区非感知时间(GH 21267),以及当输入日期具有非 UTC 时区时,DatetimeIndex.date
返回了不正确的日期(GH 21230)。修复了当
pandas.io.json.json_normalize()
在 JSON 嵌套级别中遇到None
值时的回归,并确保不删除值为None
的键(GH 21158, GH 21356)。阻止 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)。
性能改进#
错误修复#
分组/重采样/滚动操作
当对具有重复列名的
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)
数据类型特定
在 Python 3.5.2 上,
Series.str.replace()
方法会抛出TypeError
的错误(GH 21078)在
pandas.testing.assert_index_equal()
中存在的错误,当比较两个CategoricalIndex
对象且参数check_categorical=False
时,错误地引发了AssertionError
(GH 19776)
稀疏
在
SparseArray.shape
中存在的错误,之前它只返回SparseArray.sp_values
的形状(GH 21126)
索引
在
Series.reset_index()
中存在的错误,当使用无效的级别名称时,未引发适当的错误(GH 20925)在
interval_range()
中存在的错误,当使用浮点数start
或end
指定start
/periods
或end
/periods
时(GH 21161)在
MultiIndex.set_names()
中存在的错误,当MultiIndex
的nlevels == 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)
重塑
其他
贡献者#
共有 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 +