1.4.0 版本中的新功能 (2022年1月22日)#
这是 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
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
,它将继续转换为 numpy dtype 直到 pandas 2.0。届时,它将像其他 ExtensionArrays 一样保留其 dtype。
Styler#
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)关键字参数
level
和names
已添加到Styler.hide()
中(以及隐式添加到已废弃的方法Styler.hide_index()
和Styler.hide_columns()
中),以便进一步控制 MultiIndexes 和 Index 名称的可见性 (GH 25475, GH 43404, GH 43346)The
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),并且它还验证输入参数width
和height
(GH 42511)
Styler.to_html()
引入了关键字参数sparse_index
,sparse_columns
,bold_headers
,caption
,max_rows
和max_columns
(GH 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)
滚动和扩展窗口的 Rank 函数#
将 rank
函数添加到 Rolling
和 Expanding
中。新函数支持 DataFrame.rank()
的 method
、ascending
和 pct
标志。method
参数支持 min
、max
和 average
排名方法。示例
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
Groupby 位置索引#
现在可以指定相对于每个组末尾的位置范围。
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'
选项#
新的 'tight'
字典格式现在可用于 DataFrame.from_dict()
和 DataFrame.to_dict()
方法,该格式保留了 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']}
其他增强功能#
使用
as_index=False
的DataFrameGroupBy
操作现在可以正确保留被分组列的ExtensionDtype
dtypes (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()
现在支持带'table'
选项的method
参数,该选项对整个DataFrame
执行窗口操作。有关性能和功能优势,请参阅 窗口概述 (GH 42273)DataFrameGroupBy.cummin()
、SeriesGroupBy.cummin()
、DataFrameGroupBy.cummax()
和SeriesGroupBy.cummax()
现在支持参数skipna
(GH 34047)read_table()
现在支持参数storage_options
(GH 39167)DataFrame.to_stata()
和StataWriter()
现在接受仅关键字参数value_labels
,用于保存非分类列的标签 (GH 38454)依赖于基于哈希映射算法的方法,例如
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
进行索引现在支持Ellipsis
(GH 37750)IntegerArray.all()
、IntegerArray.any()
、FloatingArray.any()
和FloatingArray.all()
使用 Kleene 逻辑 (GH 41967)在
DataFrame.to_stata()
、StataWriter
、StataWriter117
和StataWriterUTF8
中添加了对可空布尔类型和整数类型的支持 (GH 40855)DataFrame.__pos__()
和DataFrame.__neg__()
现在保留ExtensionDtype
dtypes (GH 43883)当可选依赖项无法导入时引发的错误现在包含原始异常,以便于调查 (GH 43882)
Series.str.split()
现在支持一个regex
参数,明确指定模式是否是正则表达式。默认值为None
(GH 43563, GH 32835, GH 25549)DataFrame.dropna()
现在接受单个标签作为subset
参数,同时兼容类数组输入 (GH 41021)添加了
DataFrameGroupBy.value_counts()
(GH 43564)read_csv()
现在在engine="python"
时接受on_bad_lines
参数的callable
函数,用于自定义处理错误行 (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()
现在支持使用engine
关键字进行 Numba 执行 (GH 43731, GH 44862, GH 44939)Timestamp.isoformat()
现在处理来自基础datetime
类的timespec
参数 (GH 26131)NaT.to_numpy()
的dtype
参数现已得到尊重,因此可以返回np.timedelta64
(GH 44460)新选项
display.max_dir_items
定制添加到Dataframe.__dir__()
并建议用于 Tab 补全的列数 (GH 37996)将“Juneteenth National Independence Day”添加到
USFederalHolidayCalendar
(GH 44574)Rolling.var()
,Expanding.var()
,Rolling.std()
, 和Expanding.std()
现在支持使用engine
关键字进行 Numba 执行 (GH 44461)添加了
Series.info()
,以兼容DataFrame.info()
(GH 5167)实现了
IntervalArray.min()
和IntervalArray.max()
,因此min
和max
现在适用于带有IntervalDtype
的IntervalIndex
,Series
和DataFrame
(GH 44746)UInt64Index.map()
现在尽可能保留dtype
(GH 44609)read_json()
现在可以解析 unsigned long long 整型数 (GH 26068)当为 indexer 传递标量时,
DataFrame.take()
现在会引发TypeError
(GH 42875)is_list_like()
现在将 duck-arrays 识别为 list-like,除非其.ndim == 0
(GH 35131)使用
orient='table'
导出DataFrame
时,ExtensionDtype
和ExtensionArray
现在可以被(反)序列化 (GH 20612, GH 44705)为
DataFrame.to_pickle()
/read_pickle()
及相关函数添加了对 Zstandard 压缩的支持 (GH 43925)DataFrame.to_sql()
现在返回写入行数的int
值 (GH 23998)
显著的 Bug 修复#
以下 Bug 修复可能会导致显著的行为变化。
日期字符串解析不一致#
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 有时会被忽略。现在这些 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-value#
对于 np.object_
-dtype,Series.value_counts()
和 Series.mode()
不再将 None
、NaT
及其他空值强制转换为 NaN-value。此行为现在与 unique
、isin
等函数一致 (GH 42688)。
In [18]: s = pd.Series([True, None, pd.NaT, None, pd.NaT, None])
In [19]: res = s.value_counts(dropna=False)
之前,所有空值都会被替换为 NaN-value。
旧的行为:
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#
之前,如果操作产生的结果元素数量超过 2**31 - 1
,DataFrame.pivot_table()
和 DataFrame.unstack()
会引发 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
,而另一些只会测试是否相等 (`equality`)。
此不一致已被移除,pandas 现在测试是否相等 (`equality`)。
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 (开发) |
6.0 |
||
mypy (开发) |
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
参数的位置发生变更,由于 docstring 的变更 (GH 44304)当为
skipna
参数传递None
时,DataFrame
或Series
的缩减操作现在会引发ValueError
(GH 44178)当其中一个标题行仅包含
Unnamed:
列时,read_csv()
和read_html()
不再引发错误 (GH 13054)更改了
USFederalHolidayCalendar
中几个节日的name
属性,以匹配 官方联邦假日名称,具体如下“New Year’s Day” 增加了所有格撇号
“Presidents Day” 变为 “Washington’s Birthday”
“Martin Luther King Jr. Day” 现在是 “Birthday of Martin Luther King, Jr.”
“July 4th” 现在是 “Independence Day”
“Thanksgiving” 现在是 “Thanksgiving Day”
“Christmas” 现在是 “Christmas Day”
添加了“Juneteenth National Independence Day”
废弃#
废弃 Int64Index, UInt64Index 和 Float64Index#
Int64Index
, UInt64Index
和 Float64Index
已被废弃,取而代之的是基础的 Index
类,并将从 Pandas 2.0 中移除 (GH 43028)。
构造数值索引时,可以使用基础的 Index
类来指定数据类型(这也适用于旧版 pandas)
# replace
pd.Int64Index([1, 2, 3])
# with
pd.Index([1, 2, 3], dtype="int64")
检查索引对象的数据类型时,可以将对 isinstance
的检查替换为对 dtype
的检查
# replace
isinstance(idx, pd.Int64Index)
# with
idx.dtype == "int64"
当前,为了保持向后兼容性,当给定数值数据时,对 Index
的调用将继续返回 Int64Index
, UInt64Index
和 Float64Index
,但在将来,将返回一个 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
、或为MultiIndex
且其开头的Float64Index
层不包含该键时 (GH 33469)废弃了当与时区一起传递给
Timestamp
构造函数时,将numpy.datetime64
对象视为 UTC 时间的处理方式。在未来版本中,它们将被视为当地时间。为了保留旧行为,请使用Timestamp(dt64).tz_localize("UTC").tz_convert(tz)
(GH 24559)废弃了当使用标签序列对
MultiIndex
的某个层进行索引时,忽略缺失标签的处理方式 (GH 42351)创建空的
Series
没有指定dtype
时,现在将引发更明显的FutureWarning
而非DeprecationWarning
(GH 30017)废弃了
Index.get_slice_bound()
,Index.slice_indexer()
和Index.slice_locs()
中的kind
参数;在未来版本中,传递kind
将引发错误 (GH 42857)废弃了在
Rolling
,Expanding
和EWM
聚合中删除无关列的处理方式 (GH 42738)弃用使用非唯一性
Index
调用Index.reindex()
的行为 (GH 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_start
和include_end
参数;在未来的版本中,传递include_start
或include_end
将会引发错误 (GH 40245)弃用
read_csv()
、read_table()
和read_excel()
中的squeeze
参数。用户应改为在之后使用.squeeze("columns")
来挤压DataFrame
(GH 43242)弃用
SparseArray
构造函数中的index
参数 (GH 23089)弃用
date_range()
和bdate_range()
中的closed
参数,推荐使用inclusive
参数;在未来的版本中,传递closed
将会引发错误 (GH 40245)弃用
Rolling.validate()
、Expanding.validate()
和ExponentialMovingWindow.validate()
(GH 43665)弃用在使用字典时,
Series.transform
和DataFrame.transform
默默丢弃引发TypeError
的列的行为 (GH 43740)弃用在使用列表时,
Series.aggregate()
、DataFrame.aggregate()
、Series.groupby.aggregate()
和DataFrame.groupby.aggregate()
默默丢弃引发TypeError
、DataError
以及某些情况下引发ValueError
的列的行为 (GH 43740)弃用在将时区感知值设置到时区感知的
Series
或DataFrame
列中时,如果时区不匹配,其类型转换的行为。之前这会转换为 object dtype。在未来的版本中,插入的值将转换为 series 或 column 的现有 timezone (GH 37605)弃用在将时区不匹配的项传递给
DatetimeIndex.insert()
、DatetimeIndex.putmask()
、DatetimeIndex.where()
、DatetimeIndex.fillna()
、Series.mask()
、Series.where()
、Series.fillna()
、Series.shift()
、Series.replace()
、Series.reindex()
(以及相应的DataFrame
列方法) 时,其类型转换的行为。过去这会转换为 objectdtype
。在未来的版本中,这些方法会将传入的项转换为索引或 series 的 timezone (GH 37605, GH 44940)弃用
read_csv()
和read_table()
中的prefix
关键字参数,在未来的版本中该参数将被移除 (GH 43396)弃用在
read_fwf()
中,除filepath_or_buffer
之外的参数使用位置参数传递的行为 (GH 41485)弃用在
read_xml()
中,除path_or_buffer
之外的参数使用位置参数传递的行为 (GH 45133)弃用为
DataFrame.mad()
和Series.mad()
传递skipna=None
,请改为传递skipna=True
(GH 44580)弃用使用字符串 “now” 调用
to_datetime()
时设置utc=False
的行为;在未来的版本中,这会与Timestamp("now")
匹配,而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)弃用对 bool-dtype 和 numeric-dtypes 对象进行
concat()
的行为;在未来的版本中,这些将转换为 object dtype,而不是将 bool 值强制转换为 numeric 值 (GH 39817)弃用
Categorical.replace()
,请改为使用Series.replace()
(GH 44929)弃用将
set
或dict
作为索引器传递给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)弃用在使用整数 dtype 时,
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
必须是True
或False
(默认为False
) (GH 45036)弃用
Timestamp.utcfromtimestamp()
的行为,在未来,它将返回一个时区感知的 UTCTimestamp
(GH 22451)弃用
NaT.freq()
(GH 45071)弃用当传入包含
NaN
的 float-dtype 数据和整数 dtype 时,Series
和DataFrame
构造函数忽略 dtype 参数的行为;在未来的版本中,这将会引发错误 (GH 40110)弃用当
name=None
时,Series.to_frame()
和Index.to_frame()
忽略name
参数的行为。目前,这意味着保留现有名称,但在未来,显式传递name=None
将在结果 DataFrame 中将列名设置为None
(GH 44212)
性能改进#
DataFrameGroupBy.sample()
和SeriesGroupBy.sample()
的性能改进,特别是在提供了weights
参数时 (GH 34483)将非字符串数组转换为字符串数组时的性能改进 (GH 34483)
DataFrameGroupBy.transform()
和SeriesGroupBy.transform()
在处理用户定义函数时的性能改进 (GH 41598)构造
DataFrame
对象的性能改进 (GH 42631, GH 43142, GH 43147, GH 43307, GH 43144, GH 44826)DataFrameGroupBy.shift()
和SeriesGroupBy.shift()
在提供fill_value
参数时的性能改进 (GH 26615)DataFrame.corr()
方法在使用method=pearson
处理不含缺失值的数据时的性能改进 (GH 40956)某些
DataFrameGroupBy.apply()
和SeriesGroupBy.apply()
操作的性能改进 (GH 42992, GH 43578)read_stata()
的性能改进 (GH 43059, GH 43227)read_sas()
的性能改进 (GH 43333)to_datetime()
处理uint
dtypes 时的性能改进 (GH 42606)to_datetime()
在设置infer_datetime_format
为True
时的性能改进 (GH 43901)Series.sparse.to_coo()
的性能改进 (GH 42880)使用
UInt64Index
进行索引时的性能改进 (GH 43862)使用
Float64Index
进行索引时的性能改进 (GH 43705)在
MultiIndex
上使用类似列表的索引器进行索引时的性能改进 (GH 43370)在另一个
MultiIndex
上使用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 43675, GH 42841)性能改进:
DataFrameGroupBy.std()
和SeriesGroupBy.std()
(GH 43115, GH 43576)性能改进:
DataFrameGroupBy.cumsum()
和SeriesGroupBy.cumsum()
(GH 43309)SparseArray.min()
和SparseArray.max()
不再需要转换为密集数组 (GH 43526)使用步长为 1 的
slice
对SparseArray
进行切片索引时,不再需要转换为密集数组 (GH 43777)性能改进:使用
allow_fill=False
的SparseArray.take()
(GH 43654)性能改进:使用
engine="numba"
的Rolling.mean()
,Expanding.mean()
,Rolling.sum()
,Expanding.sum()
,Rolling.max()
,Expanding.max()
,Rolling.min()
和Expanding.min()
(GH 43612, GH 44176, GH 45170)提高
pandas.read_csv()
使用memory_map=True
且文件编码为 UTF-8 时的性能 (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
的聚合操作 (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)性能改进:当索引列是日期时间类型且已格式化时,
to_csv()
的性能 (GH 39413)性能改进:当
MultiIndex
包含许多未使用的级别时,to_csv()
的性能 (GH 37484)性能改进:当
index_col
设置为数值列时,read_csv()
的性能 (GH 44158)性能改进:
SparseArray.__getitem__()
(GH 23122)
错误修复#
分类数据#
错误:将 dtype 不兼容的值设置到
Categorical
(或由Categorical
支持的Series
或DataFrame
)中时,会抛出ValueError
而非TypeError
(GH 41919)错误:在
Categorical.searchsorted()
中传递 dtype 不兼容的值时,会抛出KeyError
而非TypeError
(GH 41919)错误:
Categorical.astype()
将日期时间和Timestamp
强制转换为 dtypeobject
的整型 (GH 44930)错误:在带有
CategoricalDtype
的Series.where()
中传递 dtype 不兼容的值时,会抛出ValueError
而非TypeError
(GH 41919)错误:在
Categorical.fillna()
中传递 dtype 不兼容的值时,会抛出ValueError
而非TypeError
(GH 41919)错误:在带有类似元组的类别的
Categorical.fillna()
中,用非类别元组填充时,会抛出ValueError
而非TypeError
(GH 41919)
日期时间类#
错误:在使用
format
和pandas.NA
的to_datetime()
中,曾抛出ValueError
(GH 42957)to_datetime()
如果无法遵守给定的dayfirst
选项,会静默地交换MM/DD/YYYY
和DD/MM/YYYY
格式 - 现在,对于带分隔符的日期字符串(例如31-12-2012
),会发出警告 (GH 12585)错误:当
start
=end
且集合在一侧闭合时,date_range()
和bdate_range()
不返回右边界 (GH 43394)错误:对
DatetimeIndex
或TimedeltaIndex
进行原地加法和减法操作(与DatetimeArray
或TimedeltaArray
一起)(GH 43904)错误:在 timezone-aware 的
DatetimeIndex
上调用np.isnan
,np.isfinite
, 或np.isinf
时,错误地抛出TypeError
(GH 43917)错误:将
Tick
对象与np.timedelta64
对象相加时,错误地抛出异常,而非返回Timedelta
(GH 44474)np.maximum.reduce
和np.minimum.reduce
现在在对 dtype 为datetime64[ns]
或timedelta64[ns]
的Series
,DataFrame
, 或Index
进行操作时,正确地返回Timestamp
和Timedelta
对象 (GH 43923)错误:将
np.timedelta64
对象添加到BusinessDay
或CustomBusinessDay
对象时,错误地抛出异常 (GH 44532)错误:在
Index.insert()
中,将np.datetime64
,np.timedelta64
或tuple
插入到 dtype 为object
的Index
中时,负数 loc 会添加None
并替换现有值 (GH 44509)错误:
Timestamp.to_pydatetime()
未能保留fold
属性 (GH 45087)错误:带有
DatetimeTZDtype
的Series.mode()
错误地返回 timezone-naive,而带有PeriodDtype
的则错误地抛出异常 (GH 41927)修复了
reindex()
中的回归错误,当使用与日期时间类 dtype 不兼容的填充值时会抛出错误(或在使用datetime.date
作为填充值时未抛出弃用警告)(GH 42921)错误:在
DateOffset
与Timestamp
相加时,结果中不包含offset.nanoseconds
部分 (GH 43968, GH 36589)错误:
Timestamp.fromtimestamp()
不支持tz
参数 (GH 45083)错误:从
Series
字典构建DataFrame
时,如果索引 dtype 不匹配,有时会根据传入字典的顺序抛出异常 (GH 44091)错误:在某些夏令时转换期间,
Timestamp
的哈希计算导致了分段错误 (GH 33931 and GH 40817)
时间差#
时区#
错误:在使用
infer_datetime_format=True
的to_datetime()
中,未能正确解析零 UTC 偏移量(Z
)(GH 41047)错误:
Series.dt.tz_convert()
重置了带有CategoricalIndex
的Series
的索引 (GH 43080)错误:在对两个时区不匹配的 timezone-aware 对象进行减法运算时,
Timestamp
和DatetimeIndex
错误地抛出TypeError
(GH 31793)
数值#
错误:在
DataFrame.rank()
中,当列为object
且method="first"
时,会抛出ValueError
(GH 41931)错误:
DataFrame.rank()
将缺失值和极端值视为相等(例如np.nan
和np.inf
),导致在使用na_option="bottom"
或na_option="top
时结果不正确 (GH 41931)错误:当选项
compute.use_numexpr
设置为False
时,仍然使用了numexpr
引擎 (GH 32556)错误:在
DataFrame
中,当子类的_constructor()
属性是除子类本身之外的可调用对象时,算术运算出现问题 (GH 43201)错误:涉及
RangeIndex
的算术运算中,结果的name
不正确 (GH 43962)错误:涉及
Series
的算术运算中,当操作数的 NA 匹配或元组名称匹配时,结果的name
可能不正确 (GH 44459)错误:带有
IntegerDtype
或BooleanDtype
数组以及 NA 标量的除法运算错误地抛出异常 (GH 44685)错误:将带有
FloatingDtype
的Series
与类似时间差的标量相乘时,错误地抛出异常 (GH 44772)
转换#
错误:在
UInt64Index
构造函数中,传递包含足够小可转换为 int64 的正整数和过大无法容纳在 int64 中的整数列表时出现问题 (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.DataArray
和unit="ns"
时引发TypeError
错误 (GH 44053)当子类未重载
_constructor_sliced()
时,DataFrame.convert_dtypes()
未返回正确类型时存在错误 (GH 43201)DataFrame.astype()
未从原始DataFrame
传播attrs
时存在错误 (GH 44414)DataFrame.convert_dtypes()
结果丢失columns.names
时存在错误 (GH 41435)从 pyarrow 数据构建
IntegerArray
失败未能验证 dtypes 时存在错误 (GH 44891)Series.astype()
不允许从PeriodDtype
转换为datetime64
dtype,与PeriodIndex
的行为不一致时存在错误 (GH 45038)
字符串#
检查
string[pyarrow]
dtype 在未安装 pyarrow 时错误地引发ImportError
时存在错误 (GH 44276)
区间#
当
where
调用不应替换任何内容时,带有IntervalDtype
的Series.where()
错误地引发异常时存在错误 (GH 44181)
索引#
使用
MultiIndex
并提供了level
时,Series.rename()
中存在错误 (GH 43659)当对象的
Index
长度大于 1 但只有一个唯一值时,DataFrame.truncate()
和Series.truncate()
中存在错误 (GH 42365)使用
MultiIndex
且索引为元组(其中一层也是元组)时,Series.loc()
和DataFrame.loc()
中存在错误 (GH 27591)使用
MultiIndex
(其第一层仅包含np.nan
值)时,Series.loc()
中存在错误 (GH 42055)在带有
DatetimeIndex
的Series
或DataFrame
上使用字符串进行索引时存在错误,返回类型取决于索引是否单调 (GH 24892)在
MultiIndex
上进行索引时存在错误,当索引器是包含类日期时间字符串的元组时,未能删除标量层级 (GH 42476)传递升序值时,
DataFrame.sort_values()
和Series.sort_values()
存在错误,未能引发或错误地引发ValueError
(GH 41634)使用由
pandas.DataFrame.pop()
创建的布尔索引更新pandas.Series
的值时存在错误 (GH 42530)当索引包含多个
np.nan
时,Index.get_indexer_non_unique()
中存在错误 (GH 35392)当在查询
DataFrame
的表达式中使用诸如 `Temp(°C)` 这样的反引号列名时,DataFrame.query()
未处理度符号时存在错误 (GH 42826)当引发
KeyError
时,DataFrame.drop()
的错误消息未显示带有逗号的缺失标签时存在错误 (GH 42881)当安装了
numexpr
包时,DataFrame.query()
中查询字符串中的方法调用导致错误时存在错误 (GH 22435)当排序结果未计算包含
np.nan
的索引时,DataFrame.nlargest()
和Series.nlargest()
中存在错误 (GH 28984)在非唯一对象 dtype 的
Index
上使用 NA 标量(例如np.nan
)进行索引时存在错误 (GH 43711)当新旧 dtype 匹配时,
DataFrame.__setitem__()
未设置新数组,而是错误地写入现有列的数组时存在错误 (GH 43406)将浮点 dtype 值设置到整型 dtype 的
Series
中时存在错误,当这些值可以无损转换为整数时,未能就地设置 (GH 44316)当使用匹配大小和 dtype='datetime64[ns]' 或 dtype='timedelta64[ns]' 的数组进行设置时,对象 dtype 的
Series.__setitem__()
错误地将日期时间/时间差转换为整数时存在错误 (GH 43868)当索引已排序时,
DataFrame.sort_index()
未遵守ignore_index=True
时存在错误 (GH 43591)当索引包含多个
np.datetime64("NaT")
和np.timedelta64("NaT")
时,Index.get_indexer_non_unique()
中存在错误 (GH 43869)当标量的边界为浮点数而值的边界为整数时,将标量
Interval
值设置到具有IntervalDtype
的Series
中时存在错误 (GH 44201)当将可解析为日期时间的字符串支持的
Categorical
值设置到DatetimeArray
或由DatetimeArray
支持的Series
或DataFrame
列时,未能解析这些字符串时存在错误 (GH 44236)当使用非
int64
的整型 dtype 的Series.__setitem__()
使用range
对象进行设置时,不必要地向上转换为int64
时存在错误 (GH 44261)使用布尔掩码索引器设置长度为 1 的类列表值时,
Series.__setitem__()
错误地广播该值时存在错误 (GH 44265)当
drop
和inplace
设置为True
时,Series.reset_index()
未忽略name
参数时存在错误 (GH 44575)使用混合 dtypes 的
DataFrame.loc.__setitem__()
和DataFrame.iloc.__setitem__()
有时无法就地操作时存在错误 (GH 44345)使用布尔键选择单列时,
DataFrame.loc.__getitem__()
错误地引发KeyError
错误 (GH 44322)。使用单个
ExtensionDtype
列和设置二维值(例如df.iloc[:] = df.values
)时,DataFrame.iloc()
错误地引发异常时存在错误 (GH 44514)使用单个
ExtensionDtype
列和作为索引器的数组元组,使用DataFrame.iloc()
设置值时存在错误 (GH 44703)使用负步长切片在带有
ExtensionDtype
列的loc
或iloc
上进行索引时错误地引发异常时存在错误 (GH 44551)当索引器完全为
False
时,DataFrame.loc.__setitem__()
更改 dtype 时存在错误 (GH 37550)对于非唯一且非单调的索引,
IntervalIndex.get_indexer_non_unique()
返回布尔掩码而不是整型数组时存在错误 (GH 44084)当目标为带有 NaN 的 'object'
dtype
时,IntervalIndex.get_indexer_non_unique()
未正确处理时存在错误 (GH 44482)修复了将单列
np.matrix
添加到DataFrame
时不再强制转换为一维np.ndarray
的回归问题 (GH 42376)带有整型
CategoricalIndex
的Series.__getitem__()
将整型列表视为位置索引器,与单个标量整型的行为不一致时存在错误 (GH 15470, GH 14865)将浮点数或整数设置到整型 dtype 的
Series
中时,Series.__setitem__()
在必要时未能向上转换以保留精度时存在错误 (GH 45121)DataFrame.iloc.__setitem__()
忽略 axis 参数时存在错误 (GH 45032)
缺失值#
当指定了
limit
但未指定method
时,DataFrame.fillna()
忽略axis='columns'
或axis = 1
时存在错误 (GH 40989, GH 17399)使用字典状的
value
和重复的列名时,DataFrame.fillna()
未替换缺失值时存在错误 (GH 43476)以字典格式的
np.datetime64
作为值且dtype='timedelta64[ns]'
构建DataFrame
,或反之亦然时存在错误,错误地进行了类型转换而不是引发异常 (GH 44428)当
inplace=True
时,Series.interpolate()
和DataFrame.interpolate()
未就地写入底层数组时存在错误 (GH 44749)当存在 NA 值并指定了
downcast
参数时,Index.fillna()
错误地返回未填充的Index
时存在错误。现在将转而引发NotImplementedError
;请勿传递downcast
参数 (GH 44873)即使没有条目被删除,
DataFrame.dropna()
也更改Index
时存在错误 (GH 41965)带有对象 dtype 的
Series.fillna()
错误地忽略downcast="infer"
时存在错误 (GH 44241)
多层索引#
当第一层为
DatetimeIndex
且传递了字符串键时,MultiIndex.get_loc()
中存在错误 (GH 42465)传递对应于
ExtensionDtype
层的level
时,MultiIndex.reindex()
中存在错误 (GH 42043)在嵌套元组上,
MultiIndex.get_loc()
引发TypeError
而不是KeyError
时存在错误 (GH 42440)MultiIndex.union()
设置错误的sortorder
导致后续使用切片进行索引操作时出错时存在错误 (GH 44752)当另一个值也是
MultiIndex
时,MultiIndex.putmask()
中存在错误 (GH 43212)MultiIndex.dtypes()
中,重复的层级名称每个名称只返回一个 dtype 时存在错误 (GH 45174)
输入/输出#
read_excel()
尝试从 .xlsx 文件读取图表工作表时存在错误 (GH 41448)当
record_path
长度大于 1 时,errors=ignore
未能忽略meta
的缺失值时,json_normalize()
中存在错误 (GH 41876)使用多行标题输入和将列名作为元组引用的参数时,
read_csv()
中存在错误 (GH 42446)当
colspecs
和names
长度不同时,read_fwf()
未引发ValueError
时存在错误 (GH 40830)将纯 Python 对象序列化为 JSON 时,
Series.to_json()
和DataFrame.to_json()
跳过了一些属性时存在错误 (GH 42768, GH 33043)反序列化(unpickling)对象 dtype 的
Index
时存在错误,错误地推断了数值 dtypes (GH 43188)读取长度不等的多行标题输入时,
read_csv()
错误地引发IndexError
时存在错误 (GH 43102)使用
engine="c"
分块读取文件且某些块的列少于标题时,read_csv()
引发ParserError
时存在错误 (GH 21211)read_csv()
存在错误,当期望文件路径名或类文件对象时,将异常类别从OSError
更改为TypeError
(GH 43366)使用
engine='python'
且指定了nrows
时,read_csv()
和read_fwf()
忽略除第一个以外的所有skiprows
时存在错误 (GH 44021, GH 10261)设置了
keep_date_col=True
时,read_csv()
将原始列保持为对象格式时存在错误 (GH 13378)read_json()
未正确处理非 numpy 的 dtypes(尤其是category
)时存在错误 (GH 21892, GH 33205)json_normalize()
中存在错误,多字符的sep
参数被错误地添加到每个键的前面 (GH 43831)读取缺少多层元数据的数据时,
json_normalize()
未遵守errors="ignore"
时存在错误 (GH 44312)当使用
engine="python"
且header
设置为None
时,read_csv()
使用第二行猜测隐式索引时存在错误 (GH 22144)在
read_csv()
中存在一个 bug,当给定names
且engine="c"
时无法识别错误行 (GH 22144)在
read_csv()
中存在一个 bug,当使用float_precision="round_trip"
时未跳过开头/结尾的空格 (GH 43713)Python 未构建 lzma 模块时的 bug:即使未使用 lzma 功能,在导入 pandas 时也会发出警告 (GH 43495)
在
read_csv()
中存在一个 bug,未对index_col
应用 dtype (GH 9435)使用
yaml.dump(frame)
转储/加载DataFrame
时存在的 bug (GH 42748)在
read_csv()
中存在一个 bug,当names
比header
长但与数据行数相等且engine="python"
时会引发ValueError
(GH 38453)在
ExcelWriter
中存在一个 bug,engine_kwargs
未传递给所有引擎 (GH 43442)在
read_csv()
中存在一个 bug,当parse_dates
与MultiIndex
列一起使用时会引发ValueError
(GH 8991)在
read_csv()
中存在一个 bug,当将\n
指定为delimiter
或sep
时未引发ValueError
,这与lineterminator
冲突 (GH 43528)在
to_csv()
中存在一个 bug,会将分类Series
中的 datetimes 转换为整数 (GH 40754)在
read_csv()
中存在一个 bug,在日期解析失败后会将列转换为 numeric 类型 (GH 11019)在
read_csv()
中存在一个 bug,在尝试日期转换之前未将NaN
值替换为np.nan
(GH 26203)在
read_csv()
中存在一个 bug,当尝试读取 .csv 文件并从可空整数类型推断索引列 dtype 时会引发AttributeError
(GH 44079)在
to_csv()
中存在一个 bug,总是将具有不同格式的 datetime 列强制转换为相同的格式 (GH 21734)设置了
compression
为'zip'
的DataFrame.to_csv()
和Series.to_csv()
不再创建包含以“.zip”结尾的文件的 zip 文件。而是更智能地尝试推断内部文件名 (GH 39465)在
read_csv()
中存在一个 bug,将布尔值和缺失值的混合列读取为浮点类型时,缺失值会变成 1.0 而不是 NaN (GH 42808, GH 34120)在
to_xml()
中存在一个 bug,使用扩展数组 dtype 的pd.NA
时会引发错误 (GH 43903)在
read_csv()
中存在一个 bug,同时传递date_parser
中的解析器和parse_dates=False
时,解析仍然被调用 (GH 44366)在
read_csv()
中存在一个 bug,当index_col
不是第一列时,未正确设置MultiIndex
列的名称 (GH 38549)在
read_csv()
中存在一个 bug,创建内存映射文件失败时会默默忽略错误 (GH 44766)在
read_csv()
中存在一个 bug,传递以二进制模式打开的tempfile.SpooledTemporaryFile
时会出错 (GH 44748)在
read_json()
中存在一个 bug,尝试解析包含“://”的 json 字符串时会引发ValueError
(GH 36271)在
read_csv()
中存在一个 bug,当engine="c"
且encoding_errors=None
时会导致段错误 (GH 45180)在
read_csv()
中存在一个 bug,usecols
的无效值会导致文件句柄未关闭 (GH 45384)修复了
DataFrame.to_json()
中的内存泄漏 bug (GH 43877)
Period#
将
Period
对象添加到np.timedelta64
对象时错误地引发TypeError
的 bug (GH 44182)在
PeriodIndex.to_timestamp()
中存在一个 bug,当索引的freq="B"
时,结果推断为freq="D"
而非freq="B"
(GH 44105)在
Period
构造函数中存在一个 bug,错误地允许使用np.timedelta64("NaT")
(GH 44507)在
PeriodIndex.to_timestamp()
中存在一个 bug,对于具有非连续数据的索引给出不正确的值 (GH 44100)在
Series.where()
中存在一个 bug,当不应该替换任何内容时,使用PeriodDtype
会错误地引发异常 (GH 45135)
绘图#
当给定非 numeric 数据时,
DataFrame.boxplot()
现在会引发ValueError
,而不是晦涩难懂的KeyError
或ZeroDivisionError
,这与其他绘图函数(如DataFrame.hist()
)保持一致 (GH 43480)
Groupby/resample/rolling#
在
SeriesGroupBy.apply()
中存在一个 bug,当底层Series
为空时,传递无法识别的字符串参数未能引发TypeError
(GH 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,使用可空整数 dtypes 时会丢失精度 (GH 41743)在
DataFrame.groupby.rolling.var()
中存在一个 bug,只会计算第一个组的 rolling variance (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 dtypes 会静默失败 (GH 42452)在
pandas.DataFrame.rolling()
沿行 (axis=1
) 操作时存在一个 bug,会错误地省略包含float16
和float32
的列 (GH 41779)在
Resampler.aggregate()
中存在一个 bug,不允许使用 Named Aggregation (GH 32803)在
Series.rolling()
中存在一个 bug,当Series
的dtype
为Int64
时会出错 (GH 43016)在
DataFrame.rolling.corr()
中存在一个 bug,当DataFrame
的列是MultiIndex
时会出错 (GH 21157)在
DataFrame.groupby.rolling()
中存在一个 bug,指定on
并调用__getitem__
会后续返回不正确的结果 (GH 43355)在
DataFrameGroupBy.apply()
和SeriesGroupBy.apply()
中存在一个 bug,对于基于时间的Grouper
对象,在分组向量包含NaT
的边界情况下会错误地引发ValueError
(GH 43500, GH 43515)在
DataFrameGroupBy.mean()
和SeriesGroupBy.mean()
中存在一个 bug,处理complex
dtype 时会失败 (GH 43701)在
Series.rolling()
和DataFrame.rolling()
中存在一个 bug,当center=True
且索引递减时,未正确计算第一行的窗口边界 (GH 43927)在
Series.rolling()
和DataFrame.rolling()
中存在一个 bug,对于带有不均匀纳秒的居中 datetimelike 窗口会出错 (GH 43997)在
DataFrameGroupBy.mean()
和SeriesGroupBy.mean()
中存在一个 bug,当列被至少选择两次时会引发KeyError
(GH 44924)在
DataFrameGroupBy.nth()
和SeriesGroupBy.nth()
中存在一个 bug,在axis=1
上会失败 (GH 43926)在
Series.rolling()
和DataFrame.rolling()
中存在一个 bug,如果索引包含重复项,则未遵守居中 datetime-like 窗口的右边界 (GH 3944)在
Series.rolling()
和DataFrame.rolling()
中存在一个 bug,使用返回不等长开始和结束数组的pandas.api.indexers.BaseIndexer
子类时,会发生段错误而不是引发ValueError
(GH 44470)在
Groupby.nunique()
中存在一个 bug,对于categorical
分组列,未遵守observed=True
(GH 45128)在
DataFrameGroupBy.head()
、SeriesGroupBy.head()
、DataFrameGroupBy.tail()
和SeriesGroupBy.tail()
中存在一个 bug,当dropna=True
时,未删除包含NaN
的组 (GH 45089)在
GroupBy.__iter__()
中存在一个 bug,在GroupBy
对象中选择列的子集后,它返回了所有列而不是所选子集 (GH 44821)在
Groupby.rolling()
中存在一个 bug,当传递非单调数据时,未能正确引发ValueError
(GH 43909)按具有
categorical
数据类型且长度与分组轴不相等的Series
分组时的 bug,引发了ValueError
(GH 44179)
重塑#
改进了从多维
numpy.ndarray
创建DataFrame
列时的错误消息 (GH 42463)在
concat()
中存在一个 bug,连接索引包含重复项和多个键的DataFrame
时,会创建带有重复级别条目的MultiIndex
(GH 42651)在
pandas.cut()
中存在一个 bug,作用于具有重复索引和非精确pandas.CategoricalIndex()
的Series
时会出错 (GH 42185, GH 42425)在
DataFrame.append()
中存在一个 bug,当附加的列不匹配时未能保留 dtypes (GH 43392)在
concat()
拼接bool
和boolean
dtypes 时存在一个 bug,导致结果是object
dtype 而不是boolean
dtype (GH 42800)在
crosstab()
中存在一个 bug,当输入是分类的Series
,且存在一个或两个Series
中不存在的类别,以及margins=True
时会出错。此前,缺失类别的边距值为NaN
。现在已正确报告为 0 (GH 43505)在
concat()
中存在一个 bug,当objs
参数都具有相同的索引且keys
参数包含重复项时会失败 (GH 43595)在
concat()
中存在一个 bug,忽略了sort
参数 (GH 43375)在
merge()
中存在一个 bug,使用MultiIndex
作为on
参数的列索引时,在内部分配列时会返回错误 (GH 43734)在
crosstab()
中存在一个 bug,当输入是列表或元组时会失败 (GH 44076)在
DataFrame.append()
中存在一个 bug,当附加Series
对象列表时未能保留index.name
(GH 44109)修复了
Dataframe.apply()
方法中的元数据传播问题,从而也修复了Dataframe.transform()
、Dataframe.nunique()
和Dataframe.mode()
的相同问题 (GH 28283)concat()
中的 bug,如果MultiIndex
的所有层级仅包含缺失值,则会将其转换为 float 类型 (GH 44900)DataFrame.stack()
中的 bug,在使用ExtensionDtype
列时会错误地引发异常 (GH 43561)merge()
中的 bug,在使用 on 关键字通过不同名称的索引进行连接时会引发KeyError
(GH 45094)Series.unstack()
中的 bug,在使用 object 时会对结果列进行不必要的类型推断 (GH 44595)MultiIndex.join()
中的 bug,在使用重叠的IntervalIndex
层级时出现问题 (GH 44096)DataFrame.replace()
和Series.replace()
中的 bug,结果dtype
会根据regex
参数而不同 (GH 44864)DataFrame.pivot()
中的 bug,在使用index=None
且DataFrame
索引为MultiIndex
时出现问题 (GH 23955)
稀疏#
DataFrame.sparse.to_coo()
中的 bug,在列名不唯一时会引发AttributeError
(GH 29564)SparseArray.max()
和SparseArray.min()
中的 bug,对于包含 0 个非 null 元素的数组会引发ValueError
(GH 43527)DataFrame.sparse.to_coo()
中的 bug,会将非零填充值静默转换为零 (GH 24817)SparseArray
比较方法中的 bug,在使用长度不匹配的 array-like 操作数进行比较时会引发AssertionError
或不明确的ValueError
(取决于输入) (GH 43863)SparseArray
算术方法floordiv
和mod
在除以零时的行为与非稀疏Series
的行为不匹配 (GH 38172)SparseArray
一元方法以及SparseArray.isna()
不会重新计算索引 (GH 44955)
扩展数组#
现在,对实现了
__abs__, __pos__, __neg__
的 ExtensionArrays 调用 NumPy ufuncsnp.abs
,np.positive
,np.negative
时能正确保留 dtype。特别是,此问题在TimedeltaArray
中已修复 (GH 43899, GH 23316)现在,NumPy ufuncs
np.minimum.reduce
,np.maximum.reduce
,np.add.reduce
和np.prod.reduce
在对带有IntegerDtype
或FloatDtype
的Series
调用时能正常工作,而不再引发NotImplementedError
(GH 43923, GH 44793)带有
out
关键字的 NumPy ufuncs 现在被带有IntegerDtype
和FloatingDtype
的数组所支持 (GH 45122)在使用带有扩展 dtype 的多列时,避免引发关于碎片化
DataFrame
的PerformanceWarning
(GH 44098)IntegerArray
和FloatingArray
构造函数中的 bug,会错误地将不匹配的 NA 值(例如np.timedelta64("NaT")
)强制转换为数值型 NA (GH 44514)BooleanArray.__eq__()
和BooleanArray.__ne__()
中的 bug,在与不兼容类型(如字符串)进行比较时会引发TypeError
。这导致DataFrame.replace()
在包含可为空的布尔列时有时会引发TypeError
(GH 44499)array()
中的 bug,在传递带有float16
dtype 的ndarray
时会错误地引发异常 (GH 44715)在
BooleanArray
上调用np.sqrt
时返回格式错误的FloatingArray
的 bug (GH 44715)Series.where()
中的 bug,在使用ExtensionDtype
且other
是与Series
dtype 不兼容的 NA 标量(例如,对于数值 dtype 使用NaT
)时,会错误地强制转换为兼容的 NA 值 (GH 44697)Series.replace()
中的 bug,显式传递value=None
会被视为未传递value
,且结果中不包含None
(GH 36984, GH 19998)Series.replace()
中的 bug,在无操作替换时会进行不必要的向下类型转换 (GH 44498)Series.replace()
中的 bug,带有FloatDtype
,string[python]
, 或string[pyarrow]
dtype 时无法在可能的情况下保留 dtype (GH 33484, GH 40732, GH 31644, GH 41215, GH 25438)
Styler#
Styler.to_html()
中的 bug,如果在调用to_html
方法时带有一些参数,Styler
对象会被更新 (GH 43034)Styler.copy()
中的 bug,之前未复制uuid
(GH 40675)Styler.apply()
中的 bug,返回Series
对象的函数在对齐其索引标签方面未得到正确处理 (GH 13657, GH 42014)渲染单层
MultiIndex
时出现的 bug (GH 43383)组合非稀疏渲染和
Styler.hide_columns()
或Styler.hide_index()
时出现的 bug (GH 43464)
其他#
DataFrame.astype()
中的 bug,在使用非唯一列和Series
dtype
参数时出现问题 (GH 44417)CustomBusinessMonthBegin.__add__()
(CustomBusinessMonthEnd.__add__()
) 中的 bug,当目标月的开始(结束)已经是工作日时,未应用额外的offset
参数 (GH 41356)RangeIndex.union()
中的 bug,当与另一个RangeIndex
合并时,如果步长step
匹配(甚至)且起始点相差小于step / 2
,则出现问题 (GH 44019)RangeIndex.difference()
中的 bug,在使用sort=None
且step<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=1
且periods
大于len(frame.columns)
时会生成无效的DataFrame
(GH 44978)DataFrame.diff()
中的 bug,当传递 NumPy 整数对象而不是int
对象时出现问题 (GH 44572)Series.replace()
中的 bug,在使用regex=True
且Series
包含np.nan
值时会引发ValueError
(GH 43344)DataFrame.to_records()
中的 bug,当缺失的名称被level_n
替换时,使用了不正确的n
(GH 44818)DataFrame.eval()
中的 bug,resolvers
参数覆盖了默认的解析器 (GH 34966)Series.__repr__()
和DataFrame.__repr__()
不再将索引中的所有 null 值替换为“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 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 +