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)

  • 关键字参数 levelnames 已添加到 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 特定渲染的一些增强功能

还有一些针对 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 函数添加到 RollingExpanding 中。新函数支持 DataFrame.rank()methodascendingpct 标志。method 参数支持 minmaxaverage 排名方法。示例

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']}

其他增强功能#

显著的 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_countsmode 中不再被强制转换为 NaN-value#

对于 np.object_-dtype,Series.value_counts()Series.mode() 不再将 NoneNaT 及其他空值强制转换为 NaN-value。此行为现在与 uniqueisin 等函数一致 (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

unstackpivot_table 不再对超过 int32 限制的结果引发 ValueError#

之前,如果操作产生的结果元素数量超过 2**31 - 1DataFrame.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 时,DataFrameSeries 的缩减操作现在会引发 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, UInt64IndexFloat64Index 已被废弃,取而代之的是基础的 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, UInt64IndexFloat64Index,但在将来,将返回一个 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, ExpandingEWM 聚合中删除无关列的处理方式 (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_startinclude_end 参数;在未来的版本中,传递 include_startinclude_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.transformDataFrame.transform 默默丢弃引发 TypeError 的列的行为 (GH 43740)

  • 弃用在使用列表时,Series.aggregate()DataFrame.aggregate()Series.groupby.aggregate()DataFrame.groupby.aggregate() 默默丢弃引发 TypeErrorDataError 以及某些情况下引发 ValueError 的列的行为 (GH 43740)

  • 弃用在将时区感知值设置到时区感知的 SeriesDataFrame 列中时,如果时区不匹配,其类型转换的行为。之前这会转换为 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 列方法) 时,其类型转换的行为。过去这会转换为 object dtype。在未来的版本中,这些方法会将传入的项转换为索引或 series 的 timezone (GH 37605, GH 44940)

  • 弃用 read_csv()read_table() 中的 prefix 关键字参数,在未来的版本中该参数将被移除 (GH 43396)

  • 弃用在 concat() 中向 sort 参数传递非布尔值参数的行为 (GH 41518)

  • 弃用在 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)

  • 弃用将 setdict 作为索引器传递给 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 必须是 TrueFalse (默认为 False) (GH 45036)

  • 弃用 Timestamp.utcfromtimestamp() 的行为,在未来,它将返回一个时区感知的 UTC Timestamp (GH 22451)

  • 弃用 NaT.freq() (GH 45071)

  • 弃用当传入包含 NaN 的 float-dtype 数据和整数 dtype 时,SeriesDataFrame 构造函数忽略 dtype 参数的行为;在未来的版本中,这将会引发错误 (GH 40110)

  • 弃用当 name=None 时,Series.to_frame()Index.to_frame() 忽略 name 参数的行为。目前,这意味着保留现有名称,但在未来,显式传递 name=None 将在结果 DataFrame 中将列名设置为 None (GH 44212)

性能改进#

错误修复#

分类数据#

  • 错误:将 dtype 不兼容的值设置到 Categorical(或由 Categorical 支持的 SeriesDataFrame)中时,会抛出 ValueError 而非 TypeError (GH 41919)

  • 错误:在 Categorical.searchsorted() 中传递 dtype 不兼容的值时,会抛出 KeyError 而非 TypeError (GH 41919)

  • 错误:Categorical.astype() 将日期时间和 Timestamp 强制转换为 dtype object 的整型 (GH 44930)

  • 错误:在带有 CategoricalDtypeSeries.where() 中传递 dtype 不兼容的值时,会抛出 ValueError 而非 TypeError (GH 41919)

  • 错误:在 Categorical.fillna() 中传递 dtype 不兼容的值时,会抛出 ValueError 而非 TypeError (GH 41919)

  • 错误:在带有类似元组的类别的 Categorical.fillna() 中,用非类别元组填充时,会抛出 ValueError 而非 TypeError (GH 41919)

