2.1.0 版本的新功能(2023 年 8 月 30 日)#
这是 pandas 2.1.0 的更改。有关完整的更改日志(包括其他 pandas 版本),请参阅发布说明。
增强功能#
PyArrow 将成为 pandas 3.0 的必需依赖项#
从 pandas 3.0 开始,PyArrow 将成为 pandas 的必需依赖项。此决定是基于 PDEP 10 作出的。
这将带来更多对 pandas 用户非常有益的更改,包括但不限于:
默认将字符串推断为 PyArrow 支持的字符串,从而显著减少内存占用并大幅提升性能。
默认使用 PyArrow 推断更复杂的数据类型(dtype),例如
Decimal
、lists
、bytes
、structured data
等。与依赖于 Apache Arrow 的其他库具有更好的互操作性。
我们正在这里收集关于此决定的反馈。
默认避免对字符串使用 NumPy object dtype#
以前,所有字符串默认都存储在 NumPy object dtype 的列中。此版本引入了一个选项 future.infer_string
,它会将所有字符串推断为 PyArrow 支持的字符串,其 dtype 为 "string[pyarrow_numpy]"
。这是一种新的字符串 dtype 实现,它在比较操作中遵循 NumPy 的语义,并将返回 np.nan
作为缺失值指示符。设置此选项还将把 dtype "string"
推断为存储设置为 "pyarrow_numpy"
的 StringDtype
,而忽略选项 mode.string_storage
的值。
此选项仅在安装了 PyArrow 时有效。与 NumPy object 相比,PyArrow 支持的字符串显著减少了内存占用,并提供了巨大的性能改进(GH 54430)。
可以通过以下方式启用此选项:
pd.options.future.infer_string = True
此行为将在 pandas 3.0 中成为默认。
DataFrame 归约保留扩展数据类型(dtype)#
在 pandas 的先前版本中,DataFrame 归约(DataFrame.sum()
、DataFrame.mean()
等)的结果具有 NumPy dtypes,即使 DataFrame 包含扩展 dtypes。现在,当对具有共同 dtype 的 DataFrame 列进行归约时,pandas 可以保留其 dtypes(GH 52788)。
旧行为
In [1]: df = pd.DataFrame({"a": [1, 1, 2, 1], "b": [np.nan, 2.0, 3.0, 4.0]}, dtype="Int64")
In [2]: df.sum()
Out[2]:
a 5
b 9
dtype: int64
In [3]: df = df.astype("int64[pyarrow]")
In [4]: df.sum()
Out[4]:
a 5
b 9
dtype: int64
新行为
In [1]: df = pd.DataFrame({"a": [1, 1, 2, 1], "b": [np.nan, 2.0, 3.0, 4.0]}, dtype="Int64")
In [2]: df.sum()
Out[2]:
a 5
b 9
dtype: Int64
In [3]: df = df.astype("int64[pyarrow]")
In [4]: df.sum()
Out[4]:
a 5
b 9
dtype: int64[pyarrow]
请注意,现在 dtype 分别是 masked dtype 和 PyArrow dtype,而以前是 NumPy integer dtype。
为了允许 DataFrame 归约保留扩展 dtypes,ExtensionArray._reduce()
增加了一个新的关键字参数 keepdims
。调用 ExtensionArray._reduce()
并设置 keepdims=True
应返回沿归约轴长度为 1 的数组。为了保持向后兼容性,该参数目前不是必需的,但将来会变成必需的。如果在签名中找不到该参数,DataFrame 归约将无法保留扩展 dtypes。此外,如果找不到该参数,将发出 FutureWarning
,并且像 mypy 这样的类型检查器可能会抱怨签名与 ExtensionArray._reduce()
不兼容。
Copy-on-Write 改进#
当
func
就地修改Series
时,Series.transform()
未遵循 Copy-on-Write(GH 53747)调用
Index.values()
现在将返回一个只读的 NumPy 数组(GH 53704)当从 Index 对象字典构造 DataFrame 并指定
copy=False
时,DataFrame
构造函数现在将对这些 Index 对象使用惰性副本作为 DataFrame 的列(GH 52947)Series 或 DataFrame 的浅层复制 (
df.copy(deep=False)
) 现在也将返回行/列Index
对象的浅层复制,而不仅仅是数据的浅层复制,即结果的索引不再与原始索引相同 (df.copy(deep=False).index is df.index
不再为 True)(GH 53721)DataFrame.head()
和DataFrame.tail()
现在将返回深层复制(GH 54011)为
DataFrame.eval()
添加惰性复制机制(GH 53746)在启用 Copy-on-Write 时,尝试对临时列选择进行就地操作(例如,
df["a"].fillna(100, inplace=True)
)现在将始终发出警告。在此模式下,这种就地操作将永远无效,因为该选择被视为临时副本。这适用于:DataFrame.update / Series.update
DataFrame.fillna / Series.fillna
DataFrame.replace / Series.replace
DataFrame.clip / Series.clip
DataFrame.where / Series.where
DataFrame.mask / Series.mask
DataFrame.interpolate / Series.interpolate
DataFrame.ffill / Series.ffill
DataFrame.bfill / Series.bfill
新增 DataFrame.map()
方法并支持 ExtensionArrays#
已添加 DataFrame.map()
方法,并已弃用 DataFrame.applymap()
。 DataFrame.map()
的功能与 DataFrame.applymap()
相同,但新名称更能清晰地表明这是 Series.map()
的 DataFrame
版本(GH 52353)。
当给定一个可调用对象时,Series.map()
会将该可调用对象应用于 Series
的所有元素。类似地,DataFrame.map()
会将该可调用对象应用于 DataFrame
的所有元素,而 Index.map()
会将该可调用对象应用于 Index
的所有元素。
通常,不希望将可调用对象应用于数组中类似 nan 的值,为了避免这种情况,可以在调用 map
方法时使用 na_action="ignore"
参数,即 ser.map(func, na_action="ignore")
。然而,对于许多 ExtensionArray
和 Index
类型,na_action="ignore"
未实现,并且对于除可为空的数值类型(即 dtype 为 Int64
等)之外的任何 ExtensionArray
子类,na_action="ignore"
都无法正常工作。
na_action="ignore"
现在适用于所有数组类型(GH 52219、GH 51645、GH 51809、GH 51936、GH 52033;GH 52096)。
以前的行为:
In [1]: ser = pd.Series(["a", "b", np.nan], dtype="category")
In [2]: ser.map(str.upper, na_action="ignore")
NotImplementedError
In [3]: df = pd.DataFrame(ser)
In [4]: df.applymap(str.upper, na_action="ignore") # worked for DataFrame
0
0 A
1 B
2 NaN
In [5]: idx = pd.Index(ser)
In [6]: idx.map(str.upper, na_action="ignore")
TypeError: CategoricalIndex.map() got an unexpected keyword argument 'na_action'
新行为:
In [5]: ser = pd.Series(["a", "b", np.nan], dtype="category")
In [6]: ser.map(str.upper, na_action="ignore")
Out[6]:
0 A
1 B
2 NaN
dtype: category
Categories (2, object): ['A', 'B']
In [7]: df = pd.DataFrame(ser)
In [8]: df.map(str.upper, na_action="ignore")
Out[8]:
0
0 A
1 B
2 NaN
In [9]: idx = pd.Index(ser)
In [10]: idx.map(str.upper, na_action="ignore")
Out[10]: CategoricalIndex(['A', 'B', nan], categories=['A', 'B'], ordered=False, dtype='category')
此外,请注意 Categorical.map()
隐式地将其 na_action
默认设置为 "ignore"
。此默认值已被正式弃用,将来会更改为 None
,与其他所有数组类型保持一致。
DataFrame.stack()
的新实现#
pandas 重新实现了 DataFrame.stack()
。要使用新实现,请传递参数 future_stack=True
。这将成为 pandas 3.0 中唯一的选项。
以前的实现有两个主要的行为缺点。
以前的实现会不必要地在结果中引入 NA 值。用户可以通过传递
dropna=True
(默认值)来自动移除 NA 值,但这也会移除输入中存在的 NA 值。请参见下面的示例。以前使用
sort=True
(默认值)的实现有时会排序结果索引的一部分,有时则不会。如果输入的列不是MultiIndex
,则结果索引将永远不会排序。如果列是MultiIndex
,则在大多数情况下,来自堆叠列级别而生成的结果索引中的级别会进行排序。在极少数情况下,此类级别会以非标准顺序排序,具体取决于列的创建方式。
新实现 (future_stack=True
) 在堆叠多个级别时不再不必要地引入 NA 值,并且永不排序。因此,当使用 future_stack=True
时,参数 dropna
和 sort
将不被使用,并且必须保持未指定状态。这些参数将在下一个主要版本中移除。
In [11]: columns = pd.MultiIndex.from_tuples([("B", "d"), ("A", "c")])
In [12]: df = pd.DataFrame([[0, 2], [1, 3]], index=["z", "y"], columns=columns)
In [13]: df
Out[13]:
B A
d c
z 0 2
y 1 3
在旧版本 (future_stack=False
) 中,默认的 dropna=True
会移除不必要引入的 NA 值,但在此过程中仍会将 dtype 强制转换为 float64
。在新版本中,不会引入 NA 值,因此也不会强制转换 dtype。
In [14]: df.stack([0, 1], future_stack=False, dropna=True)
Out[14]:
z A c 2.0
B d 0.0
y A c 3.0
B d 1.0
dtype: float64
In [15]: df.stack([0, 1], future_stack=True)
Out[15]:
z B d 0
A c 2
y B d 1
A c 3
dtype: int64
如果输入包含 NA 值,旧版本在 dropna=True
时也会丢弃这些值,或在 dropna=False
时引入新的 NA 值。新版本保留输入中的所有值。
In [16]: df = pd.DataFrame([[0, 2], [np.nan, np.nan]], columns=columns)
In [17]: df
Out[17]:
B A
d c
0 0.0 2.0
1 NaN NaN
In [18]: df.stack([0, 1], future_stack=False, dropna=True)
Out[18]:
0 A c 2.0
B d 0.0
dtype: float64
In [19]: df.stack([0, 1], future_stack=False, dropna=False)
Out[19]:
0 A d NaN
c 2.0
B d 0.0
c NaN
1 A d NaN
c NaN
B d NaN
c NaN
dtype: float64
In [20]: df.stack([0, 1], future_stack=True)
Out[20]:
0 B d 0.0
A c 2.0
1 B d NaN
A c NaN
dtype: float64
其他增强功能#
Series.ffill()
和Series.bfill()
现在支持具有IntervalDtype
的对象(GH 54247)read_parquet()
添加了filters
参数以过滤数据,兼容两种engines
(引擎)(GH 53212)Categorical.map()
和CategoricalIndex.map()
现在有一个na_action
参数。Categorical.map()
原先隐式地将na_action
的默认值设置为"ignore"
。此默认值已被正式弃用,将来会更改为None
。另请注意,Series.map()
的默认na_action=None
,现在除非明确设置,否则对包含分类数据的 Series 的调用将使用na_action=None
(GH 44279)api.extensions.ExtensionArray
现在拥有map()
方法(GH 51809)DataFrame.applymap()
现在使用底层api.extensions.ExtensionArray
实例的map()
方法(GH 52219)MultiIndex.sort_values()
现在支持na_position
参数(GH 51612)MultiIndex.sortlevel()
和Index.sortlevel()
增加了新的关键字参数na_position
(GH 51612)arrays.DatetimeArray.map()
、arrays.TimedeltaArray.map()
和arrays.PeriodArray.map()
现在可以接受na_action
参数(GH 51644)arrays.SparseArray.map()
现在支持na_action
参数(GH 52096)。pandas.read_html()
现在在使用 URL 时支持storage_options
关键字,允许用户向出站 HTTP 请求添加头部信息(GH 49944)添加
Index.diff()
和Index.round()
方法(GH 19708)为
Styler
的escape
参数添加选项"latex-math"
,在格式化期间,此选项将不转义"\("
和"\)"
之间的所有字符(GH 51903)在
CategoricalDtype
的repr
信息中添加类别的数据类型(dtype)(GH 52179)为
read_excel()
添加engine_kwargs
参数(GH 52214)用于类型提示的有用类已添加到新子模块
pandas.api.typing
的公共 API 中(GH 48577)为
ArrowDtype
实现Series.dt.is_month_start
、Series.dt.is_month_end
、Series.dt.is_year_start
、Series.dt.is_year_end
、Series.dt.is_quarter_start
、Series.dt.is_quarter_end
、Series.dt.days_in_month
、Series.dt.unit
、Series.dt.normalize
、Series.dt.day_name()
、Series.dt.month_name()
、Series.dt.tz_convert()
(针对pyarrow.timestamp
)(GH 52388, GH 51718)当索引不是
MultiIndex
时,DataFrameGroupBy.agg()
和DataFrameGroupBy.transform()
现在支持使用多个键进行分组,适用于engine="numba"
(GH 53486)SeriesGroupBy.agg()
和DataFrameGroupBy.agg()
现在支持传入多个函数,适用于engine="numba"
(GH 53486)SeriesGroupBy.transform()
和DataFrameGroupBy.transform()
现在支持传入字符串作为函数,适用于engine="numba"
(GH 53579)DataFrame.stack()
增加了sort
关键字,用于指定生成的MultiIndex
级别是否进行排序(GH 15105)DataFrame.unstack()
增加了sort
关键字,用于指定生成的MultiIndex
级别是否进行排序(GH 15105)Series.explode()
现在支持 PyArrow 支持的列表类型(GH 53602)Series.str.join()
现在支持ArrowDtype(pa.string())
(GH 53646)为
Categorical.from_codes()
添加了validate
参数(GH 50975)添加了由
Series.interpolate()
和DataFrame.interpolate()
使用的ExtensionArray.interpolate()
(GH 53659)为
DataFrame.to_excel()
添加了engine_kwargs
参数(GH 53220)为
DatetimeTZDtype
实现了api.interchange.from_dataframe()
(GH 54239)在
DatetimeTZDtype
上实现了__from_arrow__
(GH 52201)实现了
__pandas_priority__
,以允许自定义类型在算术运算中优先于DataFrame
、Series
、Index
或ExtensionArray
,参见开发者指南(GH 48347)在使用
DataFrame.merge()
时改进了因列不兼容而产生的错误消息(GH 51861)通过
DataFrame.isetitem()
为DataFrame
设置错误数量的列时,改进了错误消息(GH 51701)改进了在使用
DataFrame.to_json()
时,由于index
和orient
参数不兼容而产生的错误处理(GH 52143)创建空数据(0 行)、无索引且列数不正确的 DataFrame 时,改进了错误消息(GH 52084)
向
VariableOffsetWindowIndexer
提供无效的index
或offset
参数时,改进了错误消息(GH 54379)允许
DataFrame.to_feather()
接受非默认Index
和非字符串列名(GH 51787)向
Series.apply()
和DataFrame.apply()
添加了一个新参数by_row
。当设置为False
时,提供的可调用对象将始终作用于整个 Series 或 DataFrame(GH 53400, GH 53601)。DataFrame.shift()
和Series.shift()
现在允许通过提供一个期数列表来进行多期移动(GH 44424)使用
numba
进行 Groupby 聚合(例如DataFrameGroupBy.sum()
)现在可以保留输入的数据类型,而不是强制转换为float64
(GH 44952)改进了
DataFrameGroupBy.agg()
失败时的错误消息(GH 52930)许多 read/to_* 函数,例如
DataFrame.to_pickle()
和read_csv()
,支持将压缩参数转发到lzma.LZMAFile
(GH 52979)Series.argmax()
、Series.argmin()
、Series.idxmax()
、Series.idxmin()
、Index.argmax()
、Index.argmin()
、DataFrame.idxmax()
、DataFrame.idxmin()
等归约方法现在支持 object-dtype(GH 4279, GH 18021, GH 40685, GH 43697)DataFrame.to_parquet()
和read_parquet()
现在将分别写入和读取attrs
(GH 54346)带有浮点类型或 timedelta64 类型的
Index.all()
和Index.any()
不再引发TypeError
,与Series.all()
和Series.any()
的行为一致(GH 54566)PyArrow 13.0 及更高版本现在支持对 PyArrow 支持的数据类型使用
Series.cummax()
、Series.cummin()
和Series.cumprod()
(GH 52085)添加了对 DataFrame Consortium 标准的支持(GH 54383)
提高了
DataFrameGroupBy.quantile()
和SeriesGroupBy.quantile()
的性能(GH 51722)PyArrow 支持的整数数据类型现在支持按位运算(GH 54495)
向后不兼容的 API 变更#
Python 最低版本提高#
pandas 2.1.0 支持 Python 3.9 及更高版本。
依赖项最低版本提高#
部分依赖项的最低支持版本已更新。如果已安装,现在需要
包 |
最低版本 |
必需 |
已更改 |
---|---|---|---|
numpy |
1.22.4 |
X |
X |
mypy (dev) |
1.4.1 |
X |
|
beautifulsoup4 |
4.11.1 |
X |
|
bottleneck |
1.3.4 |
X |
|
dataframe-api-compat |
0.1.7 |
X |
|
fastparquet |
0.8.1 |
X |
|
fsspec |
2022.05.0 |
X |
|
hypothesis |
6.46.1 |
X |
|
gcsfs |
2022.05.0 |
X |
|
jinja2 |
3.1.2 |
X |
|
lxml |
4.8.0 |
X |
|
numba |
0.55.2 |
X |
|
numexpr |
2.8.0 |
X |
|
openpyxl |
3.0.10 |
X |
|
pandas-gbq |
0.17.5 |
X |
|
psycopg2 |
2.9.3 |
X |
|
pyreadstat |
1.1.5 |
X |
|
pyqt5 |
5.15.6 |
X |
|
pytables |
3.7.0 |
X |
|
pytest |
7.3.2 |
X |
|
python-snappy |
0.6.1 |
X |
|
pyxlsb |
1.0.9 |
X |
|
s3fs |
2022.05.0 |
X |
|
scipy |
1.8.1 |
X |
|
sqlalchemy |
1.4.36 |
X |
|
tabulate |
0.8.10 |
X |
|
xarray |
2022.03.0 |
X |
|
xlsxwriter |
3.0.3 |
X |
|
zstandard |
0.17.0 |
X |
对于可选库,一般建议使用最新版本。
其他 API 变更#
arrays.PandasArray
已重命名为NumpyExtensionArray
,并且附加的数据类型名称从PandasDtype
更改为NumpyEADtype
;在下一个主要版本之前,导入PandasArray
仍然有效(GH 53694)
弃用#
在类似 setitem 的 Series 操作中弃用静默向上转型#
PDEP-6: https://pandas.ac.cn/pdeps/0006-ban-upcasting.html
在 Series(或 DataFrame 列)上,会静默向上转型 dtype 的类似 setitem 的操作已被弃用并显示警告。受影响的操作示例如下:
ser.fillna('foo', inplace=True)
ser.where(ser.isna(), 'foo', inplace=True)
ser.iloc[indexer] = 'foo'
ser.loc[indexer] = 'foo'
df.iloc[indexer, 0] = 'foo'
df.loc[indexer, 'a'] = 'foo'
ser[indexer] = 'foo'
其中 ser
是一个 Series
,df
是一个 DataFrame
,而 indexer
可以是切片、掩码、单个值、值列表或数组,或任何其他允许的索引器。
在将来的版本中,这些操作将引发错误,您应该先将数据类型转换为通用类型。
以前的行为:
In [1]: ser = pd.Series([1, 2, 3])
In [2]: ser
Out[2]:
0 1
1 2
2 3
dtype: int64
In [3]: ser[0] = 'not an int64'
In [4]: ser
Out[4]:
0 not an int64
1 2
2 3
dtype: object
新行为:
In [1]: ser = pd.Series([1, 2, 3])
In [2]: ser
Out[2]:
0 1
1 2
2 3
dtype: int64
In [3]: ser[0] = 'not an int64'
FutureWarning:
Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas.
Value 'not an int64' has dtype incompatible with int64, please explicitly cast to a compatible dtype first.
In [4]: ser
Out[4]:
0 not an int64
1 2
2 3
dtype: object
为了保留当前行为,在上述情况下,您可以先将 ser
转换为 object
dtype
In [21]: ser = pd.Series([1, 2, 3])
In [22]: ser = ser.astype('object')
In [23]: ser[0] = 'not an int64'
In [24]: ser
Out[24]:
0 not an int64
1 2
2 3
dtype: object
根据具体用例,转换为不同的 dtype 可能更合适。例如,在以下情况中,我们将数据类型转换为 float64
In [25]: ser = pd.Series([1, 2, 3])
In [26]: ser = ser.astype('float64')
In [27]: ser[0] = 1.1
In [28]: ser
Out[28]:
0 1.1
1 2.0
2 3.0
dtype: float64
欲了解更多信息,请参阅 https://pandas.ac.cn/pdeps/0006-ban-upcasting.html。
弃用解析混合时区的时间日期#
解析混合时区的时间日期已被弃用并显示警告,除非用户将 utc=True
传递给 to_datetime()
(GH 50887)
以前的行为:
In [7]: data = ["2020-01-01 00:00:00+06:00", "2020-01-01 00:00:00+01:00"]
In [8]: pd.to_datetime(data, utc=False)
Out[8]:
Index([2020-01-01 00:00:00+06:00, 2020-01-01 00:00:00+01:00], dtype='object')
新行为:
In [9]: pd.to_datetime(data, utc=False)
FutureWarning:
In a future version of pandas, parsing datetimes with mixed time zones will raise
a warning unless `utc=True`. Please specify `utc=True` to opt in to the new behaviour
and silence this warning. To create a `Series` with mixed offsets and `object` dtype,
please use `apply` and `datetime.datetime.strptime`.
Index([2020-01-01 00:00:00+06:00, 2020-01-01 00:00:00+01:00], dtype='object')
为了抑制此警告并避免在未来版本的 pandas 中出现错误,请指定 utc=True
In [29]: data = ["2020-01-01 00:00:00+06:00", "2020-01-01 00:00:00+01:00"]
In [30]: pd.to_datetime(data, utc=True)
Out[30]: DatetimeIndex(['2019-12-31 18:00:00+00:00', '2019-12-31 23:00:00+00:00'], dtype='datetime64[ns, UTC]', freq=None)
要创建具有混合偏移和 object
dtype 的 Series
,请使用 apply
和 datetime.datetime.strptime
In [31]: import datetime as dt
In [32]: data = ["2020-01-01 00:00:00+06:00", "2020-01-01 00:00:00+01:00"]
In [33]: pd.Series(data).apply(lambda x: dt.datetime.strptime(x, '%Y-%m-%d %H:%M:%S%z'))
Out[33]:
0 2020-01-01 00:00:00+06:00
1 2020-01-01 00:00:00+01:00
dtype: object
其他弃用#
弃用
DataFrameGroupBy.dtypes
,请检查底层对象的dtypes
代替(GH 51045)弃用
DataFrame._data
和Series._data
,请使用公共 API 代替(GH 33333)弃用
concat()
当任何被连接的对象长度为 0 时的行为;过去在确定结果 dtype 时会忽略空对象的 dtype,在未来版本中将不会(GH 39122)弃用
Categorical.to_list()
,请使用obj.tolist()
代替(GH 51254)弃用带有 datetime64 或
PeriodDtype
值的DataFrameGroupBy.all()
和DataFrameGroupBy.any()
,与Series
和DataFrame
的弃用一致(GH 34479)弃用
DataFrame.ewm()
、DataFrame.rolling()
、DataFrame.expanding()
中的axis=1
,请在调用方法前先进行转置(GH 51778)弃用
DataFrame.groupby()
和Grouper
构造函数中的axis=1
,请改用frame.T.groupby(...)
(GH 51203)弃用
Series.align()
和DataFrame.align()
中的broadcast_axis
关键字,请在调用align
之前向上转型,使用left = DataFrame({col: left for col in right.columns}, index=right.index)
(GH 51856)在
Index.fillna()
中废弃了downcast
关键字 (GH 53956)在
DataFrame.pct_change()
、Series.pct_change()
、DataFrameGroupBy.pct_change()
和SeriesGroupBy.pct_change()
中废弃了fill_method
和limit
关键字,请改为在调用pct_change
之前显式调用(例如)DataFrame.ffill()
或DataFrame.bfill()
(GH 53491)在
DataFrame.align()
和Series.align()
中废弃了method
、limit
和fill_axis
关键字,请改为显式地对对齐结果调用DataFrame.fillna()
或Series.fillna()
(GH 51856)在
Rolling.quantile()
和Expanding.quantile()
中废弃了quantile
关键字,请改为使用q
(GH 52550)在
DataFrame.take()
中废弃了接受切片的操作,请改为调用obj[slicer]
或传递整数序列 (GH 51539)在
DataFrame.idxmax()
、DataFrame.idxmin()
、Series.idxmax()
、Series.idxmin()
中,当存在所有或部分 NA 条目且skipna=False
时的行为被废弃;未来版本中,这会引发ValueError
(GH 51276)在
Series.agg()
中废弃了将函数应用于Series
中每个元素,并且仅在元素级操作失败时才应用于整个Series
的行为。未来版本中,提供给Series.agg()
的函数将始终仅应用于整个Series
。要保留当前行为,请改用Series.transform()
(GH 53325)在
DataFrame.agg()
中废弃了将函数列表应用于DataFrame
中每个元素,并且仅在元素级操作失败时才应用于DataFrame
列的行为。要保留当前行为,请改用DataFrame.transform()
(GH 53325)废弃了将
DataFrame
传递给DataFrame.from_records()
,请改用DataFrame.set_index()
或DataFrame.drop()
(GH 51353)废弃了将字符串解析为日期时间时静默丢弃无法识别的时区 (GH 18702)
在
DataFrame.ewm()
、Series.ewm()
、DataFrame.rolling()
、Series.rolling()
、DataFrame.expanding()
、Series.expanding()
中废弃了axis
关键字 (GH 51778)在
DataFrame.resample()
、Series.resample()
中废弃了axis
关键字 (GH 51778)在
Series.interpolate()
、DataFrame.interpolate()
、Series.fillna()
、DataFrame.fillna()
、Series.ffill()
、DataFrame.ffill()
、Series.bfill()
、DataFrame.bfill()
中废弃了downcast
关键字 (GH 40988)废弃了
concat()
中len(keys) != len(objs)
时的行为,未来版本中这会引发错误而不是截断为两个序列中较短的一个 (GH 43485)废弃了
Series.argsort()
在存在 NA 值时的行为;未来版本中这些 NA 值将被排在末尾而不是返回 -1 (GH 54219)在
DataFrame.groupby()
和Series.groupby()
中废弃了observed=False
的默认值;未来版本中默认值将变为True
(GH 43999)在
SeriesGroupBy.aggregate()
聚合中废弃了将group.name
绑定到每个分组的行为;如果你的操作需要利用分组键,请改为迭代 groupby 对象 (GH 41090)在
DataFrameGroupBy.idxmax()
、DataFrameGroupBy.idxmin()
、DataFrameGroupBy.fillna()
、DataFrameGroupBy.take()
、DataFrameGroupBy.skew()
、DataFrameGroupBy.rank()
、DataFrameGroupBy.cumprod()
、DataFrameGroupBy.cumsum()
、DataFrameGroupBy.cummax()
、DataFrameGroupBy.cummin()
、DataFrameGroupBy.pct_change()
、DataFrameGroupBy.diff()
、DataFrameGroupBy.shift()
和DataFrameGroupBy.corrwith()
中废弃了axis
关键字;对于axis=1
的情况,请改为在底层DataFrame
上进行操作 (GH 50405, GH 51046)废弃了在使用
DataFrameGroupBy
且as_index=False
时,如果分组键不是 DataFrame 的列,则结果中不包含分组键的行为 (GH 49519)废弃了
is_categorical_dtype()
,请改用isinstance(obj.dtype, pd.CategoricalDtype)
(GH 52527)废弃了
is_datetime64tz_dtype()
,请改为检查isinstance(dtype, pd.DatetimeTZDtype)
(GH 52607)废弃了
is_int64_dtype()
,请改为检查dtype == np.dtype(np.int64)
(GH 52564)废弃了
is_interval_dtype()
,请改为检查isinstance(dtype, pd.IntervalDtype)
(GH 52607)废弃了
is_period_dtype()
,请改为检查isinstance(dtype, pd.PeriodDtype)
(GH 52642)废弃了
is_sparse()
,请改为检查isinstance(dtype, pd.SparseDtype)
(GH 52642)废弃了
Styler.applymap_index()
。请改用新的Styler.map_index()
方法 (GH 52708)废弃了
Styler.applymap()
。请改用新的Styler.map()
方法 (GH 52708)废弃了
DataFrame.applymap()
。请改用新的DataFrame.map()
方法 (GH 52353)废弃了
DataFrame.swapaxes()
和Series.swapaxes()
,请改用DataFrame.transpose()
或Series.transpose()
(GH 51946)在
PeriodArray
构造函数中废弃了freq
参数,请改为传递dtype
(GH 52462)废弃了
take()
中允许非标准输入,请改为传递numpy.ndarray
、ExtensionArray
、Index
或Series
(GH 52981)废弃了
isin()
、value_counts()
、unique()
、factorize()
允许非标准序列作为输入,请在调用前转换为numpy.ndarray
、Index
、ExtensionArray
或Series
中的一种 (GH 52986)废弃了
DataFrame
聚合函数sum
、prod
、std
、var
、sem
在axis=None
时的行为,未来版本中这将作用于两个轴并返回一个标量,而不是像axis=0
那样;注意这也会影响 numpy 函数,例如np.sum(df)
(GH 21597)废弃了
concat()
在DataFrame
包含全 NA 列时的行为,未来版本中在确定结果 dtype 时不会丢弃这些列 (GH 40893)废弃了
Series.dt.to_pydatetime()
的行为,未来版本中这将返回包含 Pythondatetime
对象的Series
,而不是包含日期时间的ndarray
;这与其他Series.dt
属性的行为一致 (GH 20306)废弃了 pandas 对象和无 dtype 序列(例如
list
、tuple
)之间的逻辑运算(|
、&
、^
),请改为在操作前将序列包装在Series
或 NumPy 数组中 (GH 51521)在
Series.apply()
中废弃了convert_type
参数 (GH 52140)废弃了将字典传递给
SeriesGroupBy.agg()
;请改为传递聚合列表 (GH 50684)在
Categorical
构造函数中废弃了fastpath
关键字,请改用Categorical.from_codes()
(GH 20110)废弃了
is_bool_dtype()
对 object-dtypeIndex
包含布尔对象时返回True
的行为 (GH 52680)废弃了方法
Series.bool()
和DataFrame.bool()
(GH 51749)在
DatetimeIndex
构造函数中废弃了未使用的closed
和normalize
关键字 (GH 52628)在
TimedeltaIndex
构造函数中废弃了未使用的closed
关键字 (GH 52628)废弃了两个索引不同且非布尔型的
Series
之间的逻辑运算总是将结果强制转换为 bool dtype 的行为。未来版本中,这将保持输入的返回类型 (GH 52500, GH 52538)废弃了具有
BDay
频率的Period
和PeriodDtype
,请改用具有BDay
频率的DatetimeIndex
(GH 53446)废弃了
value_counts()
,请改用pd.Series(obj).value_counts()
(GH 47862)废弃了
Series.first()
和DataFrame.first()
;请改为创建掩码并使用.loc
进行过滤 (GH 45908)废弃了对 object-dtype 使用
Series.interpolate()
和DataFrame.interpolate()
(GH 53631)废弃了
Series.last()
和DataFrame.last()
;请改为创建掩码并使用.loc
进行过滤 (GH 53692)废弃了在
SparseDtype
中允许任意fill_value
的行为,未来版本中fill_value
需要与dtype.subtype
兼容,即该子类型可以容纳的标量,或整数或布尔子类型的NaN
(GH 23124)在
DataFrameGroupBy.quantile()
和SeriesGroupBy.quantile()
中废弃了允许 bool dtype,与Series.quantile()
和DataFrame.quantile()
的行为一致 (GH 51424)废弃了
testing.assert_series_equal()
和testing.assert_frame_equal()
将类似 NA 的值(例如NaN
和None
)视为等效的行为 (GH 52081)已弃用向
read_excel()
提供字节输入。要读取文件路径,请使用字符串或路径类对象 (GH 53767)已弃用从标量数据构造
SparseArray
,请改为传递一个序列 (GH 53039)已弃用在
DataFrame.replace()
和Series.replace()
中,当value
未指定且to_replace
非字典类型时回退到填充行为 (GH 33302)已弃用向
read_json()
提供直接的 JSON 输入。请改为将直接的 JSON 字符串输入包装在io.StringIO
中 (GH 53409)已弃用向
read_xml()
提供直接的字符串输入。请改为将直接的字符串/字节输入包装在io.StringIO
/io.BytesIO
中 (GH 53767)已弃用向
read_html()
提供直接的字符串/字节输入。请改为将直接的字符串/字节输入包装在io.StringIO
/io.BytesIO
中 (GH 53767)已弃用选项
mode.use_inf_as_na
,请改为预先将 inf 条目转换为NaN
(GH 51684)已弃用
DataFrameGroupBy.get_group()
中的参数obj
(GH 53545)已弃用使用
Series.__getitem__()
和Series.__setitem__()
在Series
上进行位置索引,在未来版本中,ser[item]
将始终把item
解释为标签,而非位置 (GH 50617)已弃用在
.agg
,.apply
和.transform
中替换内置函数和 NumPy 函数;请改为使用对应的字符串别名(例如,"sum"
代替sum
或np.sum
) (GH 53425)已弃用在
to_timedelta()
中表示单位的字符串T
,t
,L
和l
(GH 52536)已弃用
.ExtensionArray.fillna
中的“method”和“limit”关键字,请改为实现_pad_or_backfill
(GH 53621)已弃用
DataFrame.replace()
和Series.replace()
中的method
和limit
关键字 (GH 33302)已弃用
Series.fillna()
,DataFrame.fillna()
,SeriesGroupBy.fillna()
,DataFrameGroupBy.fillna()
和Resampler.fillna()
上的method
和limit
关键字,请改为使用obj.bfill()
或obj.ffill()
(GH 53394)已弃用在具有浮点型索引的对象上使用整数切片时的
Series.__getitem__()
,Series.__setitem__()
,DataFrame.__getitem__()
,DataFrame.__setitem__()
行为,在未来版本中,这将视为位置索引 (GH 49612)已弃用与
pandas.array()
一起使用不支持的 datetime64 和 timedelta64 分辨率。支持的分辨率包括:“s”、“ms”、“us”、“ns” 分辨率 (GH 53058)已弃用用于
Series.interpolate()
和DataFrame.interpolate()
的值"pad"
,"ffill"
,"bfill",
"backfill"
,请改为使用obj.ffill()
或obj.bfill()
(GH 53581)已弃用
Index.argmax()
,Index.argmin()
,Series.argmax()
,Series.argmin()
在全部为 NA 且skipna=True
时,或存在 NA 且skipna=False
时返回 -1 的行为;在未来版本中,这将引发ValueError
(GH 33941, GH 33942)已弃用在
DataFrame.to_sql()
中允许非关键字参数,除了name
和con
(GH 54229)已弃用在同时向
DataFrame.shift()
,Series.shift()
和DataFrameGroupBy.shift()
传递freq
和fill_value
时静默忽略fill_value
的行为;在未来版本中,这将引发ValueError
(GH 53832)
性能改进#
concat()
在使用同质的np.float64
或np.float32
dtypes 时的性能改进 (GH 52685)factorize()
适用于不包含字符串的对象列的性能改进 (GH 51921)read_orc()
在读取远程 URI 文件路径时的性能改进 (GH 51609)read_parquet()
和DataFrame.to_parquet()
在使用engine="pyarrow"
读取远程文件时的性能改进 (GH 51609)read_parquet()
在字符串列上使用use_nullable_dtypes=True
时的性能改进 (GH 47345)DataFrame.clip()
和Series.clip()
中的性能改进 (GH 51472)DataFrame.filter()
在给定items
时的性能改进 (GH 52941)DataFrame.first_valid_index()
和DataFrame.last_valid_index()
适用于扩展数组 dtypes 的性能改进 (GH 51549)DataFrame.where()
在cond
由扩展 dtype 支持时的性能改进 (GH 51574)MultiIndex.set_levels()
和MultiIndex.set_codes()
在verify_integrity=True
时的性能改进 (GH 51873)MultiIndex.sortlevel()
在ascending
是列表时的性能改进 (GH 51612)Series.combine_first()
中的性能改进 (GH 51777)fillna()
在数组不包含 null 值时的性能改进 (GH 51635)isna()
在数组没有 null 值或全部是 null 值时的性能改进 (GH 51630)将字符串解析为
boolean[pyarrow]
dtype 时的性能改进 (GH 51730)Period
的默认格式化器(period_format
)现在显着提速(约两倍)。这改进了str(Period)
,repr(Period)
和Period.strftime(fmt=None)()
的性能,以及.PeriodArray.strftime(fmt=None)
,.PeriodIndex.strftime(fmt=None)
和.PeriodIndex.format(fmt=None)
的性能。涉及PeriodArray
或PeriodIndex
且使用默认date_format
的to_csv
操作也显着加速 (GH 51459)访问
arrays.IntegerArrays.dtype
和arrays.FloatingArray.dtype
时的性能改进 (GH 52998)DataFrameGroupBy
/SeriesGroupBy
聚合操作(例如DataFrameGroupBy.sum()
)在使用engine="numba"
时的性能改进 (GH 53731)MultiIndex
和多列操作(例如DataFrame.sort_values()
,DataFrame.groupby()
,Series.unstack()
)在索引/列值已排序时的性能改进 (GH 53806)concat()
在拼接轴是MultiIndex
时的性能改进 (GH 53574)read_csv()
在使用engine="c"
时的性能改进 (GH 52632)ArrowExtensionArray.to_numpy()
中的性能改进 (GH 52525)DataFrameGroupBy.groups()
中的性能改进 (GH 53088)DataFrame.astype()
在dtype
是扩展 dtype 时的性能改进 (GH 54299)DataFrame.iloc()
在输入是单个整数且 DataFrame 由扩展 dtypes 支持时的性能改进 (GH 54508)DataFrame.isin()
适用于扩展 dtypes 的性能改进 (GH 53514)DataFrame.loc()
在选择行和列时的性能改进 (GH 53014)DataFrame.transpose()
在转置具有单个 PyArrow dtype 的 DataFrame 时的性能改进 (GH 54224)DataFrame.transpose()
在转置具有单个掩码 dtype 的 DataFrame 时的性能改进,例如Int64
(GH 52836)Series.add()
适用于 PyArrow 字符串和二进制 dtypes 的性能改进 (GH 53150)Series.corr()
和Series.cov()
适用于扩展 dtypes 的性能改进 (GH 52502)Series.drop_duplicates()
适用于ArrowDtype
的性能改进 (GH 54667)。Series.ffill()
,Series.bfill()
,DataFrame.ffill()
,DataFrame.bfill()
在使用 PyArrow dtypes 时的性能改进 (GH 53950)Series.str.get_dummies()
适用于由 PyArrow 支持的字符串的性能改进 (GH 53655)Series.str.get()
适用于由 PyArrow 支持的字符串的性能改进 (GH 53152)Series.str.split()
在使用expand=True
且适用于由 PyArrow 支持的字符串时的性能改进 (GH 53585)Series.to_numpy()
在 dtype 是 NumPy 浮点 dtype 且na_value
是np.nan
时的性能改进 (GH 52430)astype()
在从 PyArrow 时间戳或时长 dtype 转换为 NumPy 时的性能改进 (GH 53326)各种
MultiIndex
集合和索引操作中的性能改进 (GH 53955)在对
arrays.IntegerArray
和arrays.FloatingArray
执行各种重塑操作时的性能改进,通过避免不必要的验证 (GH 53013)使用 PyArrow 时间戳和时长 dtypes 进行索引时的性能改进 (GH 53368)
将数组传递给
RangeIndex.take()
,DataFrame.loc()
, 或DataFrame.iloc()
且 DataFrame 使用 RangeIndex 时的性能改进 (GH 53387)
Bug 修复#
分类#
CategoricalIndex.remove_categories()
中的错误,其中有序类别未被维护 (GH 53935)。Series.astype()
中的错误,当使用dtype="category"
且针对具有只读 null 值掩码的可为空的数组时 (GH 53658)Series.map()
中的错误,其中如果 Series 持有Categorical
,则na_action
参数的值未被使用 (GH 22527)。
日期时间类#
DatetimeIndex.map()
在使用na_action="ignore"
时现在按预期工作 (GH 51644)DatetimeIndex.slice_indexer()
现在对非单调索引在切片边界不在索引中时引发KeyError
;此行为先前已弃用,但处理不一致 (GH 53983)修复了
DateOffset
中的错误,该错误在将DateOffset
对象乘以常量时行为不一致 (GH 47953)修复了
date_range()
中的错误,该错误在freq
为带有nanoseconds
的DateOffset
时发生 (GH 46877)修复了
to_datetime()
中的错误,该错误在将包含 PyArrow 时间戳的arrays.ArrowExtensionArray
的Series
或DataFrame
转换为 numpy datetime 时发生 (GH 52545)修复了
DatetimeArray.map()
和DatetimeIndex.map()
中的错误,其中提供的可调用对象是以数组为单位操作,而不是以元素为单位操作 (GH 51977)修复了
DataFrame.to_sql()
中的错误,该错误在处理 PyArrow 支持的日期类型 dtype 时引发ValueError
(GH 53854)修复了
Timestamp.date()
,Timestamp.isocalendar()
,Timestamp.timetuple()
和Timestamp.toordinal()
中的错误,对于超出 Python 标准库 datetime 模块支持范围的输入,它们返回不正确的结果 (GH 53668)修复了
Timestamp.round()
中的错误,当值接近实现边界时,它返回不正确的结果,而不是引发OutOfBoundsDatetime
(GH 51494)修复了从 datetime 或 timedelta 标量构造
Series
或DataFrame
时总是推断纳秒分辨率而不是根据输入推断的错误 (GH 52212)修复了使用
ts_input=pd.NA
构造Timestamp
时引发TypeError
的错误 (GH 45481)修复了解析带有星期几但没有日的 datetime 字符串(例如“2023 Sept Thu”)时错误地引发
AttributeError
而不是ValueError
的错误 (GH 52659)修复了当
Series
的 dtype 是非纳秒分辨率的时区感知 datetime 时,其 repr 引发OutOfBoundsDatetime
的错误 (GH 54623)
时间差#
修复了
TimedeltaIndex
除法或乘法导致.freq
为“0 Days”而不是None
的错误 (GH 51575)修复了
Timedelta
处理 NumPytimedelta64
对象时未正确引发ValueError
的错误 (GH 52806)修复了
to_timedelta()
中的错误,该错误在将包含pyarrow.duration
的ArrowDtype
的Series
或DataFrame
转换为 NumPytimedelta64
时发生 (GH 54298)修复了
Timedelta.__hash__()
中的错误,该错误在某些大秒分辨率值上引发OutOfBoundsTimedelta
(GH 54037)修复了
Timedelta.round()
中的错误,当值接近实现边界时,它返回不正确的结果,而不是引发OutOfBoundsTimedelta
(GH 51494)修复了
TimedeltaIndex.map()
中使用na_action="ignore"
时的错误 (GH 51644)修复了
arrays.TimedeltaArray.map()
和TimedeltaIndex.map()
中的错误,其中提供的可调用对象是以数组为单位操作,而不是以元素为单位操作 (GH 51977)
时区#
修复了
infer_freq()
中的错误,该错误对时区感知时间戳的Series
引发TypeError
(GH 52456)修复了
DatetimeTZDtype.base()
中的错误,它总是返回一个纳秒分辨率的 NumPy dtype (GH 52705)
数值#
修复了
RangeIndex
在作为被减数,减数为数值时错误地设置step
的错误 (GH 53255)修复了
Series.corr()
和Series.cov()
对 masked dtypes 引发AttributeError
的错误 (GH 51422)修复了在对全零 NumPy 数据调用
Series.kurt()
和Series.skew()
时返回 Python 类型而不是 NumPy 类型的错误 (GH 53482)修复了
Series.mean()
,DataFrame.mean()
在处理包含可转换为数字的字符串(例如“2”)的 object-dtype 值时返回不正确数值结果的错误;现在它们会引发TypeError
(GH 36703, GH 44008)修复了
DataFrame.corrwith()
对 PyArrow 支持的 dtypes 引发NotImplementedError
的错误 (GH 52314)修复了
DataFrame.size()
和Series.size()
返回 64 位整数而不是 Python int 的错误 (GH 52897)修复了
DateFrame.dot()
对ArrowDtype
数据返回object
dtype 的错误 (GH 53979)修复了
Series.any()
,Series.all()
,DataFrame.any()
和DataFrame.all()
中bool_only
的默认值被设置为None
而不是False
的错误;此更改不会影响用户 (GH 53258)修复了
Series.corr()
和Series.cov()
对 masked dtypes 引发AttributeError
的错误 (GH 51422)修复了
Series.median()
和DataFrame.median()
在处理包含可转换为数字的字符串(例如“2”)的 object-dtype 值时返回不正确数值结果的错误;现在它们会引发TypeError
(GH 34671)修复了
Series.sum()
将 dtypeuint64
转换为int64
的错误 (GH 53401)
转换#
修复了
DataFrame.style.to_latex()
和DataFrame.style.to_html()
中的错误,该错误在 DataFrame 包含位数多于双精度浮点数可表示范围的整数时发生 (GH 52272)修复了
array()
中的错误,当给定单位为“s”、“us”或“ms”的datetime64
或timedelta64
dtype 时,它返回NumpyExtensionArray
而不是DatetimeArray
或TimedeltaArray
(GH 52859)修复了
array()
中的错误,当给定空列表且无 dtype 时,它返回NumpyExtensionArray
而不是FloatingArray
(GH 54371)修复了
ArrowDtype.numpy_dtype()
中的错误,对于非纳秒的pyarrow.timestamp
和pyarrow.duration
类型,它返回纳秒单位 (GH 51800)修复了
DataFrame.__repr__()
在列的 dtype 为np.record
时错误地引发TypeError
的错误 (GH 48526)修复了
DataFrame.info()
在设置use_numba
时引发ValueError
的错误 (GH 51922)修复了
DataFrame.insert()
在loc
为np.int64
时引发TypeError
的错误 (GH 53193)修复了
HDFStore.select()
在存储和检索大整数时丢失精度的错误 (GH 54186)修复了
Series.astype()
不支持object_
的错误 (GH 54251)
字符串#
修复了
Series.str()
在迭代时未引发TypeError
的错误 (GH 54173)修复了
DataFrame`
的repr
在处理 string-dtype 列时发生的错误 (GH 54797)
区间#
IntervalIndex.get_indexer()
和IntervalIndex.get_indexer_nonunique()
在target
是只读数组时引发错误 (GH 53703)修复了
IntervalDtype
中的错误,其中对象在删除后仍可能保持活动状态 (GH 54184)修复了
interval_range()
中的错误,其中浮点step
会因浮点数误差导致产生不正确的区间 (GH 54477)
索引#
修复了
DataFrame.__setitem__()
在将DataFrame
设置到重复列时丢失 dtype 的错误 (GH 53143)修复了
DataFrame.__setitem__()
使用布尔掩码和DataFrame.putmask()
处理混合非数值 dtypes 和非NaN
值时错误地引发TypeError
的错误 (GH 53291)修复了
DataFrame.iloc()
在仅使用nan
作为元素时发生的错误 (GH 52234)修复了
Series.loc()
在将Series
分配给 object dtypeSeries
的预定义索引时将Series
强制转换为np.dnarray
的错误 (GH 48933)
缺失值#
修复了
DataFrame.interpolate()
在method
为 “pad”, “ffill”, “bfill” 或 “backfill” 时未能填充跨数据区域的错误 (GH 53898)修复了
DataFrame.interpolate()
在DataFrame
为空时忽略inplace
参数的错误 (GH 53199)修复了
Series.idxmin()
,Series.idxmax()
,DataFrame.idxmin()
,DataFrame.idxmax()
在DatetimeIndex
索引包含NaT
时错误地返回NaN
而不是NaT
的错误 (GH 43587)修复了
Series.interpolate()
和DataFrame.interpolate()
在downcast
关键字无效时未能引发错误,该关键字只能是None
或"infer"
的错误 (GH 53103)修复了
Series.interpolate()
和DataFrame.interpolate()
在处理复杂 dtype 时未能正确填充NaN
条目的错误 (GH 53635)
多级索引#
修复了
MultiIndex.set_levels()
未保留Categorical
的 dtypes 的错误 (GH 52125)修复了显示带有长元素的
MultiIndex
时发生的错误 (GH 52960)
输入/输出#
DataFrame.to_orc()
现在在给定非默认Index
时会引发ValueError
(GH 51828)DataFrame.to_sql()
现在在使用 SQLAlchemy 连接时,如果 name 参数留空会引发ValueError
(GH 52675)修复了
json_normalize()
无法解析元数据字段列表类型的错误 (GH 37782)修复了
read_csv()
中的错误,在使用engine="pyarrow"
且parse_dates
设置为列表或字典时会出错 (GH 47961)修复了
read_csv()
在使用engine="pyarrow"
并同时指定带有index_col
的dtype
时引发错误的错误 (GH 53229)修复了
read_hdf()
在引发IndexError
后未正确关闭存储的错误 (GH 52781)修复了
read_html()
中样式元素被读取到 DataFrame 中的错误 (GH 52197)修复了
read_html()
中尾部文本与包含display:none
样式的元素一起被移除的错误 (GH 51629)在
read_sql_table()
读取视图时引发异常的错误 (GH 52969)在
read_sql()
读取多个具有相同列名的时区感知列时发生的错误 (GH 44421)在
read_xml()
中去除字符串数据空白字符的错误 (GH 53811)在
DataFrame.to_html()
中,当列为多级索引时,colspace
参数应用不正确的错误 (GH 53885)在
DataFrame.to_html()
中,针对具有复杂 dtype 的空DataFrame
进行转换时引发ValueError
的错误 (GH 54167)在
DataFrame.to_json()
中,非纳秒精度的DateTimeArray
/DateTimeIndex
无法正确序列化的错误 (GH 53686)读写空的 Stata dta 文件时丢失 dtype 信息的错误 (GH 46240)
将
bz2
视为硬性要求的错误 (GH 53857)
Period#
在
PeriodDtype
构造函数中,未传递参数或传递None
时未能引发TypeError
的错误 (GH 27388)在
PeriodDtype
构造函数中,对于不同的DateOffset
freq
输入,错误返回相同的normalize
的错误 (GH 24121)在
PeriodDtype
构造函数中,传递无效类型时引发ValueError
而非TypeError
的错误 (GH 51790)在
PeriodDtype
中,对象在删除时可能仍保持存活的错误 (GH 54184)在
read_csv()
中,当使用engine="pyarrow"
时,未将空字符串处理为 null 值的错误 (GH 52087)在
read_csv()
中,当使用engine="pyarrow"
时,对于全是 null 的列,返回object
dtype 列而不是float64
dtype 列的错误 (GH 52087)在
Period.now()
中,不接受freq
参数作为关键字参数的错误 (GH 53369)在
PeriodIndex.map()
中,当使用na_action="ignore"
时发生的错误 (GH 51644)在
arrays.PeriodArray.map()
和PeriodIndex.map()
中,提供的可调用对象按数组而不是按元素操作的错误 (GH 51977)错误地允许使用
CustomBusinessDay
freq 构建Period
或PeriodDtype
的错误;请改用BusinessDay
(GH 52534)
绘图#
在
Series.plot()
中,当使用color=None
调用时发生的错误 (GH 51953)修复了在
DataFrame.plot.scatter()
中使用c="b"
调用时出现的 UserWarning (GH 53908)
分组/重采样/滚动#
在
DataFrameGroupBy.idxmin()
,SeriesGroupBy.idxmin()
,DataFrameGroupBy.idxmax()
,SeriesGroupBy.idxmax()
中,当用于空的 DataFrameGroupBy 或 SeriesGroupBy 时返回错误的 dtype 的错误 (GH 51423)在
DataFrame.groupby.rank()
中,对可空数据类型使用na_option="bottom"
或na_option="top"
时发生的错误 (GH 54206)在
DataFrame.resample()
和Series.resample()
中,当对TimedeltaIndex
进行重采样时错误地允许使用非固定freq
的错误 (GH 51896)在
DataFrame.resample()
和Series.resample()
中,对空数据进行重采样时丢失时区的错误 (GH 53664)在
DataFrame.resample()
和Series.resample()
中,当值超出轴范围时,origin
参数在重采样中无效的错误 (GH 53662)加权滚动聚合在指定
min_periods=0
时发生的错误 (GH 51449)在
DataFrame.groupby()
和Series.groupby()
中,当被分组的Series
或DataFrame
的索引是DatetimeIndex
,TimedeltaIndex
或PeriodIndex
,并且groupby
方法的第一个参数是一个函数时,该函数作用于整个索引而不是索引的每个元素的错误 (GH 51979)在
DataFrameGroupBy.agg()
中,使用列表进行聚合时未遵守as_index=False
的错误 (GH 52849)在
DataFrameGroupBy.apply()
中,当分组后的输入DataFrame
被子集化为一个DataFrame
(例如[['a']]
而非['a']
) 且提供的可调用对象返回的Series
索引不完全相同时引发错误的错误 (GH 52444)在
DataFrameGroupBy.apply()
中,当选择多列并提供返回np.ndarray
结果的函数时引发TypeError
的错误 (GH 18930)在
DataFrameGroupBy.groups()
和SeriesGroupBy.groups()
中,当日期时间键与其他键结合使用时产生错误的组键数量的错误 (GH 51158)在
DataFrameGroupBy.quantile()
和SeriesGroupBy.quantile()
中,当使用sort=False
时可能隐式地对结果索引进行排序的错误 (GH 53009)在
SeriesGroupBy.size()
中,对于ArrowDtype
或掩码 dtype (例如Int64
) 的数据,其 dtype 为np.int64
的错误 (GH 53831)在
DataFrame.groupby()
中,当对结果 groupby 对象进行列选择时,当按仅包含一个元素的列表进行分组时,未将名称作为元组返回的错误 (GH 53500)在
DataFrameGroupBy.var()
和SeriesGroupBy.var()
中,当使用 datetime64, timedelta64 或PeriodDtype
值调用时未能引发TypeError
的错误 (GH 52128, GH 53045)在
DataFrameGroupBy.resample()
中,当使用kind="period"
时引发AttributeError
的错误 (GH 24103)在
Resampler.ohlc()
中,当处理空对象时返回Series
而非空DataFrame
的错误 (GH 42902)在
SeriesGroupBy.count()
和DataFrameGroupBy.count()
中,对于ArrowDtype
或掩码 dtype (例如Int64
) 的数据,其 dtype 为np.int64
的错误 (GH 53831)在
SeriesGroupBy.nth()
和DataFrameGroupBy.nth()
中,在进行列选择后,使用dropna="any"
或dropna="all"
时未对列进行子集化的错误 (GH 53518)在
SeriesGroupBy.nth()
和DataFrameGroupBy.nth()
中,在进行列选择后,使用dropna="any"
或dropna="all"
导致行被丢弃的错误 (GH 53518)在
SeriesGroupBy.sum()
和DataFrameGroupBy.sum()
中,将np.inf + np.inf
和(-np.inf) + (-np.inf)
求和为np.nan
而非np.inf
和-np.inf
的错误 (GH 53606)在
Series.groupby()
中,当分组的Series
具有DatetimeIndex
索引,并且by
参数给定一个名称为月份的Series
时引发错误的错误 (GH 48509)
重塑#
在
concat()
中,当某一列具有pa.null()
dtype 时强制转换为object
dtype 的错误 (GH 53702)在
crosstab()
中,当使用dropna=False
时未在结果中保留np.nan
的错误 (GH 10772)在
merge_asof()
中,处理扩展 dtype 时引发KeyError
的错误 (GH 52904)在
merge_asof()
中,对由只读 ndarray 支持的数据引发ValueError
的错误 (GH 53513)在
merge_asof()
中,当使用left_index=True
或right_index=True
且索引 dtype 不匹配时,在某些情况下给出错误结果而非引发MergeError
的错误 (GH 53870)在
merge()
中,当对整数ExtensionDtype
和浮点 NumPy dtype 进行合并时引发TypeError
的错误 (GH 46178)在
DataFrame.agg()
和Series.agg()
中,当在非唯一列上应用且传入 dist-like 参数时返回错误类型的错误 (GH 51099)在
DataFrame.combine_first()
中,当other
为空时忽略 other 的列的错误 (GH 53792)在
DataFrame.idxmin()
和DataFrame.idxmax()
中,空 DataFrame 丢失轴 dtype 的错误 (GH 53265)在
DataFrame.merge()
中,当具有单层MultiIndex
时合并不正确的错误 (GH 52331)在
DataFrame.stack()
中,当列是MultiIndex
且 DataFrame 包含混合 dtype 时丢失扩展 dtype 的错误 (GH 45740)错误:
DataFrame.stack()
按字典顺序对列进行排序时出现错误 (GH 53786)错误:
DataFrame.transpose()
推断对象列的 dtype 时出现错误 (GH 51546)错误:
Series.combine_first()
将int64
dtype 转换为float64
并在处理非常大的整数时丢失精度 (GH 51764)错误:连接空的
DataFrame
对象时,连接后的索引是RangeIndex
而不是连接后的索引类型 (GH 52777)
稀疏#
错误:
SparseDtype
构造函数在为其子类型(必须是 NumPy dtype)提供不兼容的dtype
时未能引发TypeError
(GH 53160)错误:
arrays.SparseArray.map()
允许将填充值包含在稀疏值中 (GH 52095)
扩展数组#
错误:
ArrowStringArray
构造函数在处理字符串的字典类型时引发ValueError
(GH 54074)错误:
DataFrame
构造函数在字典中给定带有扩展 dtype 的Series
时未进行复制 (GH 53744)错误:
ArrowExtensionArray
将 pandas 非纳秒级时间对象从非零值转换为零值 (GH 53171)错误:
Series.quantile()
处理 PyArrow 时间类型时引发ArrowInvalid
(GH 52678)错误:
Series.rank()
对于Float64
dtype 的小值返回错误的顺序 (GH 52471)错误:
Series.unique()
处理带有NA
值的布尔ArrowDtype
时出现错误 (GH 54667)错误:
__iter__()
和__getitem__()
对于非纳秒级 dtype 返回 python datetime 和 timedelta 对象 (GH 53326)错误:
factorize()
对于具有多个块的pyarrow.dictionary
类型pyarrow.chunked_array
返回不正确的唯一值 (GH 54844)错误:将
ExtensionArray
子类传递给dtype
关键字时出现错误。现在将引发UserWarning
,建议传递实例代替 (GH 31356, GH 54592)错误:当列具有带有
pyarrow.ExtensionDtype
的ArrowDtype
时,DataFrame
的 repr 不起作用 (GH 54063)错误:掩码 ExtensionDtype(例如
Float64Dtype
,BooleanDtype
)的__from_arrow__
方法不接受pyarrow.null()
类型的 PyArrow 数组 (GH 52223)
样式器#
元数据#
修复了
DataFrame.max()
,DataFrame.min()
,DataFrame.prod()
,DataFrame.mean()
,Series.mode()
,DataFrame.median()
,DataFrame.sem()
,DataFrame.skew()
,DataFrame.kurt()
中的元数据传播问题 (GH 28283)修复了
DataFrame.squeeze()
和DataFrame.describe()
中的元数据传播问题 (GH 28283)修复了
DataFrame.std()
中的元数据传播问题 (GH 28283)
其他#
错误:
FloatingArray.__contains__
处理NaN
项时,当存在NaN
值时错误地返回False
(GH 52840)错误:
DataFrame
和Series
在处理包含NaN
值的复杂 dtype 数据时引发异常 (GH 53627)错误:
DatetimeIndex
中,当索引带时间但时间为午夜且频率不是基于天时,repr
未打印时间 (GH 53470)错误:
testing.assert_frame_equal()
和testing.assert_series_equal()
现在对两个不相等的集合引发断言错误 (GH 51727)错误:
testing.assert_frame_equal()
即使被要求不检查索引类型,也检查 category dtype (GH 52126)错误:
api.interchange.from_dataframe()
未遵循allow_copy
参数 (GH 54322)错误:
api.interchange.from_dataframe()
在与包含 null 值的非 pandas 时区感知数据进行交换时引发异常 (GH 54287)错误:
api.interchange.from_dataframe()
转换空 DataFrame 对象时出现错误 (GH 53155)错误:
from_dummies()
中,生成的Index
与原始Index
不匹配 (GH 54300)错误:
from_dummies()
中,生成的数据总是object
dtype 而不是列的 dtype (GH 54300)错误:
DataFrameGroupBy.first()
,DataFrameGroupBy.last()
,SeriesGroupBy.first()
, 和SeriesGroupBy.last()
中,空组返回np.nan
而不是相应的ExtensionArray
NA 值 (GH 39098)错误:
DataFrame.pivot_table()
将整数的均值转换回整数时出现错误 (GH 16676)错误:
DataFrame.reindex()
使用应与ExtensionDtype
一起推断的fill_value
时,错误地推断为object
dtype (GH 52586)错误:
DataFrame.shift()
对具有单个ExtensionDtype
列的DataFrame
使用axis=1
时给出不正确的结果 (GH 53832)错误:
Index.sort_values()
在传递key
时出现错误 (GH 52764)错误:
Series.align()
,DataFrame.align()
,Series.reindex()
,DataFrame.reindex()
,Series.interpolate()
,DataFrame.interpolate()
在使用method="asfreq"
时未能正确引发异常 (GH 53620)错误:
Series.argsort()
在传递无效axis
时未能引发异常 (GH 54257)错误:
Series.map()
对空 series 提供可调用对象时,返回的 series 是object
dtype。现在保留原始 dtype (GH 52384)错误:
Series.memory_usage()
使用deep=True
时,对于对象 Series 抛出错误,且返回值不正确,因为它未考虑 GC 修正 (GH 51858)错误:
period_range()
在未将freq
作为参数传递时的默认行为不正确 (GH 53687)修复了
pandas._libs.json
的__name__
属性不正确的问题 (GH 52898)
贡献者#
共有 266 位贡献者为本次发布提交了补丁。名字旁带有“+”的人是首次贡献补丁。
AG +
Aarni Koskela
Adrian D’Alessandro +
Adrien RUAULT +
Ahmad +
Aidos Kanapyanov +
Alex Malins
Alexander Seiler +
Ali Asgar +
Allison Kwan
Amanda Bizzinotto +
Andres Algaba +
Angela Seo +
Anirudh Hegde +
Antony Evmorfopoulos +
An Anushka Bishnoi
ArnaudChanoine +
Artem Vorobyev +
Arya Sarkar +
Ashwin Srinath
Austin Au-Yeung +
Austin Burnett +
Bear +
Ben Mangold +
Bernardo Gameiro +
Boyd Kane +
Brayan Alexander Muñoz B +
Brock
Chetan0402 +
Chris Carini
ChristofKaufmann
Clark-W +
Conrad Mcgee Stocks
Corrie Bartelheimer +
Coulton Theuer +
D067751 +
Daniel Isaac
Daniele Nicolodi +
David Samuel +
David Seifert +
Dea Leon +
Dea María Léon
Deepyaman Datta
Denis Sapozhnikov +
Dharani Akurathi +
DimiGrammatikakis +
Dirk Ulbricht +
Dmitry Shemetov +
Dominik Berger
Efkan S. Goktepe +
Ege Özgüroğlu
Eli Schwartz
Erdi +
Fabrizio Primerano +
Facundo Batista +
Fangchen Li
Felipe Maion +
Francis +
Future Programmer +
Gabriel Kabbe +
Gaétan Ramet +
Gianluca Ficarelli
Godwill Agbehonou +
Guillaume Lemaitre
Guo Ci
Gustavo Vargas +
Hamidreza Sanaee +
HappyHorse +
Harald Husum +
Hugo van Kemenade
Ido Ronen +
Irv Lustig
JHM Darbyshire
JHM Darbyshire (iMac)
JJ +
Jarrod Millman
Jay +
Jeff Reback
Jessica Greene +
Jiawei Zhang +
Jinli Xiao +
Joanna Ge +
Jona Sassenhagen +
Jonas Haag
Joris Van den Bossche
Joshua Shew +
Julian Badillo
Julian Ortiz +
Julien Palard +
Justin Tyson +
Justus Magin
Kabiir Krishna +
Kang Su Min
Ketu Patel +
Kevin +
Kevin Anderson
Kevin Jan Anker
Kevin Klein +
Kevin Sheppard
Kostya Farber
LM +
Lars Lien Ankile +
Lawrence Mitchell
Liwei Cai +
Loic Diridollou
Luciana Solorzano +
Luke Manley
Lumberbot (aka Jack)
Marat Kopytjuk +
Marc Garcia
Marco Edward Gorelli
MarcoGorelli
Maria Telenczuk +
MarvinGravert +
Mateusz Sokół +
Matt Richards
Matthew Barber +
Matthew Roeschke
Matus Valo +
Mia Reimer +
Michael Terry +
Michael Tiemann +
Milad Maani Jou +
Miles Cranmer +
MirijaH +
Miyuu +
Natalia Mokeeva
Nathan Goldbaum +
Nicklaus Roach +
Nicolas Camenisch +
Nikolay Boev +
Nirav
Nishu Choudhary
Noa Tamir
Noy Hanan +
Numan +
Numan Ijaz +
Omar Elbaz +
Pandas Development Team
Parfait Gasana
Parthi
Patrick Hoefler
Patrick Schleiter +
Pawel Kranzberg +
Philip
Philip Meier +
Pranav Saibhushan Ravuri
PrathumP +
Rahul Siloniya +
Rajasvi Vinayak +
Rajat Subhra Mukherjee +
Ralf Gommers
RaphSku
Rebecca Chen +
Renato Cotrim Maciel +
Reza (Milad) Maanijou +
Richard Shadrach
Rithik Reddy +
Robert Luce +
Ronalido +
Rylie Wei +
SOUMYADIP MAL +
Sanjith Chockan +
Sayed Qaiser Ali +
Scott Harp +
Se +
Shashwat Agrawal
Simar Bassi +
Simon Brugman +
Simon Hawkins
Simon Høxbro Hansen
Snorf Yang +
Sortofamudkip +
Stefan Krawczyk
Stefanie Molin
Stefanie Senger
Stelios Petrakis +
Stijn Van Hoey
Sven
Sylvain MARIE
Sylvain Marié
Terji Petersen
Thierry Moisan
Thomas
Thomas A Caswell
Thomas Grainger
Thomas Li
Thomas Vranken +
Tianye Song +
Tim Hoffmann
Tim Loderhose +
Tim Swast
Timon Jurschitsch +
Tolker-KU +
Tomas Pavlik +
Toroi +
Torsten Wörtwein
Travis Gibbs +
Umberto Fasci +
Valerii +
VanMyHu +
Victor Momodu +
Vijay Vaidyanathan +
VomV +
William Andrea
William Ayd
Wolf Behrenhoff +
Xiao Yuan
Yao Xiao
Yasin Tatar
Yaxin Li +
Yi Wei +
Yulia +
Yusharth Singh +
Zach Breger +
Zhengbo Wang
abokey1 +
ahmad2901 +
assafam +
auderson
august-tengland +
bunardsheng +
cmmck +
cnguyen-03 +
coco +
dependabot[bot]
giplessis +
github-actions[bot]
gmaiwald +
gmollard +
jbrockmendel
kathleenhang
kevx82 +
lia2710 +
liang3zy22 +
ltartaro +
lusolorz +
m-ganko +
mKlepsch +
mattkeanny +
mrastgoo +
nabdoni +
omar-elbaz +
paulreece +
penelopeysm +
potap75 +
pre-commit-ci[bot] +
raanasn +
raj-thapa +
ramvikrams +
rebecca-palmer
reddyrg1 +
rmhowe425 +
segatrade +
shteken +
sweisss +
taytzehao
tntmatthews +
tpaxman +
tzehaoo +
v-mcoutinho +
wcgonzal +
yonashub
yusharth +
Ádám Lippai
Štěpán Műller +