2.1.0 中的新功能 (2023年8月30日)#
这是 pandas 2.1.0 中的更改。请参阅 发行说明 以获取包括其他版本 pandas 的完整更新日志。
增强功能#
PyArrow 将成为 pandas 3.0 的必需依赖项#
PyArrow 将从 pandas 3.0 开始成为 pandas 的必需依赖。这一决定是基于 PDEP 10 做出的。
这将启用对 pandas 用户非常有益的更多更改,包括但不限于:
默认情况下将字符串推断为 PyArrow 支持的字符串,从而显著减少内存占用并大幅提升性能。
默认情况下,通过 PyArrow 推断更复杂的 dtypes,如
Decimal、列表、字节、结构化数据等。与其他依赖于 Apache Arrow 的库更好的互操作性。
我们正在收集对此决定的反馈 这里。
默认情况下避免使用 NumPy 对象 dtype 用于字符串#
以前,所有字符串默认存储在具有NumPy对象数据类型的列中。此版本引入了一个选项 future.infer_string,该选项推断所有字符串为具有数据类型 "string[pyarrow_numpy]" 的PyArrow支持的字符串。这是一个新的字符串数据类型实现,遵循NumPy语义进行比较操作,并将返回 np.nan 作为缺失值指示符。设置该选项还会将数据类型 "string" 推断为 StringDtype,并将存储设置为 "pyarrow_numpy",忽略选项 mode.string_storage 背后的值。
此选项仅在安装了 PyArrow 时有效。与 NumPy 对象相比,PyArrow 支持的字符串显著减少了内存占用,并提供了巨大的性能提升(GH 54430)。
该选项可以通过以下方式启用:
pd.options.future.infer_string = True
此行为将成为 pandas 3.0 的默认行为。
DataFrame 缩减保留扩展数据类型#
在 pandas 的早期版本中,DataFrame 缩减的结果(DataFrame.sum() DataFrame.mean() 等)具有 NumPy dtypes,即使 DataFrames 是扩展 dtypes。pandas 现在可以在对具有相同 dtype 的 DataFrame 列进行缩减时保留 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 分别是掩码 dtype 和 PyArrow dtype,而之前它是 NumPy 整数 dtype。
为了允许 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)当从 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)尝试在临时列选择上就地操作(例如,
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")。然而,许多 ExtensionArray 和 Index 类型未实现 na_action="ignore",并且除了可空数值类型(即具有 dtype Int64 等)之外,na_action="ignore" 对任何 ExtensionArray 子类都无法正确工作。
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值,并且永远不会排序。因此,参数 dropna 和 sort 不再使用,并且在使用 future_stack=True 时必须保持未指定。这些参数将在下一个主要版本中被移除。
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,对分类数据的系列调用现在将使用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)将
"latex-math"作为选项添加到Styler的escape参数中,这将不会在格式化期间转义"\("和"\)"之间的所有字符 (GH 51903)将类别的 dtype 添加到
CategoricalDtype的repr信息中 (GH 52179)为
read_excel()添加engine_kwargs参数 (GH 52214)在新的子模块
pandas.api.typing中,已添加对类型提示有用的类到公共 API 中 (GH 48577)实现了
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()用于ArrowDtype与pyarrow.timestamp(GH 52388, GH 51718)DataFrameGroupBy.agg()和DataFrameGroupBy.transform()现在支持在索引不是MultiIndex时,通过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)将
validate参数添加到Categorical.from_codes()(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())现在可以保留输入的 dtype,而不是转换为float64(GH 44952)改进了当
DataFrameGroupBy.agg()失败时的错误信息 (GH 52930)许多读/写函数,例如
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()现在支持对象类型 (GH 4279, GH 18021, GH 40685, GH 43697)DataFrame.to_parquet()和read_parquet()现在将分别写入和读取attrs(GH 54346)Index.all()和Index.any()在浮点数据类型和 timedelta64 数据类型下不再引发TypeError,与Series.all()和Series.any()行为匹配 (GH 54566)Series.cummax(),Series.cummin()和Series.cumprod()现在支持 pyarrow 版本 13.0 及以上的 pyarrow 数据类型 (GH 52085)增加了对 DataFrame 联盟标准的支持 (GH 54383)
在
DataFrameGroupBy.quantile()和SeriesGroupBy.quantile()中的性能提升 (GH 51722)PyArrow 支持的整数数据类型现在支持按位操作 (GH 54495)
向后不兼容的 API 更改#
增加了 Python 的最小版本要求#
pandas 2.1.0 支持 Python 3.9 及以上版本。
增加了依赖项的最小版本要求#
一些依赖项的最低支持版本已更新。如果已安装,我们现在要求:
包 |
最低版本 |
必需的 |
Changed |
|---|---|---|---|
numpy |
1.22.4 |
X |
X |
mypy (dev) |
1.4.1 |
X |
|
beautifulsoup4 |
4.11.1 |
X |
|
瓶颈 |
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.pydata.org/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 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
根据使用情况,可能更适合转换为不同的数据类型。例如,在下面,我们转换为 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.pydata.org/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[s, 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)当任何被连接的对象长度为0时,已弃用
concat()行为;在过去,确定结果数据类型时会忽略空对象的数据类型,在未来的版本中将不会忽略 (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)已弃用的
fill_method和limit关键字在DataFrame.pct_change()、Series.pct_change()、DataFrameGroupBy.pct_change()和SeriesGroupBy.pct_change()中,请在调用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)在所有条目均为NA或任何条目为NA且``skipna=False``的情况下,
DataFrame.idxmax(),DataFrame.idxmin(),Series.idxmax(),Series.idxmin()的弃用行为;在未来的版本中,这些将引发ValueError(GH 51276)弃用给
Series.agg()的函数尝试在每个Series元素上操作,并且只有在元素级操作失败时才在整个Series上操作。在未来,给Series.agg()的函数将始终只在整个Series上操作。要保持当前行为,请改用Series.transform()(GH 53325)弃用在一个给定的函数列表中尝试对
DataFrame.agg()中的每个元素进行操作,只有在逐元素操作失败时才对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)在未来版本中,当
len(keys) != len(objs)时,concat()的行为将被弃用,届时这将引发错误而不是截断到两个序列中较短的那个(GH 43485)在存在NA值的情况下,弃用了
Series.argsort()的行为;在未来的版本中,这些值将被排序到末尾,而不是给出-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)当
DataFrame的所有列都是全NA时,concat()的弃用行为,在未来的版本中,这些列在确定结果数据类型时不会被丢弃 (GH 40893)已弃用的
Series.dt.to_pydatetime()行为,在未来的版本中,这将返回一个包含 Pythondatetime对象的Series,而不是日期时间的ndarray;这与其他Series.dt属性的行为相匹配 (GH 20306)不推荐在 pandas 对象和无 dtype 的序列(例如
list,tuple)之间使用逻辑操作(|,&,^),操作前请将序列包装在Series或 NumPy 数组中 (GH 51521)已弃用的参数
convert_type在Series.apply()中 (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之间的弃用逻辑操作总是强制将结果转换为布尔类型。在未来的版本中,这将保持输入的返回类型 (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)已弃用
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)不推荐使用字面量 json 输入到
read_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)已弃用的字符串
T,t,L和l表示to_timedelta()中的单位 (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)已弃用的值
"pad","ffill","bfill","backfill"用于Series.interpolate()和DataFrame.interpolate(),请改用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)
性能提升#
在使用同质
np.float64或np.float32dtypes 时,concat()的性能提升 (GH 52685)在
factorize()中对不包含字符串的对象列的性能改进 (GH 51921)在读取远程URI文件路径时,
read_orc()的性能提升 (GH 51609)在使用
engine="pyarrow"读取远程文件时,read_parquet()和DataFrame.to_parquet()的性能提升 (GH 51609)在使用
use_nullable_dtypes=True时,字符串列上的read_parquet()性能提升 (GH 47345)在
DataFrame.clip()和Series.clip()中的性能提升 (GH 51472)当给出
items时,DataFrame.filter()的性能改进 (GH 52941)在扩展数组dtypes中,
DataFrame.first_valid_index()和DataFrame.last_valid_index()的性能改进 (GH 51549)当
cond由扩展数据类型支持时,DataFrame.where()的性能改进 (GH 51574)在
verify_integrity=True时,MultiIndex.set_levels()和MultiIndex.set_codes()的性能改进 (GH 51873)当
ascending是一个列表时,MultiIndex.sortlevel()的性能改进 (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)`。涉及使用默认 ``date_format的PeriodArray或PeriodIndex的to_csv操作也显著加速(GH 51459)访问
arrays.IntegerArrays.dtype和arrays.FloatingArray.dtype的性能改进 (GH 52998)性能提升:对于使用
engine="numba"的DataFrameGroupBy/SeriesGroupBy聚合(例如DataFrameGroupBy.sum())(GH 53731)在
MultiIndex和多列操作(例如DataFrame.sort_values()、DataFrame.groupby()、Series.unstack())中性能提升,当索引/列值已经排序时 (GH 53806)当连接轴是
MultiIndex时,concat()的性能改进 (GH 53574)在使用
engine="c"时,read_csv()的性能提升 (GH 52632)在
ArrowExtensionArray.to_numpy()中的性能提升 (GH 52525)在
DataFrameGroupBy.groups()中的性能提升 (GH 53088)当
dtype是一个扩展 dtype 时,DataFrame.astype()的性能改进 (GH 54299)当输入是单个整数且数据框由扩展数据类型支持时,
DataFrame.iloc()的性能改进 (GH 54508)在
DataFrame.isin()中对扩展数据类型的性能改进 (GH 53514)在选择行和列时,
DataFrame.loc()的性能提升 (GH 53014)在转置一个包含单个 PyArrow dtype 的 DataFrame 时,
DataFrame.transpose()的性能改进 (GH 54224)在转置一个包含单个掩码数据类型的 DataFrame 时,
DataFrame.transpose()的性能改进,例如Int64(GH 52836)在
Series.add()中对 PyArrow 字符串和二进制 dtypes 的性能改进 (GH 53150)在扩展 dtypes 中对
Series.corr()和Series.cov()的性能改进 (GH 52502)在
Series.drop_duplicates()中对ArrowDtype的性能改进 (GH 54667)。在使用 PyArrow dtypes 的情况下,
Series.ffill()、Series.bfill()、DataFrame.ffill()、DataFrame.bfill()的性能提升 (GH 53950)在
Series.str.get_dummies()中对 PyArrow 支持的字符串的性能改进 (GH 53655)在
Series.str.get()中对 PyArrow 支持的字符串的性能改进 (GH 53152)在使用
expand=True的情况下,Series.str.split()在 PyArrow 支持的字符串中的性能提升 (GH 53585)当 dtype 是 NumPy 浮点 dtype 且
na_value是np.nan时,Series.to_numpy()的性能改进 (GH 52430)在从 PyArrow 时间戳或持续时间 dtype 转换为 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)
错误修复#
Categorical#
在
CategoricalIndex.remove_categories()中的错误,其中有序类别不会被维持 (GH 53935)。在
Series.astype()中使用dtype="category"时,对于带有只读空值掩码的可空数组的错误 (GH 53658)在
Series.map()中的一个错误,如果序列包含Categorical,则na_action参数的值未被使用(GH 22527)。
Datetimelike#
DatetimeIndex.map()使用na_action="ignore"现在按预期工作 (GH 51644)DatetimeIndex.slice_indexer()现在对于非单调索引,如果任何一个切片边界不在索引中,则会引发KeyError;此行为之前已被弃用,但处理不一致 (GH 53983)DateOffset中的一个错误,当将DateOffset对象乘以一个常数时,其行为不一致 (GH 47953)当
freq是一个包含nanoseconds的DateOffset时,date_range()中的 Bug (GH 46877)在将包含 PyArrow 时间戳的
arrays.ArrowExtensionArray的Series或DataFrame转换为 numpy 日期时间时存在错误 (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)解析带有工作日但没有日期的日期时间字符串时出现错误,例如“2023 Sept Thu”,错误地引发
AttributeError而不是ValueError(GH 52659)当 dtype 是具有非纳秒分辨率的时区感知 datetime 时,
Series的 repr 中的 Bug 引发OutOfBoundsDatetime(GH 54623)
Timedelta#
TimedeltaIndex的除法或乘法中的错误导致.freq为 “0 Days” 而不是None(GH 51575)Timedelta中与 NumPytimedelta64对象相关的错误未能正确引发ValueError(GH 52806)在将包含
pyarrow.duration的ArrowDtype的Series或DataFrame转换为 NumPytimedelta64时出现错误 (GH 54298)在
Timedelta.__hash__()中的错误,在某些较大的秒分辨率值上引发OutOfBoundsTimedelta(GH 54037)在接近实现边界值的情况下,
Timedelta.round()中的错误返回不正确的结果,而不是引发OutOfBoundsTimedelta(GH 51494)Bug in
TimedeltaIndex.map()withna_action="ignore"(GH 51644)在
arrays.TimedeltaArray.map()和TimedeltaIndex.map()中的错误,其中提供的可调用对象以数组方式操作而不是元素方式操作 (GH 51977)
时区#
在
infer_freq()中存在的错误,对于时区感知的Series时间戳会引发TypeError(GH 52456)在
DatetimeTZDtype.base()中的错误,总是返回一个具有纳秒分辨率的 NumPy dtype (GH 52705)
Numeric#
在
RangeIndex中设置step不正确,当作为被减数且减数为数值时 (GH 53255)Series.corr()和Series.cov()中的错误在掩码数据类型上引发AttributeError(GH 51422)在调用
Series.kurt()和Series.skew()时,当所有 NumPy 数据为零时返回 Python 类型而不是 NumPy 类型 (GH 53482)在包含可以转换为数字的字符串(例如“2”)的对象类型值中,
Series.mean()和DataFrame.mean()存在错误,返回不正确的数值结果;现在这些情况会引发TypeError(GH 36703, GH 44008)在
DataFrame.corrwith()中对 PyArrow 支持的数据类型引发NotImplementedError的错误 (GH 52314)DataFrame.size()和Series.size()中的错误,返回64位整数而不是Python整数 (GH 52897)在返回
ArrowDtype数据的objectdtype 时DateFrame.dot()中的 Bug (GH 53979)Series.any(),Series.all(),DataFrame.any(), 和DataFrame.all()中的一个错误将bool_only的默认值设置为None而不是False;这一更改应该不会对用户产生影响 (GH 53258)Series.corr()和Series.cov()中的错误在掩码数据类型上引发AttributeError(GH 51422)在包含可以转换为数字的字符串(例如“2”)的对象类型值中,
Series.median()和DataFrame.median()存在错误,返回不正确的数值结果;现在这些情况会引发TypeError(GH 34671)Series.sum()中将数据类型uint64转换为int64的错误 (GH 53401)
转换#
如果 DataFrame 包含的整数位数超过浮点数双精度所能表示的位数,则
DataFrame.style.to_latex()和DataFrame.style.to_html()存在错误 (GH 52272)当给定单位为“s”、“us”或“ms”的
datetime64或timedelta64dtype 时,array()中的错误返回NumpyExtensionArray而不是DatetimeArray或TimedeltaArray(GH 52859)当给定一个空列表且没有 dtype 时,
array()中的错误返回NumpyExtensionArray而不是FloatingArray(GH 54371)在
ArrowDtype.numpy_dtype()中返回非纳秒pyarrow.timestamp和pyarrow.duration类型的纳秒单位的问题 (GH 51800)DataFrame.__repr__()中的一个错误在列的数据类型为np.record时错误地引发了一个TypeError(GH 48526)在设置
use_numba时,DataFrame.info()引发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)
Interval#
IntervalIndex.get_indexer()和IntervalIndex.get_indexer_nonunique()如果target是只读数组则引发 (GH 53703)在
IntervalDtype中的一个错误,当对象被删除时可能仍然保持活动状态 (GH 54184)在
interval_range()中的一个错误,其中浮点数step会由于浮点数舍入误差产生不正确的区间 (GH 54477)
索引#
在将
DataFrame设置到重复列时,DataFrame.__setitem__()中的错误会丢失 dtype (GH 53143)在使用布尔掩码的
DataFrame.__setitem__()和混合非数字数据类型且值不是NaN的DataFrame.putmask()时,错误地引发TypeError的错误 (GH 53291)当仅使用
nan作为唯一元素时,DataFrame.iloc()中的错误 (GH 52234)在
Series.loc()中存在一个错误,当在objectdtype 的Series的预定义索引处分配Series时,会将Series转换为np.dnarray(GH 48933)
缺失#
在
method为"pad"、"ffill"、"bfill"或"backfill"时,DataFrame.interpolate()中的错误导致无法跨数据填充 (GH 53898)在
DataFrame为空时,DataFrame.interpolate()中的inplace被忽略的错误 (GH 53199)在包含
NaT的DatetimeIndex索引中,Series.idxmin(),Series.idxmax(),DataFrame.idxmin(),DataFrame.idxmax()中的 Bug 错误地返回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的 dtypes (GH 52125)显示带有长元素的
MultiIndex时出现错误 (GH 52960)
I/O#
DataFrame.to_orc()现在在给定非默认的Index时引发ValueError(GH 51828)DataFrame.to_sql()现在在使用 SQLAlchemy 连接时,当名称参数为空时会引发ValueError(GH 52675)json_normalize()中的错误无法解析元数据字段列表类型 (GH 37782)在
read_csv()中的错误,当parse_dates设置为一个包含engine="pyarrow"的列表或字典时会出现错误 (GH 47961)使用
engine="pyarrow"时,指定dtype和index_col会导致read_csv()出现错误 (GH 53229)在引发
IndexError后,read_hdf()中的错误未正确关闭存储 (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 文件时出现错误,其中 dtype 信息丢失 (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"(GH 52087)在
read_csv()中存在一个错误,当使用engine="pyarrow"时,返回的是object数据类型的列,而不是float64数据类型的列,这些列在engine="pyarrow"下全是空值 (GH 52087)在
Period.now()中存在一个错误,不接受freq参数作为关键字参数 (GH 53369)Bug in
PeriodIndex.map()withna_action="ignore"(GH 51644) 的中文翻译为:在
arrays.PeriodArray.map()和PeriodIndex.map()中的错误,其中提供的可调用对象以数组方式操作而不是元素方式操作 (GH 51977)在错误地允许使用
CustomBusinessDayfreq 构建Period或PeriodDtype的错误;请改用BusinessDay(GH 52534)
绘图#
当使用
color=None调用Series.plot()时出现的错误 (GH 51953)在调用
c="b"时修复了DataFrame.plot.scatter()中的 Fixed UserWarning (GH 53908)
分组/重采样/滚动#
DataFrameGroupBy.idxmin(),SeriesGroupBy.idxmin(),DataFrameGroupBy.idxmax(),SeriesGroupBy.idxmax()中的错误:当在空的 DataFrameGroupBy 或 SeriesGroupBy 上使用时返回错误的 dtype (GH 51423)在传递
na_option="bottom"或na_option="top"时,DataFrame.groupby.rank()在可空数据类型中的错误 (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在 groupby 后被子集化为DataFrame`(``[['a']]`而不是['a'])并且给定的可调用对象返回的Series没有全部使用相同的索引时,会导致错误被引发 (GH 52444)在选择多个列并提供返回
np.ndarray结果的函数时,DataFrameGroupBy.apply()中的错误引发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)在使用
dropna="any"或dropna="all"进行列选择后,SeriesGroupBy.nth()和DataFrameGroupBy.nth()中的错误不会对列进行子集化 (GH 53518)Bug in
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有一个DatetimeIndex索引并且给by参数传递了一个名为月份的Series时,Series.groupby()中的错误 (GH 48509)
Reshaping#
在
concat()中将类型强制转换为object类型时,当某一列具有pa.null()类型 (GH 53702) 的错误当
dropna=False时,crosstab()中的错误不会在结果中保留np.nan(GH 10772)在
merge_asof()中对扩展 dtypes 引发KeyError的错误 (GH 52904)在
merge_asof()中出现的错误,对于由只读 ndarrays 支持的数据引发ValueError(GH 53513)在
merge_asof()中使用left_index=True或right_index=True时,索引数据类型不匹配在某些情况下会给出不正确的结果,而不是引发MergeError(GH 53870)在合并整数
ExtensionDtype和浮点数 NumPy dtype 时merge()中的错误引发TypeError(GH 46178)在非唯一列上使用
DataFrame.agg()和Series.agg()时出现的错误,当传递类似 dist 的参数时会返回不正确的类型 (GH 51099)在
DataFrame.combine_first()中的错误,如果other为空,则忽略其他列 (GH 53792)在
DataFrame.idxmin()和DataFrame.idxmax()中的错误,其中轴的数据类型会因空帧而丢失 (GH 53265)在具有单级
MultiIndex时,DataFrame.merge()中的错误导致无法正确合并 (GH 52331)当列是
MultiIndex并且框架包含混合的 dtypes 时,DataFrame.stack()中的 Bug 会丢失扩展 dtypes (GH 45740)在
DataFrame.stack()中按字典顺序排序列的错误 (GH 53786)在
DataFrame.transpose()中推断对象列的数据类型时存在错误 (GH 51546)Series.combine_first()中的错误将int64数据类型转换为float64并在非常大的整数上失去精度 (GH 51764)当连接空的
DataFrame对象时出现错误,连接后的索引会是RangeIndex而不是连接索引类型 (GH 52777)
Sparse#
SparseDtype构造函数在给定其子类型的不兼容dtype时未能引发TypeError的错误,该子类型必须是 NumPy dtype (GH 53160)在
arrays.SparseArray.map()中的错误允许填充值包含在稀疏值中 (GH 52095)
ExtensionArray#
ArrowStringArray构造函数中的错误在处理字典类型的字符串时会引发ValueError(GH 54074)ArrowExtensionArray中的错误,将 pandas 非纳秒时间对象从非零值转换为零值 (GH 53171)在
Series.quantile()中,PyArrow 时间类型引发ArrowInvalid的错误 (GH 52678)在
Series.rank()中存在一个错误,对于Float64数据类型的小值返回了错误的顺序 (GH 52471)在包含
NA值的布尔ArrowDtype中Series.unique()的错误 (GH 54667)在
__iter__()和__getitem__()中返回非纳秒 dtypes 的 python datetime 和 timedelta 对象的 Bug (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 的
__from_arrow__方法(例如Float64Dtype,BooleanDtype)中存在一个错误,该方法不接受类型为pyarrow.null()的 PyArrow 数组 (GH 52223)
Styler#
元数据#
修复了
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)在
DatetimeIndex中的错误,当传递带有时间的索引的repr不打印时间为午夜且非基于日的频率(GH 53470)testing.assert_frame_equal()和testing.assert_series_equal()中的错误现在会为两个不相等的集合抛出断言错误 (GH 51727)在
testing.assert_frame_equal()中的错误检查类别 dtypes,即使被要求不检查索引类型 (GH 52126)api.interchange.from_dataframe()中的错误没有尊重allow_copy参数 (GH 54322)api.interchange.from_dataframe()中的错误在从包含空值的非 pandas tz-aware 数据交换期间引发 (GH 54287)在转换空DataFrame对象时
api.interchange.from_dataframe()中的Bug (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)在包含单个
ExtensionDtype列的DataFrame上使用axis=1的DataFrame.shift()存在错误,导致结果不正确 (GH 53832)当传递
key时,Index.sort_values()中的错误 (GH 52764)在
Series.align()、DataFrame.align()、Series.reindex()、DataFrame.reindex()、Series.interpolate()、DataFrame.interpolate()中存在一个错误,错误地未能使用 method=”asfreq” 引发 (GH 53620)在传递无效的
axis时,Series.argsort()中的错误未能引发 (GH 54257)当给一个空系列传递一个可调用对象时,
Series.map()中的错误,返回的系列具有object数据类型。现在它保持原始数据类型 (GH 52384)当
deep=True时,Series.memory_usage()中的错误会抛出对象系列的错误,并且返回值不正确,因为它没有考虑到 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 +