日期时间类#

  • 错误:DataFrame 构造函数不必要地复制非日期时间类的二维对象数组 (GH 39272)

  • 错误:在使用 formatpandas.NAto_datetime() 中,曾抛出 ValueError (GH 42957)

  • to_datetime() 如果无法遵守给定的 dayfirst 选项,会静默地交换 MM/DD/YYYYDD/MM/YYYY 格式 - 现在,对于带分隔符的日期字符串(例如 31-12-2012),会发出警告 (GH 12585)

  • 错误:当 start = end 且集合在一侧闭合时,date_range()bdate_range() 不返回右边界 (GH 43394)

  • 错误:对 DatetimeIndexTimedeltaIndex 进行原地加法和减法操作(与 DatetimeArrayTimedeltaArray 一起)(GH 43904)

  • 错误:在 timezone-aware 的 DatetimeIndex 上调用 np.isnan, np.isfinite, 或 np.isinf 时,错误地抛出 TypeError (GH 43917)

  • 错误:从带有混合时区的日期时间字符串构建 Series 时,错误地部分推断日期时间值 (GH 40111)

  • 错误:将 Tick 对象与 np.timedelta64 对象相加时,错误地抛出异常,而非返回 Timedelta (GH 44474)

  • np.maximum.reducenp.minimum.reduce 现在在对 dtype 为 datetime64[ns]timedelta64[ns]Series, DataFrame, 或 Index 进行操作时,正确地返回 TimestampTimedelta 对象 (GH 43923)

  • 错误:将 np.timedelta64 对象添加到 BusinessDayCustomBusinessDay 对象时,错误地抛出异常 (GH 44532)

  • 错误:在 Index.insert() 中,将 np.datetime64, np.timedelta64tuple 插入到 dtype 为 objectIndex 中时,负数 loc 会添加 None 并替换现有值 (GH 44509)

  • 错误:Timestamp.to_pydatetime() 未能保留 fold 属性 (GH 45087)

  • 错误:带有 DatetimeTZDtypeSeries.mode() 错误地返回 timezone-naive,而带有 PeriodDtype 的则错误地抛出异常 (GH 41927)

  • 修复了 reindex() 中的回归错误,当使用与日期时间类 dtype 不兼容的填充值时会抛出错误(或在使用 datetime.date 作为填充值时未抛出弃用警告)(GH 42921)

  • 错误:在 DateOffsetTimestamp 相加时,结果中不包含 offset.nanoseconds 部分 (GH 43968, GH 36589)

  • 错误:Timestamp.fromtimestamp() 不支持 tz 参数 (GH 45083)

  • 错误:从 Series 字典构建 DataFrame 时,如果索引 dtype 不匹配,有时会根据传入字典的顺序抛出异常 (GH 44091)

  • 错误:在某些夏令时转换期间,Timestamp 的哈希计算导致了分段错误 (GH 33931 and GH 40817)

时间差#

  • 错误:将全为 NaTTimeDeltaIndex, SeriesDataFrame 列与 object-dtype 数字数组进行除法运算时,未能将结果推断为 timedelta64-dtype (GH 39750)

  • 错误:将 timedelta64[ns] 数据与标量进行整除运算时,返回了错误的值 (GH 44466)

  • 错误:Timedelta 现在正确地考虑了任何 kwargs 中的纳秒贡献 (GH 43764, GH 45227)

时区#

数值#

  • 错误:将整数列表或元组与 Series 进行整除运算时,错误地抛出异常 (GH 44674)

  • 错误:在 DataFrame.rank() 中,当列为 objectmethod="first" 时,会抛出 ValueError (GH 41931)

  • 错误:DataFrame.rank() 将缺失值和极端值视为相等(例如 np.nannp.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)

  • 错误:带有 IntegerDtypeBooleanDtype 数组以及 NA 标量的除法运算错误地抛出异常 (GH 44685)

  • 错误:将带有 FloatingDtypeSeries 与类似时间差的标量相乘时,错误地抛出异常 (GH 44772)

转换#

字符串#

  • 检查 string[pyarrow] dtype 在未安装 pyarrow 时错误地引发 ImportError 时存在错误 (GH 44276)

