2.1.0 (2023年8月30日) 中的新功能#
这是 pandas 2.1.0 中的变更。有关 发布说明 的完整更新日志,包括其他 pandas 版本,请参阅。
增强功能#
PyArrow 将成为 pandas 3.0 的必需依赖项#
PyArrow 将成为 pandas 3.0 及更高版本的必需依赖项。此决定基于 PDEP 10。
这将带来更多对 pandas 用户非常有益的改变,包括但不限于
默认将字符串推断为 PyArrow 支持的字符串,从而显著减少内存占用并大幅提升性能。
默认使用 PyArrow 推断更复杂的数据类型,例如
Decimal、lists、bytes、structured data等等。与其他依赖 Apache Arrow 的库更好地互操作。
我们正在此处收集关于此决定的反馈。
默认避免对字符串使用 NumPy object 数据类型#
以前,所有字符串默认存储在具有 NumPy object 数据类型的列中。此版本引入了一个选项 future.infer_string,可以将所有字符串推断为具有数据类型 "string[pyarrow_numpy]" 的 PyArrow 支持的字符串。这是一种新的字符串数据类型实现,它在比较操作中遵循 NumPy 语义,并将 np.nan 作为缺失值指示符。设置此选项还将把数据类型 "string" 推断为具有存储设置为 "pyarrow_numpy" 的 StringDtype,同时忽略选项 mode.string_storage 后面的值。
此选项仅在安装了 PyArrow 时有效。PyArrow 支持的字符串与 NumPy object 相比,内存占用显著减少,并提供巨大的性能提升 (GH 54430)。
此选项可以通过以下方式启用:
pd.options.future.infer_string = True
此行为将在 pandas 3.0 中成为默认设置。
DataFrame 聚合操作保留扩展数据类型#
在 pandas 的早期版本中,DataFrame 聚合操作(DataFrame.sum() DataFrame.mean() 等)的结果是 NumPy 数据类型,即使 DataFrame 具有扩展数据类型。现在,当对具有相同数据类型的 DataFrame 列执行聚合操作时,Pandas 可以保留其数据类型 (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]
请注意,数据类型现在分别是掩码数据类型和 PyArrow 数据类型,而以前是 NumPy 整数数据类型。
为了允许 DataFrame 聚合操作保留扩展数据类型,ExtensionArray._reduce() 新增了一个关键字参数 keepdims。调用 ExtensionArray._reduce() 并传入 keepdims=True 应在聚合轴上返回长度为 1 的数组。为了保持向后兼容性,该参数目前不是必需的,但在将来会成为必需参数。如果在签名中未找到该参数,DataFrame 聚合操作将无法保留扩展数据类型。此外,如果未找到该参数,将发出一个 FutureWarning,并且 mypy 等类型检查器可能会抱怨签名与 ExtensionArray._reduce() 不兼容。
写时复制改进#
Series.transform()在func就地修改Series时现在遵守写时复制原则 (GH 53747)调用
Index.values()现在将返回一个只读的 NumPy 数组 (GH 53704)DataFrame构造函数,当从 Index 对象的字典构造 DataFrame 并指定copy=False时,现在将对这些 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)尝试在临时列选择上就地操作(例如,
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() 相同的功能,但新名称更好地传达了这是 DataFrame 版本的 Series.map() (GH 52353)。
当给定一个可调用对象时,Series.map() 将该可调用对象应用于 Series 的所有元素。类似地,DataFrame.map() 将该可调用对象应用于 DataFrame 的所有元素,而 Index.map() 将该可调用对象应用于 Index 的所有元素。
通常,不希望将可调用对象应用于数组中的 nan 值,为了避免这种情况,可以调用 map 方法并传入 na_action="ignore",例如 ser.map(func, na_action="ignore")。然而,na_action="ignore" 并未针对许多 ExtensionArray 和 Index 类型实现,并且除了可为空的数值类型(即数据类型为 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"。此行为已被弃用,Categorical.map() 的默认值将改为 na_action=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 值,但在处理过程中仍会将数据类型强制转换为 float64。在新版本中,不会引入任何 NA 值,因此也没有数据类型的强制转换。
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)将类别的 dtype 添加到
CategoricalDtype的repr信息中 (GH 52179)为
read_excel()添加了engine_kwargs参数 (GH 52214)对类型提示有用的类已添加到新子模块
pandas.api.typing的公共 API 中 (GH 48577)为具有
pyarrow.timestamp的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()(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)添加了
ExtensionArray.interpolate(),供Series.interpolate()和DataFrame.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进行分组聚合(例如DataFrameGroupBy.sum())现在可以保留输入的 dtype,而不再强制转换为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 数据类型 (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)Series.cummax()、Series.cummin()和Series.cumprod()现在支持 pyarrow 13.0 及更高版本的 pyarrow 数据类型 (GH 52085)增加了对 DataFrame Consortium Standard 的支持 (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,其附加的 dtype 名称已从PandasDtype更改为NumpyEADtype;导入PandasArray在下一个主要版本之前仍然有效 (GH 53694)
弃用#
弃用 setitem 类的 Series 操作中的隐式向上转型#
PDEP-6: https://pandas.ac.cn/pdeps/0006-ban-upcasting.html
在 Series(或 DataFrame 列)上执行的 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 数据类型:
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
根据用例,转换为不同的数据类型可能更合适。例如,在以下示例中,我们转换为 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 类型的 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 时的行为;过去在确定结果类型时会忽略空对象的类型,未来版本将不再忽略 (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 条目或任何 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 值时的行为;在未来版本中,这些值将被排序到末尾而不是返回 -1 (GH 54219)。弃用
DataFrame.groupby()和Series.groupby()中observed=False的默认值;这在未来版本中将默认为True(GH 43999)。弃用在
SeriesGroupBy.aggregate()聚合中将group.name绑定到每个组的行为;如果您的操作需要利用 groupby 键,请改为迭代 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 列时的行为,在未来版本中,这些列在确定结果类型时将不会被丢弃 (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()对于布尔对象为对象类型Index返回True的行为 (GH 52680)。弃用方法
Series.bool()和DataFrame.bool()(GH 51749)。弃用
DatetimeIndex构造函数中未使用的closed和normalize关键字 (GH 52628)。弃用
TimedeltaIndex构造函数中未使用的closed关键字 (GH 52628)。弃用两个非布尔
Series之间索引不同时,逻辑运算总是将结果强制转换为布尔类型的行为。在未来版本中,这将保持输入的数据类型 (GH 52500, GH 52538)。弃用
Period和PeriodDtype与BDay频率一起使用,请改为使用带有BDay频率的DatetimeIndex(GH 53446)。弃用
value_counts(),请改为使用pd.Series(obj).value_counts()(GH 47862)。弃用
Series.first()和DataFrame.first();请改为创建掩码并使用.loc进行筛选 (GH 45908)。弃用
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()中允许布尔类型,与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上使用Series.__getitem__()和Series.__setitem__()的位置索引,在未来版本中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)。弃用在将
freq和fill_value同时传递给DataFrame.shift()、Series.shift()和DataFrameGroupBy.shift()时,默默地忽略fill_value的行为;在未来版本中,这将引发ValueError(GH 53832)。
性能改进#
在
concat()处理同构np.float64或np.float32类型时,性能得到改进 (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()处理扩展数组类型时,性能得到改进 (GH 51549)。在
DataFrame.where()中cond由扩展类型支持时,性能得到改进 (GH 51574)。在
MultiIndex.set_levels()和MultiIndex.set_codes()中当verify_integrity=True时,性能得到改进 (GH 51873)。在
MultiIndex.sortlevel()中ascending为列表时,性能得到改进 (GH 51612)。在
Series.combine_first()中,性能得到改进 (GH 51777)。在数组不包含空值时,
fillna()的性能得到改进 (GH 51635)。在数组没有空值或全部为空值时,
isna()的性能得到改进 (GH 51630)。解析字符串为
boolean[pyarrow]类型时,性能得到改进 (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)的性能。to_csv涉及PeriodArray或PeriodIndex且使用默认date_format的操作也显著加速 (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是扩展数据类型时,性能得到改进 (GH 54299)。在
DataFrame.iloc()中,当输入为单个整数且 DataFrame 由扩展数据类型支持时,性能得到改进 (GH 54508)。在
DataFrame.isin()处理扩展数据类型时,性能得到改进 (GH 53514)。在选择行和列时,
DataFrame.loc()的性能有所改进 (GH 53014)在转置具有单个 PyArrow 数据类型的 DataFrame 时,
DataFrame.transpose()的性能有所改进 (GH 54224)在转置具有单个掩码数据类型(例如
Int64)的 DataFrame 时,DataFrame.transpose()的性能有所改进 (GH 52836)针对 PyArrow 字符串和二进制数据类型,
Series.add()的性能有所改进 (GH 53150)针对扩展数据类型,
Series.corr()和Series.cov()的性能有所改进 (GH 52502)针对
ArrowDtype,Series.drop_duplicates()的性能有所改进 (GH 54667)。使用 PyArrow 数据类型时,
Series.ffill()、Series.bfill()、DataFrame.ffill()、DataFrame.bfill()的性能有所改进 (GH 53950)针对 PyArrow 支持的字符串,
Series.str.get_dummies()的性能有所改进 (GH 53655)针对 PyArrow 支持的字符串,
Series.str.get()的性能有所改进 (GH 53152)针对 PyArrow 支持的字符串,带有
expand=True的Series.str.split()的性能有所改进 (GH 53585)当数据类型为 NumPy 浮点数据类型且
na_value为np.nan时,Series.to_numpy()的性能有所改进 (GH 52430)将 PyArrow 时间戳或持续时间数据类型转换为 NumPy 时,
astype()的性能有所改进 (GH 53326)各种
MultiIndex设置和索引操作的性能有所改进 (GH 53955)通过避免不必要的验证,在对
arrays.IntegerArray和arrays.FloatingArray执行各种重塑操作时,性能有所改进 (GH 53013)使用 PyArrow 时间戳和持续时间数据类型进行索引时,性能有所改进 (GH 53368)
当将数组传递给
RangeIndex.take()、DataFrame.loc()或DataFrame.iloc()且 DataFrame 使用 RangeIndex 时,性能有所改进 (GH 53387)
错误修复#
类别型#
CategoricalIndex.remove_categories()中修复了一个错误,该错误导致有序类别无法保持 (GH 53935)。针对带有只读空值掩码的可为空数组,
Series.astype()带有dtype="category"时修复了一个错误 (GH 53658)Series.map()中修复了一个错误,如果 series 包含Categorical,则na_action参数的值未被使用 (GH 22527)。
日期时间类型#
带有
na_action="ignore"的DatetimeIndex.map()现在按预期工作 (GH 51644)如果切片边界中的任何一个不在索引中,
DatetimeIndex.slice_indexer()现在会针对非单调索引引发KeyError;此行为先前已弃用但处理不一致 (GH 53983)DateOffset中修复了一个错误,该错误在将DateOffset对象乘以常量时行为不一致 (GH 47953)date_range()中修复了一个错误,当freq是带有nanoseconds的DateOffset时 (GH 46877)to_datetime()修复了一个错误,该错误在将包含 PyArrow 时间戳的Series或DataFrame的arrays.ArrowExtensionArray转换为 NumPy datetime 时出现 (GH 52545)DatetimeArray.map()和DatetimeIndex.map()中修复了一个错误,该错误导致提供的可调用对象以数组方式而非元素方式操作 (GH 51977)DataFrame.to_sql()中修复了一个错误,该错误在 PyArrow 支持的日期类数据类型时引发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)解析包含工作日但没有日期(例如“2023 Sept Thu”)的日期时间字符串时修复了一个错误,该错误错误地引发
AttributeError而不是ValueError(GH 52659)当数据类型是具有非纳秒分辨率的时区感知 datetime 时,
Series的 repr 中修复了一个错误,该错误引发OutOfBoundsDatetime(GH 54623)
时间差#
TimedeltaIndex除法或乘法导致.freq为“0 天”而不是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)带有
na_action="ignore"的TimedeltaIndex.map()修复了一个错误 (GH 51644)arrays.TimedeltaArray.map()和TimedeltaIndex.map()中修复了一个错误,该错误导致提供的可调用对象以数组方式而非元素方式操作 (GH 51977)
时区#
infer_freq()中修复了一个错误,该错误会针对时区感知时间戳的Series引发TypeError(GH 52456)DatetimeTZDtype.base()中修复了一个错误,该错误始终返回具有纳秒分辨率的 NumPy 数据类型 (GH 52705)
数值型#
RangeIndex中修复了一个错误,该错误在作为减数且被减数为数值时错误地设置了step(GH 53255)Series.corr()和Series.cov()中修复了一个错误,该错误针对掩码数据类型引发AttributeError(GH 51422)在对全零 NumPy 数据调用
Series.kurt()和Series.skew()时修复了一个错误,该错误返回 Python 类型而不是 NumPy 类型 (GH 53482)Series.mean()和DataFrame.mean()中修复了一个错误,该错误导致包含可转换为数字的字符串(例如“2”)的对象数据类型值返回不正确的数值结果;现在这些操作会引发TypeError(GH 36703, GH 44008)DataFrame.corrwith()中修复了一个错误,该错误针对 PyArrow 支持的数据类型引发NotImplementedError(GH 52314)DataFrame.size()和Series.size()修复了一个错误,该错误返回 64 位整数而不是 Python int (GH 52897)DateFrame.dot()中修复了一个错误,该错误针对ArrowDtype数据返回object数据类型 (GH 53979)Series.any()、Series.all()、DataFrame.any()和DataFrame.all()修复了一个错误,该错误导致bool_only的默认值设置为None而不是False;此更改不应影响用户 (GH 53258)Series.corr()和Series.cov()中修复了一个错误,该错误针对掩码数据类型引发AttributeError(GH 51422)Series.median()和DataFrame.median()修复了一个错误,该错误导致包含可转换为数字的字符串(例如“2”)的对象数据类型值返回不正确的数值结果;现在这些操作会引发TypeError(GH 34671)Series.sum()将数据类型uint64转换为int64的错误已修复 (GH 53401)
转换#
DataFrame.style.to_latex()和DataFrame.style.to_html()中修复了一个错误,如果 DataFrame 包含的整数位数超过浮点双精度所能表示的位数 (GH 52272)array()修复了一个错误,该错误在给定单位为“s”、“us”或“ms”的datetime64或timedelta64数据类型时返回NumpyExtensionArray而不是DatetimeArray或TimedeltaArray(GH 52859)array()修复了一个错误,该错误在给定空列表且无数据类型时返回NumpyExtensionArray而不是FloatingArray(GH 54371)ArrowDtype.numpy_dtype()修复了一个错误,该错误会针对非纳秒pyarrow.timestamp和pyarrow.duration类型返回纳秒单位 (GH 51800)DataFrame.__repr__()修复了一个错误,该错误在列的数据类型为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修复了一个错误 (GH 54797)
区间#
IntervalIndex.get_indexer()和IntervalIndex.get_indexer_nonunique()修复了一个错误,该错误在target是只读数组时引发错误 (GH 53703)IntervalDtype中修复了一个错误,该错误导致对象在删除时仍可能存活 (GH 54184)interval_range()中修复了一个错误,该错误导致浮点step由于浮点数误差产生不正确的区间 (GH 54477)
索引#
DataFrame.__setitem__()修复了一个错误,该错误在将DataFrame设置到重复列时会丢失数据类型 (GH 53143)DataFrame.__setitem__()带有布尔掩码和DataFrame.putmask()带有混合非数值数据类型和除了NaN以外的值时修复了一个错误,该错误错误地引发了TypeError(GH 53291)DataFrame.iloc()修复了一个错误,该错误在使用nan作为唯一元素时出现 (GH 52234)Series.loc()修复了一个错误,该错误在对象数据类型Series的预定义索引处分配Series时将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()修复了一个错误,该错误在带有包含NaT的DatetimeIndex索引时错误地返回NaN而不是NaT(GH 43587)Series.interpolate()和DataFrame.interpolate()修复了一个错误,该错误在无效的downcast关键字上未能引发错误,该关键字只能是None或"infer"(GH 53103)具有复杂数据类型的
Series.interpolate()和DataFrame.interpolate()修复了一个错误,该错误错误地未能填充NaN条目 (GH 53635)
MultiIndex#
MultiIndex.set_levels()未保留Categorical数据类型的错误已修复 (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()中修复了一个错误,该错误在parse_dates设置为列表或字典且engine="pyarrow"时会出错 (GH 47961)read_csv()带有engine="pyarrow"时,在指定dtype和index_col时引发错误的错误已修复 (GH 53229)read_hdf()修复了一个错误,该错误在引发IndexError后未正确关闭存储 (GH 52781)read_html()修复了一个错误,该错误导致样式元素被读取到 DataFrames 中 (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()修复了一个错误,该错误导致具有复杂数据类型的空DataFrame转换时引发了ValueError(GH 54167)DataFrame.to_json()修复了一个错误,该错误导致具有非纳秒精度的DateTimeArray/DateTimeIndex无法正确序列化 (GH 53686)写入和读取空 Stata dta 文件时丢失数据类型信息的错误已修复 (GH 46240)
bz2被视为硬性要求的错误已修复 (GH 53857)
周期#
PeriodDtype构造函数中修复了一个错误,该错误在没有传递参数或传递None时未能引发TypeError(GH 27388)PeriodDtype构造函数中修复了一个错误,该错误为不同的DateOffsetfreq输入错误地返回相同的normalize(GH 24121)PeriodDtype构造函数中修复了一个错误,该错误在传递无效类型时引发ValueError而不是TypeError(GH 51790)PeriodDtype中修复了一个错误,该错误导致对象在删除时仍可能存活 (GH 54184)read_csv()修复了一个错误,该错误在使用engine="pyarrow"时未将空字符串处理为 null 值 (GH 52087)read_csv()修复了一个错误,该错误在使用engine="pyarrow"且所有列都为 null 时,返回object数据类型列而不是float64数据类型列 (GH 52087)Period.now()修复了一个错误,该错误不接受freq参数作为关键字参数 (GH 53369)带有
na_action="ignore"的PeriodIndex.map()修复了一个错误 (GH 51644)arrays.PeriodArray.map()和PeriodIndex.map()中修复了一个错误,该错误导致提供的可调用对象以数组方式而非元素方式操作 (GH 51977)修复了一个错误,该错误错误地允许使用
CustomBusinessDay频率构造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 上使用时返回错误的数据类型 (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或掩码数据类型(例如Int64)的数据,数据类型将为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或掩码数据类型(例如Int64)的数据,数据类型将为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 时强制转换为objectdtype 的错误 (GH 53702)在
crosstab()中,当dropna=False时不会在结果中保留np.nan的错误 (GH 10772)在
melt()中,variable列会丢失扩展数据类型(extension dtypes)的错误 (GH 54297)在
merge_asof()中,对扩展数据类型(extension dtypes)引发KeyError的错误 (GH 52904)在
merge_asof()中,对于只读 ndarrays 支持的数据引发ValueError的错误 (GH 53513)在
merge_asof()中,当left_index=True或right_index=True与不匹配的索引数据类型(index dtypes)在某些情况下给出不正确的结果而不是引发MergeError的错误 (GH 53870)在
merge()中,当合并整数ExtensionDtype和浮点 NumPy dtype 时引发TypeError的错误 (GH 46178)在
DataFrame.agg()和Series.agg()中,对非唯一列应用 dist-like 参数时返回不正确类型的错误 (GH 51099)在
DataFrame.combine_first()中,如果other为空则忽略其列的错误 (GH 53792)在
DataFrame.idxmin()和DataFrame.idxmax()中,空帧的轴数据类型(axis dtype)会丢失的错误 (GH 53265)在
DataFrame.merge()中,当MultiIndex具有单层时合并不正确的错误 (GH 52331)在
DataFrame.stack()中,当列是MultiIndex且帧包含混合数据类型时,会丢失扩展数据类型(extension dtypes)的错误 (GH 45740)在
DataFrame.stack()中,按字典顺序对列进行排序的错误 (GH 53786)在
DataFrame.transpose()中,推断对象列数据类型(dtype)的错误 (GH 51546)在
Series.combine_first()中,将int64数据类型转换为float64并导致非常大的整数精度丢失的错误 (GH 51764)在连接空的
DataFrame对象时,连接的索引会变成RangeIndex而不是连接的索引类型的错误 (GH 52777)
稀疏#
在
SparseDtype构造函数中,当为其子类型给定不兼容的dtype(必须是 NumPy dtype)时未能引发TypeError的错误 (GH 53160)在
arrays.SparseArray.map()中,允许将填充值包含在稀疏值中的错误 (GH 52095)
扩展数组#
在
ArrowStringArray构造函数中,对于字符串的字典类型引发ValueError的错误 (GH 54074)在
DataFrame构造函数中,当在字典中给定具有扩展数据类型(extension dtype)的Series时未复制的错误 (GH 53744)在
ArrowExtensionArray中,将 pandas 非纳秒时间对象从非零值转换为零值的错误 (GH 53171)在
Series.quantile()中,对于 PyArrow 时间类型引发ArrowInvalid的错误 (GH 52678)在
Series.rank()中,对于Float64数据类型的小值返回错误顺序的错误 (GH 52471)在
Series.unique()中,对于包含NA值的布尔ArrowDtype返回不正确唯一值的错误 (GH 54667)在
__iter__()和__getitem__()中,对于非纳秒数据类型(non-nano dtypes)返回 python datetime 和 timedelta 对象的错误 (GH 53326)在
factorize()中,对于包含多个块的pyarrow.dictionary类型pyarrow.chunked_array返回不正确唯一值的错误 (GH 54844)在将
ExtensionArray子类传递给dtype关键字时出错。现在将引发UserWarning以鼓励传递实例 (GH 31356, GH 54592)当列具有带
pyarrow.ExtensionDtype的ArrowDtype时,DataFramerepr 不工作的错误 (GH 54063)掩码扩展数据类型(masked ExtensionDtypes)(例如
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值时,对复杂数据类型(complex dtype)的数据引发错误的错误 (GH 53627)在
DatetimeIndex中,当索引传递时间且时间为午夜且非基于日期的频率时,repr不打印时间的错误 (GH 53470)在
testing.assert_frame_equal()和testing.assert_series_equal()中,现在对两个不相等的集合抛出断言错误的错误 (GH 51727)在
testing.assert_frame_equal()中,即使要求不检查索引类型也会检查分类数据类型(category dtypes)的错误 (GH 52126)在
api.interchange.from_dataframe()中,不遵守allow_copy参数的错误 (GH 54322)在
api.interchange.from_dataframe()中,从包含空值的非 pandas 时区感知数据进行交换时引发错误的错误 (GH 54287)在
api.interchange.from_dataframe()中,转换空 DataFrame 对象时出现的错误 (GH 53155)在
from_dummies()中,结果Index与原始Index不匹配的错误 (GH 54300)在
from_dummies()中,结果数据总是object数据类型而不是列的数据类型的错误 (GH 54300)在
DataFrameGroupBy.first(),DataFrameGroupBy.last(),SeriesGroupBy.first()和SeriesGroupBy.last()中,空组返回np.nan而不是相应的ExtensionArrayNA 值的错误 (GH 39098)在
DataFrame.pivot_table()中,将整数的平均值转换回整数的错误 (GH 16676)在
DataFrame.reindex()中,当fill_value应推断为ExtensionDtype时错误地推断为object数据类型的错误 (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()中,当给空序列提供可调用对象时,返回的序列具有object数据类型。现在它会保留原始数据类型 (GH 52384)在
Series.memory_usage()中,当deep=True时,对于对象系列抛出错误,并且返回的值不正确,因为它没有考虑 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 +
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 +