区间#

  • where 调用不应替换任何内容时,带有 IntervalDtypeSeries.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)

  • 在带有 DatetimeIndexSeriesDataFrame 上使用字符串进行索引时存在错误,返回类型取决于索引是否单调 (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 值设置到具有 IntervalDtypeSeries 中时存在错误 (GH 44201)

  • 当将可解析为日期时间的字符串支持的 Categorical 值设置到 DatetimeArray 或由 DatetimeArray 支持的 SeriesDataFrame 列时,未能解析这些字符串时存在错误 (GH 44236)

  • 当使用非 int64 的整型 dtype 的 Series.__setitem__() 使用 range 对象进行设置时,不必要地向上转换为 int64 时存在错误 (GH 44261)

  • 使用布尔掩码索引器设置长度为 1 的类列表值时,Series.__setitem__() 错误地广播该值时存在错误 (GH 44265)

  • dropinplace 设置为 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 列的 lociloc 上进行索引时错误地引发异常时存在错误 (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)

  • 带有整型 CategoricalIndexSeries.__getitem__() 将整型列表视为位置索引器,与单个标量整型的行为不一致时存在错误 (GH 15470, GH 14865)

  • 将浮点数或整数设置到整型 dtype 的 Series 中时,Series.__setitem__() 在必要时未能向上转换以保留精度时存在错误 (GH 45121)

  • DataFrame.iloc.__setitem__() 忽略 axis 参数时存在错误 (GH 45032)

缺失值#

多层索引#

输入/输出#

  • read_excel() 尝试从 .xlsx 文件读取图表工作表时存在错误 (GH 41448)

  • record_path 长度大于 1 时,errors=ignore 未能忽略 meta 的缺失值时,json_normalize() 中存在错误 (GH 41876)

  • 使用多行标题输入和将列名作为元组引用的参数时,read_csv() 中存在错误 (GH 42446)

  • colspecsnames 长度不同时,read_fwf() 未引发 ValueError 时存在错误 (GH 40830)

  • 将纯 Python 对象序列化为 JSON 时,Series.to_json()DataFrame.to_json() 跳过了一些属性时存在错误 (GH 42768, GH 33043)

  • 从 sqlalchemy 的 Row 对象构建 DataFrame 时,列标题被丢弃 (GH 40682)

  • 反序列化(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,当给定 namesengine="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,当 namesheader 长但与数据行数相等且 engine="python" 时会引发 ValueError (GH 38453)

  • ExcelWriter 中存在一个 bug,engine_kwargs 未传递给所有引擎 (GH 43442)

  • read_csv() 中存在一个 bug,当 parse_datesMultiIndex 列一起使用时会引发 ValueError (GH 8991)

  • read_csv() 中存在一个 bug,当将 \n 指定为 delimitersep 时未引发 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,而不是晦涩难懂的 KeyErrorZeroDivisionError,这与其他绘图函数(如 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,会错误地省略包含 float16float32 的列 (GH 41779)

  • Resampler.aggregate() 中存在一个 bug,不允许使用 Named Aggregation (GH 32803)

  • Series.rolling() 中存在一个 bug,当 SeriesdtypeInt64 时会出错 (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() 拼接 boolboolean 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=NoneDataFrame 索引为 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 算术方法 floordivmod 在除以零时的行为与非稀疏 Series 的行为不匹配 (GH 38172)

  • SparseArray 一元方法以及 SparseArray.isna() 不会重新计算索引 (GH 44955)

扩展数组#

  • array() 中的 bug,未能保留 PandasArray (GH 43887)

  • 现在,对实现了 __abs__, __pos__, __neg__ 的 ExtensionArrays 调用 NumPy ufuncs np.abs, np.positive, np.negative 时能正确保留 dtype。特别是,此问题在 TimedeltaArray 中已修复 (GH 43899, GH 23316)

  • 现在,NumPy ufuncs np.minimum.reduce, np.maximum.reduce, np.add.reducenp.prod.reduce 在对带有 IntegerDtypeFloatDtypeSeries 调用时能正常工作,而不再引发 NotImplementedError (GH 43923, GH 44793)

  • 带有 out 关键字的 NumPy ufuncs 现在被带有 IntegerDtypeFloatingDtype 的数组所支持 (GH 45122)

  • 在使用带有扩展 dtype 的多列时,避免引发关于碎片化 DataFramePerformanceWarning (GH 44098)

  • IntegerArrayFloatingArray 构造函数中的 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,在使用 ExtensionDtypeother 是与 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 中的 bug,初始化时的 uuid 保持了一个浮动的下划线 (GH 43037)

  • Styler.to_html() 中的 bug,如果在调用 to_html 方法时带有一些参数,Styler 对象会被更新 (GH 43034)

  • Styler.copy() 中的 bug,之前未复制 uuid (GH 40675)

  • Styler.apply() 中的 bug,返回 Series 对象的函数在对齐其索引标签方面未得到正确处理 (GH 13657, GH 42014)

  • 渲染带有命名 Index 的空 DataFrame 时出现的 bug (GH 43305)

  • 渲染单层 MultiIndex 时出现的 bug (GH 43383)

  • 组合非稀疏渲染和 Styler.hide_columns()Styler.hide_index() 时出现的 bug (GH 43464)

  • Styler 中使用多个选择器时设置表格样式出现的 bug (GH 44011)

  • 行截断和列截断未能反映隐藏行的 bug (GH 43703, GH 44247)

其他#

  • 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=Nonestep<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=1ExtensionDtype 列时,传递不兼容的 fill_value 会错误地引发异常 (GH 44564)

  • DataFrame.shift() 中的 bug,当使用 axis=1periods 大于 len(frame.columns) 时会生成无效的 DataFrame (GH 44978)

  • DataFrame.diff() 中的 bug,当传递 NumPy 整数对象而不是 int 对象时出现问题 (GH 44572)

  • Series.replace() 中的 bug,在使用 regex=TrueSeries 包含 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 +