1.3.0 版的新功能 (2021年7月2日)#

这些是 pandas 1.3.0 中的更改。有关包括其他 pandas 版本在内的完整更改日志,请参阅发行说明

警告

读取新的 Excel 2007+ (.xlsx) 文件时,read_excel() 的默认参数 engine=None 现在将在选项 io.excel.xlsx.reader 设置为 "auto" 的所有情况下使用 openpyxl 引擎。以前,在某些情况下会使用 xlrd 引擎。有关此更改的背景信息,请参阅1.2.0 版新功能

功能增强#

读取 CSV 或 JSON 文件时自定义 HTTP(s) 头#

当从不受 fsspec 处理的远程 URL(例如 HTTP 和 HTTPS)读取数据时,传递给 storage_options 的字典将用于创建请求中包含的头部。这可用于控制 User-Agent 头部或发送其他自定义头部(GH 36688)。例如:

In [1]: headers = {"User-Agent": "pandas"}
In [2]: df = pd.read_csv(
   ...:     "https://download.bls.gov/pub/time.series/cu/cu.item",
   ...:     sep="\t",
   ...:     storage_options=headers
   ...: )

读取和写入 XML 文档#

我们添加了 I/O 支持,可以使用 read_xml()DataFrame.to_xml() 读取和渲染 XML 文档的浅层版本。使用 lxml 作为解析器,XPath 1.0 和 XSLT 1.0 均可用。(GH 27554

In [1]: xml = """<?xml version='1.0' encoding='utf-8'?>
   ...: <data>
   ...:  <row>
   ...:     <shape>square</shape>
   ...:     <degrees>360</degrees>
   ...:     <sides>4.0</sides>
   ...:  </row>
   ...:  <row>
   ...:     <shape>circle</shape>
   ...:     <degrees>360</degrees>
   ...:     <sides/>
   ...:  </row>
   ...:  <row>
   ...:     <shape>triangle</shape>
   ...:     <degrees>180</degrees>
   ...:     <sides>3.0</sides>
   ...:  </row>
   ...:  </data>"""

In [2]: df = pd.read_xml(xml)
In [3]: df
Out[3]:
      shape  degrees  sides
0    square      360    4.0
1    circle      360    NaN
2  triangle      180    3.0

In [4]: df.to_xml()
Out[4]:
<?xml version='1.0' encoding='utf-8'?>
<data>
  <row>
    <index>0</index>
    <shape>square</shape>
    <degrees>360</degrees>
    <sides>4.0</sides>
  </row>
  <row>
    <index>1</index>
    <shape>circle</shape>
    <degrees>360</degrees>
    <sides/>
  </row>
  <row>
    <index>2</index>
    <shape>triangle</shape>
    <degrees>180</degrees>
    <sides>3.0</sides>
  </row>
</data>

更多信息请参阅 IO 工具用户指南中的写入 XML

Styler 增强功能#

我们对 Styler 进行了一些重点开发。另请参阅已修订和改进的Styler 文档GH 39720GH 39317GH 40493)。

DataFrame 构造函数在 dict 参数中尊重 copy=False#

当将字典与 copy=False 一起传递给 DataFrame 时,将不再创建副本(GH 32960)。

In [1]: arr = np.array([1, 2, 3])

In [2]: df = pd.DataFrame({"A": arr, "B": arr.copy()}, copy=False)

In [3]: df
Out[3]: 
   A  B
0  1  1
1  2  2
2  3  3

df["A"] 仍然是 arr 的一个视图

In [4]: arr[0] = 0

In [5]: assert df.iloc[0, 0] == 0

不传递 copy 时的默认行为将保持不变,即会创建副本。

PyArrow 支持的字符串数据类型#

我们增强了 StringDtype,这是一种专用于字符串数据的扩展类型。(GH 39908

现在可以将 storage 关键字选项指定给 StringDtype。使用 pandas 选项或使用 dtype='string[pyarrow]' 指定 dtype,以允许 StringArray 由 PyArrow 数组而不是 Python 对象的 NumPy 数组支持。

PyArrow 支持的 StringArray 需要安装 pyarrow 1.0.0 或更高版本。

警告

string[pyarrow] 目前被认为是实验性的。其实现和部分 API 可能会在不发出警告的情况下更改。

In [6]: pd.Series(['abc', None, 'def'], dtype=pd.StringDtype(storage="pyarrow"))
Out[6]: 
0     abc
1    <NA>
2     def
dtype: string

你也可以使用别名 "string[pyarrow]"

In [7]: s = pd.Series(['abc', None, 'def'], dtype="string[pyarrow]")

In [8]: s
Out[8]: 
0     abc
1    <NA>
2     def
dtype: string

你也可以使用 pandas 选项创建 PyArrow 支持的字符串数组。

In [9]: with pd.option_context("string_storage", "pyarrow"):
   ...:     s = pd.Series(['abc', None, 'def'], dtype="string")
   ...: 

In [10]: s
Out[10]: 
0     abc
1    <NA>
2     def
dtype: string

常用的字符串访问器方法均可使用。在适当的情况下,Series 或 DataFrame 列的返回类型也将具有字符串 dtype。

In [11]: s.str.upper()
Out[11]: 
0     ABC
1    <NA>
2     DEF
dtype: string

In [12]: s.str.split('b', expand=True).dtypes
Out[12]: 
0    string[pyarrow]
1    string[pyarrow]
dtype: object

返回整数的字符串访问器方法将返回一个具有 Int64Dtype 的值

In [13]: s.str.count("a")
Out[13]: 
0       1
1    <NA>
2       0
dtype: Int64

居中时间日期型滚动窗口#

当对具有时间日期型索引的 DataFrame 和 Series 对象执行滚动计算时,现在可以使用居中时间日期型窗口(GH 38780)。例如:

In [14]: df = pd.DataFrame(
   ....:     {"A": [0, 1, 2, 3, 4]}, index=pd.date_range("2020", periods=5, freq="1D")
   ....: )
   ....: 

In [15]: df
Out[15]: 
            A
2020-01-01  0
2020-01-02  1
2020-01-03  2
2020-01-04  3
2020-01-05  4

In [16]: df.rolling("2D", center=True).mean()
Out[16]: 
              A
2020-01-01  0.5
2020-01-02  1.5
2020-01-03  2.5
2020-01-04  3.5
2020-01-05  4.0

其他功能增强#

值得注意的错误修复#

这些是可能导致显著行为更改的错误修复。

Categorical.unique 现在始终保持与原始数据相同的 dtype#

以前,当对分类数据调用 Categorical.unique() 时,新数组中未使用的类别会被删除,导致新数组的 dtype 与原始数组不同 (GH 18291)

例如,给定

In [17]: dtype = pd.CategoricalDtype(['bad', 'neutral', 'good'], ordered=True)

In [18]: cat = pd.Categorical(['good', 'good', 'bad', 'bad'], dtype=dtype)

In [19]: original = pd.Series(cat)

In [20]: unique = original.unique()

旧行为:

In [1]: unique
['good', 'bad']
Categories (2, object): ['bad' < 'good']
In [2]: original.dtype == unique.dtype
False

新行为:

In [21]: unique
Out[21]: 
['good', 'bad']
Categories (3, object): ['bad' < 'neutral' < 'good']

In [22]: original.dtype == unique.dtype
Out[22]: True

DataFrame.combine_first() 中保留 dtypes#

DataFrame.combine_first() 现在将保留 dtypes (GH 7509)

In [23]: df1 = pd.DataFrame({"A": [1, 2, 3], "B": [1, 2, 3]}, index=[0, 1, 2])

In [24]: df1
Out[24]: 
   A  B
0  1  1
1  2  2
2  3  3

In [25]: df2 = pd.DataFrame({"B": [4, 5, 6], "C": [1, 2, 3]}, index=[2, 3, 4])

In [26]: df2
Out[26]: 
   B  C
2  4  1
3  5  2
4  6  3

In [27]: combined = df1.combine_first(df2)

旧行为:

In [1]: combined.dtypes
Out[2]:
A    float64
B    float64
C    float64
dtype: object

新行为:

In [28]: combined.dtypes
Out[28]: 
A    float64
B      int64
C    float64
dtype: object

Groupby 方法 agg 和 transform 不再更改可调用对象的返回 dtype#

以前,当参数 func 是可调用对象时,方法 DataFrameGroupBy.aggregate()SeriesGroupBy.aggregate()DataFrameGroupBy.transform()SeriesGroupBy.transform() 可能会转换结果的 dtype,可能导致不理想的结果 (GH 21240)。当结果是数值类型且转换回输入 dtype 不改变任何值时(通过 np.allclose 测量),就会发生这种转换。现在不再发生这种转换。

In [29]: df = pd.DataFrame({'key': [1, 1], 'a': [True, False], 'b': [True, True]})

In [30]: df
Out[30]: 
   key      a     b
0    1   True  True
1    1  False  True

旧行为:

In [5]: df.groupby('key').agg(lambda x: x.sum())
Out[5]:
        a  b
key
1    True  2

新行为:

In [31]: df.groupby('key').agg(lambda x: x.sum())
Out[31]: 
     a  b
key      
1    1  2

DataFrameGroupBy.mean()DataFrameGroupBy.median()GDataFrameGroupBy.var()SeriesGroupBy.mean()SeriesGroupBy.median()SeriesGroupBy.var()float 结果#

以前,这些方法可能根据输入值的不同而产生不同的 dtype。现在,这些方法将始终返回 float dtype。 (GH 41137)

In [32]: df = pd.DataFrame({'a': [True], 'b': [1], 'c': [1.0]})

旧行为:

In [5]: df.groupby(df.index).mean()
Out[5]:
        a  b    c
0    True  1  1.0

新行为:

In [33]: df.groupby(df.index).mean()
Out[33]: 
     a    b    c
0  1.0  1.0  1.0

使用 lociloc 设置值时尝试就地操作#

当使用 lociloc 设置整个列时,pandas 将尝试将值插入到现有数据中,而不是创建一个全新的数组。

In [34]: df = pd.DataFrame(range(3), columns=["A"], dtype="float64")

In [35]: values = df.values

In [36]: new = np.array([5, 6, 7], dtype="int64")

In [37]: df.loc[[0, 1, 2], "A"] = new

在新旧行为中,values 中的数据都会被覆盖,但在旧行为中,df["A"] 的 dtype 变更为 int64

旧行为:

In [1]: df.dtypes
Out[1]:
A    int64
dtype: object
In [2]: np.shares_memory(df["A"].values, new)
Out[2]: False
In [3]: np.shares_memory(df["A"].values, values)
Out[3]: False

在 pandas 1.3.0 中,df 继续与 values 共享数据

新行为:

In [38]: df.dtypes
Out[38]: 
A    float64
dtype: object

In [39]: np.shares_memory(df["A"], new)
Out[39]: False

In [40]: np.shares_memory(df["A"], values)
Out[40]: True

设置 frame[keys] = values 时从不就地操作#

当使用 frame[keys] = values 设置多列时,新数组将替换这些键的预先存在的数组,而这些数组将 **不会** 被覆盖 (GH 39510)。结果是,列将保留 values 的 dtype(s),绝不会转换为现有数组的 dtypes。

In [41]: df = pd.DataFrame(range(3), columns=["A"], dtype="float64")

In [42]: df[["A"]] = 5

在旧行为中,5 被转换为 float64 并插入到支持 df 的现有数组中

旧行为:

In [1]: df.dtypes
Out[1]:
A    float64

在新行为中,我们得到一个新数组,并保留一个整数 dtype 的 5

新行为:

In [43]: df.dtypes
Out[43]: 
A    int64
dtype: object

在布尔 Series 中设置值时一致的类型转换#

现在将非布尔值设置到 dtype=boolSeries 中时,将始终转换为 dtype=object (GH 38709)

In [1]: orig = pd.Series([True, False])

In [2]: ser = orig.copy()

In [3]: ser.iloc[1] = np.nan

In [4]: ser2 = orig.copy()

In [5]: ser2.iloc[1] = 2.0

旧行为:

In [1]: ser
Out [1]:
0    1.0
1    NaN
dtype: float64

In [2]:ser2
Out [2]:
0    True
1     2.0
dtype: object

新行为:

In [1]: ser
Out [1]:
0    True
1     NaN
dtype: object

In [2]:ser2
Out [2]:
0    True
1     2.0
dtype: object

DataFrameGroupBy.rolling 和 SeriesGroupBy.rolling 不再在值中返回分组列#

现在,分组列将从 groupby.rolling 操作的结果中删除 (GH 32262)

In [44]: df = pd.DataFrame({"A": [1, 1, 2, 3], "B": [0, 1, 2, 3]})

In [45]: df
Out[45]: 
   A  B
0  1  0
1  1  1
2  2  2
3  3  3

旧行为:

In [1]: df.groupby("A").rolling(2).sum()
Out[1]:
       A    B
A
1 0  NaN  NaN
1    2.0  1.0
2 2  NaN  NaN
3 3  NaN  NaN

新行为:

In [46]: df.groupby("A").rolling(2).sum()
Out[46]: 
       B
A       
1 0  NaN
  1  1.0
2 2  NaN
3 3  NaN

移除了滚动方差和标准差中的人工截断#

Rolling.std()Rolling.var() 将不再人工截断小于 ~1e-8~1e-15 的结果为零 (GH 37051, GH 40448, GH 39872)。

然而,当在较大值上滚动时,结果中现在可能存在浮点数误差。

In [47]: s = pd.Series([7, 5, 5, 5])

In [48]: s.rolling(3).var()
Out[48]: 
0         NaN
1         NaN
2    1.333333
3    0.000000
dtype: float64

DataFrameGroupBy.rolling 和 SeriesGroupBy.rolling 与 MultiIndex 不再在结果中删除级别#

DataFrameGroupBy.rolling()SeriesGroupBy.rolling() 将不再删除结果中具有 MultiIndexDataFrame 的级别。这可能导致结果 MultiIndex 中级别重复的感知,但此更改恢复了 1.1.3 版本中的行为 (GH 38787, GH 38523)。

In [49]: index = pd.MultiIndex.from_tuples([('idx1', 'idx2')], names=['label1', 'label2'])

In [50]: df = pd.DataFrame({'a': [1], 'b': [2]}, index=index)

In [51]: df
Out[51]: 
               a  b
label1 label2      
idx1   idx2    1  2

旧行为:

In [1]: df.groupby('label1').rolling(1).sum()
Out[1]:
          a    b
label1
idx1    1.0  2.0

新行为:

In [52]: df.groupby('label1').rolling(1).sum()
Out[52]: 
                        a    b
label1 label1 label2          
idx1   idx1   idx2    1.0  2.0

向后不兼容的 API 更改#

增加了依赖项的最低版本#

某些依赖项的最低支持版本已更新。如果已安装,我们现在要求

最低版本

必需

已更改

numpy

1.17.3

X

X

pytz

2017.3

X

python-dateutil

2.7.3

X

bottleneck

1.2.1

numexpr

2.7.0

X

pytest (dev)

6.0

X

mypy (dev)

0.812

X

setuptools

38.6.0

X

对于可选库,一般建议使用最新版本。下表列出了 pandas 开发过程中当前测试的每个库的最低版本。低于最低测试版本的可选库可能仍然有效,但不被视为支持。

最低版本

已更改

beautifulsoup4

4.6.0

fastparquet

0.4.0

X

fsspec

0.7.4

gcsfs

0.6.0

lxml

4.3.0

matplotlib

2.2.3

numba

0.46.0

openpyxl

3.0.0

X

pyarrow

0.17.0

X

pymysql

0.8.1

X

pytables

3.5.1

s3fs

0.4.0

scipy

1.2.0

sqlalchemy

1.3.0

X

tabulate

0.8.7

X

xarray

0.12.0

xlrd

1.2.0

xlsxwriter

1.0.2

xlwt

1.3.0

pandas-gbq

0.12.0

有关更多信息,请参阅依赖项可选依赖项

其他 API 更改#

  • 部分初始化的 CategoricalDtype 对象(即那些 categories=None 的对象)将不再与完全初始化的 dtype 对象进行等值比较 (GH 38516)

  • 现在,访问 DataFrame 上的 _constructor_expanddimSeries 上的 _constructor_sliced 将引发 AttributeError。以前会引发 NotImplementedError (GH 38782)

  • DataFrame.to_sql() 添加了新的 engine**engine_kwargs 参数,以支持其他未来的“SQL 引擎”。目前我们仍然只在底层使用 SQLAlchemy,但计划支持更多引擎,例如 turbodbc (GH 36893)

  • PeriodIndex 字符串表示中移除了冗余的 freq (GH 41653)

  • ExtensionDtype.construct_array_type() 现在是 ExtensionDtype 子类的一个必需方法,而不是可选方法 (GH 24860)

  • 现在,对不可哈希的 pandas 对象调用 hash 将引发 TypeError,并附带内置错误消息(例如 unhashable type: 'Series')。以前会引发自定义消息,例如 'Series' objects are mutable, thus they cannot be hashed。此外,isinstance(<Series>, abc.collections.Hashable) 现在将返回 False (GH 40013)

  • Styler.from_custom_template() 现在有两个新的模板名称参数,并移除了旧的 name 参数,因为为了更好地解析,引入了模板继承 (GH 42053)。还需要对 Styler 属性进行子类化修改。

构建#

  • `.pptx` 和 `.pdf` 格式的文档不再包含在 wheels 或源发行版中。(GH 30741

弃用#

弃用了 DataFrame 缩减和 DataFrameGroupBy 操作中删除无用列的行为#

DataFrame 上调用缩减操作(例如 .min.max.sum),当 numeric_only=None(默认)时,缩减操作引发 TypeError 的列会被静默忽略并从结果中删除。

此行为已被弃用。在将来的版本中,将引发 TypeError,用户将需要在使用函数之前仅选择有效列。

例如

In [53]: df = pd.DataFrame({"A": [1, 2, 3, 4], "B": pd.date_range("2016-01-01", periods=4)})

In [54]: df
Out[54]: 
   A          B
0  1 2016-01-01
1  2 2016-01-02
2  3 2016-01-03
3  4 2016-01-04

旧行为:

In [3]: df.prod()
Out[3]:
Out[3]:
A    24
dtype: int64

未来行为:

In [4]: df.prod()
...
TypeError: 'DatetimeArray' does not implement reduction 'prod'

In [5]: df[["A"]].prod()
Out[5]:
A    24
dtype: int64

同样,当将函数应用于 DataFrameGroupBy 时,函数引发 TypeError 的列目前会被静默忽略并从结果中删除。

此行为已被弃用。在将来的版本中,将引发 TypeError,用户将需要在使用函数之前仅选择有效列。

例如

In [55]: df = pd.DataFrame({"A": [1, 2, 3, 4], "B": pd.date_range("2016-01-01", periods=4)})

In [56]: gb = df.groupby([1, 1, 2, 2])

旧行为:

In [4]: gb.prod(numeric_only=False)
Out[4]:
A
1   2
2  12

未来行为:

In [5]: gb.prod(numeric_only=False)
...
TypeError: datetime64 type does not support prod operations

In [6]: gb[["A"]].prod(numeric_only=False)
Out[6]:
    A
1   2
2  12

其他弃用#

性能改进#

Bug 修复#

分类#

  • CategoricalIndex 的 Bug,当传递标量数据时错误地未引发 `TypeError`(GH 38614

  • CategoricalIndex.reindex 的 Bug,当传入的 Index 不是分类类型但其值都是类别中的标签时,操作失败(GH 28690

  • 从 `date` 对象的 object-dtype 数组构造 Categorical 时,未能正确地与 `astype` 进行往返转换的 Bug(GH 38552

  • 从 `ndarray` 和 CategoricalDtype 构造 DataFrame 的 Bug(GH 38857

  • DataFrame 中将分类值设置到 object-dtype 列的 Bug(GH 39136

  • DataFrame.reindex() 的 Bug,当新索引包含重复项且旧索引为 CategoricalIndex 时,引发 `IndexError`(GH 38906

  • Categorical.fillna() 的 Bug,当使用非类别元组进行填充时,对于元组类别的处理,错误地引发 `NotImplementedError` 而非 `ValueError`(GH 41914

日期时间类#

时间差#

  • 从 `np.timedelta64` 对象构造 Timedelta 的 Bug,其中非纳秒单位超出 `timedelta64[ns]` 的范围(GH 38965

  • 构造 TimedeltaIndex 时错误地接受 `np.datetime64("NaT")` 对象的 Bug(GH 39462

  • 从仅包含符号而无数字的输入字符串构造 Timedelta 时未能引发错误的 Bug(GH 39710

  • TimedeltaIndexto_timedelta() 的 Bug,当传入的非纳秒 `timedelta64` 数组在转换为 `timedelta64[ns]` 时溢出,却未能引发错误(GH 40008

时区#

  • 不同的表示 UTC 的 `tzinfo` 对象未被视为等效的 Bug(GH 39216

  • dateutil.tz.gettz("UTC") 未被识别为与表示 UTC 的其他 tzinfo 等效的 Bug(GH 39276

数值#

转换#

  • Series.to_dict() 的 Bug,当 `orient='records'` 时,现在返回 Python 原生类型(GH 25969

  • Series.view()Index.view() 的 Bug,在日期时间类(`datetime64[ns]`、`datetime64[ns, tz]`、`timedelta64`、`period`)dtypes 之间进行转换时(GH 39788

  • 从空的 `np.recarray` 创建 DataFrame 时,未能保留原始 dtypes 的 Bug(GH 40121

  • 从 `frozenset` 构造 DataFrame 时,未能引发 `TypeError` 的 Bug(GH 40163

  • Index 构造中,当数据无法转换为传入的 `dtype` 时,默默地忽略该 `dtype` 的 Bug(GH 21311

  • StringArray.astype() 的 Bug,在转换为 `dtype='categorical'` 时,回退到 NumPy 并引发错误(GH 40450

  • factorize() 的 Bug,当给定一个数值 NumPy dtype 低于 int64、uint64 和 float64 的数组时,唯一值未能保留其原始 dtype(GH 41132

  • 用包含具有 `ExtensionDtype` 的类数组和 `copy=True` 的字典构造 DataFrame 时,未能创建副本的 Bug(GH 38939

  • qcut() 的 Bug,当以 `Float64DType` 作为输入时引发错误(GH 40730

  • 构造 DataFrameSeries 时,`datetime64[ns]` 数据和 `dtype=object` 导致结果为 `datetime` 对象而非 Timestamp 对象的 Bug(GH 41599

  • 构造 DataFrameSeries 时,`timedelta64[ns]` 数据和 `dtype=object` 导致结果为 `np.timedelta64` 对象而非 Timedelta 对象的 Bug(GH 41599

  • 构造 DataFrame 时,当给定一个包含 PeriodInterval 对象的二维 object-dtype `np.ndarray` 时,未能分别转换为 PeriodDtypeIntervalDtype 的 Bug(GH 41812

  • 从列表和 PandasDtype 构造 Series 的 Bug(GH 39357

  • 从不符合 `int64` dtype 范围的 `range` 对象创建 Series 的 Bug(GH 30173

  • 从具有全元组键和需要重新索引的 Index 的 `dict` 创建 Series 的 Bug(GH 41707

  • infer_dtype() 的 Bug,未能识别带有 Period dtype 的 Series、Index 或数组(GH 23553

  • infer_dtype() 的 Bug,对于一般的 ExtensionArray 对象会引发错误。现在将返回 `"unknown-array"` 而非引发错误(GH 37367

  • DataFrame.convert_dtypes() 的 Bug,在空 DataFrame 上调用时错误地引发了 `ValueError`(GH 40393

字符串#

区间#

  • IntervalIndex.intersection()IntervalIndex.symmetric_difference() 的 Bug,在与 CategoricalIndex 操作时总是返回 object-dtype(GH 38653, GH 38741

  • IntervalIndex.intersection() 的 Bug,当至少一个 Index 对象包含在另一个中存在的重复项时,返回重复项(GH 38743

  • IntervalIndex.union(), IntervalIndex.intersection(), IntervalIndex.difference()IntervalIndex.symmetric_difference() 现在,当与另一个具有不兼容 dtype 的 IntervalIndex 操作时,会转换为适当的 dtype 而不是引发 `TypeError`(GH 39267

  • PeriodIndex.union(), PeriodIndex.intersection(), PeriodIndex.symmetric_difference(), PeriodIndex.difference() 现在,当与另一个具有不兼容 dtype 的 PeriodIndex 操作时,会转换为 object dtype 而不是引发 `IncompatibleFrequency`(GH 39306

  • IntervalIndex.is_monotonic(), IntervalIndex.get_loc(), IntervalIndex.get_indexer_for()IntervalIndex.__contains__() 的 Bug,当存在 NA 值时(GH 41831

索引#

  • Index.union()MultiIndex.union() 的 Bug,当 Index 不是单调的或 `sort` 设置为 `False` 时,会丢弃重复的 Index 值(GH 36289, GH 31326, GH 40862

  • CategoricalIndex.get_indexer() 的 Bug,在非唯一时未能引发 `InvalidIndexError`(GH 38372

  • IntervalIndex.get_indexer() 的 Bug,当 `target` 具有 `CategoricalDtype` 且索引和目标都包含 NA 值时(GH 41934

  • Series.loc() 的 Bug,当输入使用布尔列表过滤且要设置的值是低维列表时,引发 `ValueError`(GH 20438

  • DataFrame 中插入许多新列导致后续索引行为不正确的 Bug(GH 38380

  • DataFrame.__setitem__() 的 Bug,当为重复列设置多个值时引发 `ValueError`(GH 15695

  • DataFrame.loc(), Series.loc(), DataFrame.__getitem__()Series.__getitem__() 的 Bug,对于字符串切片,当 DatetimeIndex 非单调时返回不正确的元素(GH 33146

  • DataFrame.reindex()Series.reindex() 的 Bug,带时区感知索引时,当 `method="ffill"` 和 `method="bfill"` 且指定 `tolerance` 时引发 `TypeError`(GH 38566

  • DataFrame.reindex() 的 Bug,当 `datetime64[ns]` 或 `timedelta64[ns]` 的 `fill_value` 需要转换为 object dtype 时,错误地转换为整数(GH 39755

  • DataFrame.__setitem__() 的 Bug,当使用指定列和非空 DataFrame 值设置空 DataFrame 时引发 `ValueError`(GH 38831

  • DataFrame.loc.__setitem__() 的 Bug,当 DataFrame 存在重复列时,对唯一列进行操作会引发 `ValueError`(GH 38521

  • DataFrame.iloc.__setitem__()DataFrame.loc.__setitem__() 的 Bug,当使用字典值进行设置时,对于混合 dtypes 的处理(GH 38335

  • Series.loc.__setitem__()DataFrame.loc.__setitem__() 的 Bug,当提供布尔生成器时引发 `KeyError`(GH 39614

  • Series.iloc()DataFrame.iloc() 的 Bug,当提供生成器时引发 `KeyError`(GH 39614

  • DataFrame.__setitem__() 的 Bug,当右侧是一个列数错误的 DataFrame 时,未引发 `ValueError`(GH 38604

  • Series.__setitem__() 的 Bug,当使用标量索引器设置 Series 时引发 `ValueError`(GH 38303

  • DataFrame.loc() 的 Bug,当作为输入的 DataFrame 只有一行时,会丢弃 MultiIndex 的级别(GH 10521

  • DataFrame.__getitem__()Series.__getitem__() 的 Bug,当使用具有毫秒的 Index 的现有字符串进行切片时,总是引发 `KeyError`(GH 33589

  • 在数值 Series 中设置 `timedelta64` 或 `datetime64` 值时,未能转换为 object dtype 的 Bug(GH 39086, GH 39619

  • SeriesDataFrame 中设置 Interval 值时,当 IntervalDtype 不匹配时,错误地将新值转换为现有 dtype 的 Bug(GH 39120

  • 在具有整数 dtype 的 Series 中设置 `datetime64` 值时,错误地将 `datetime64` 值转换为整数的 Bug(GH 39266

  • 在具有 Datetime64TZDtypeSeries 中设置 `np.datetime64("NaT")` 时,错误地将无时区的值视为有时区的值的 Bug(GH 39769

  • Index.get_loc() 的 Bug,当 `key=NaN` 且指定 `method` 但 `NaN` 不在 Index 中时,未引发 `KeyError`(GH 39382

  • DatetimeIndex.insert() 的 Bug,将 `np.datetime64("NaT")` 插入到时区感知索引时,错误地将无时区的值视为有时区的值(GH 39769

  • Index.insert() 中,当设置的新列无法保留在现有 `frame.columns` 中时,或在 Series.reset_index()DataFrame.reset_index() 中,错误地引发错误,而不是转换为兼容的 dtype 的 Bug(GH 39068

  • RangeIndex.append() 的 Bug,其中长度为 1 的单个对象被错误地连接(GH 39401

  • RangeIndex.astype() 的 Bug,当转换为 CategoricalIndex 时,类别变成了 Int64Index 而非 RangeIndexGH 41263

  • 使用布尔索引器将 `numpy.timedelta64` 值设置到 object-dtype Series 的 Bug(GH 39488

  • 使用 `at` 或 `iat` 将数值设置到布尔 dtype Series 时,未能转换为 object-dtype 的 Bug(GH 39582

  • DataFrame.__setitem__()DataFrame.iloc.__setitem__() 的 Bug,当尝试使用行切片进行索引并将列表设置为值时引发 `ValueError`(GH 40440

  • DataFrame.loc() 的 Bug,当在 MultiIndex 中未找到键且级别未完全指定时,未引发 `KeyError`(GH 41170

  • DataFrame.loc.__setitem__() 的 Bug,在扩展设置时,当扩展轴中的索引包含重复项时,错误地引发错误(GH 40096

  • 带有 MultiIndexDataFrame.loc.__getitem__() 的 Bug,当至少一个索引列具有 float dtype 且我们检索标量时转换为浮点数(GH 41369

  • DataFrame.loc() 的 Bug,错误地匹配非布尔索引元素(GH 20432

  • 在使用 `np.nan` 对具有 CategoricalIndexSeriesDataFrame 进行索引时,当存在 `np.nan` 键时,错误地引发 `KeyError` 的 Bug(GH 41933

  • Series.__delitem__() 的 Bug,当使用 `ExtensionDtype` 时错误地转换为 `ndarray`(GH 40386

  • 带有 CategoricalIndexDataFrame.at() 的 Bug,当传入整数键时返回不正确的结果(GH 41846

  • DataFrame.loc() 的 Bug,如果索引器包含重复项,则返回错误顺序的 MultiIndexGH 40978

  • DataFrame.__setitem__() 的 Bug,当使用 `str` 子类作为列名且 DatetimeIndex 时引发 `TypeError`(GH 37366

  • PeriodIndex.get_loc() 中存在一个错误,当给定一个 Period 对象且其 freq 不匹配时,未能抛出 KeyError (GH 41670)

  • 当使用 UInt64Index 和负整数键时,.loc.__getitem__ 存在一个错误,在某些情况下会抛出 OverflowError 而非 KeyError,在其他情况下则会回绕为正整数 (GH 41777)

  • Index.get_indexer() 中存在一个错误,在某些情况下,当给定无效的 methodlimittolerance 参数时,未能抛出 ValueError (GH 41918)

  • 在对具有 TimedeltaIndexSeriesDataFrame 进行切片时,传递无效字符串会抛出 ValueError 而非 TypeError 的错误 (GH 41821)

  • Index 构造函数中存在一个错误,有时会静默忽略指定的 dtype (GH 38879)

  • Index.where() 的行为现在与 Index.putmask() 的行为保持一致,即 index.where(mask, other) 匹配 index.putmask(~mask, other) (GH 39412)

缺失值#

多级索引#

  • DataFrame.drop() 中存在一个错误,当 MultiIndex 不唯一且未提供 level 时会抛出 TypeError (GH 36293)

  • MultiIndex.intersection() 中存在一个错误,导致结果中 NaN 重复 (GH 38623)

  • MultiIndex.equals() 中存在一个错误,当 MultiIndex 包含 NaN 时,即使它们的顺序不同,也会错误地返回 True (GH 38439)

  • MultiIndex.intersection() 中存在一个错误,与 CategoricalIndex 取交集时总是返回空结果 (GH 38653)

  • MultiIndex.difference() 中存在一个错误,当索引包含不可排序的条目时,错误地抛出 TypeError (GH 41915)

  • MultiIndex.reindex() 中存在一个错误,当在空的 MultiIndex 上使用且仅索引特定级别时,会抛出 ValueError (GH 41170)

  • MultiIndex.reindex() 中存在一个错误,当对齐扁平的 Index 时,会抛出 TypeError (GH 41707)

输入/输出#

  • Index.__repr__() 中存在一个错误,当 display.max_seq_items=1 时 (GH 38415)

  • read_csv() 中存在一个错误,当设置了 decimal 参数且 engine="python" 时,无法识别科学计数法 (GH 31920)

  • read_csv() 中存在一个错误,当 NA 值包含注释字符串时,将其解释为注释,现已针对 engine="python" 修复 (GH 34002)

  • read_csv() 中存在一个错误,当文件没有数据行时,如果指定了多个标题列和 index_col,会抛出 IndexError (GH 38292)

  • read_csv() 中存在一个错误,对于 engine="python",不接受 usecols 的长度与 names 不同 (GH 16469)

  • read_csv() 中存在一个错误,当 delimiter="," 且为 engine="python" 指定了 usecolsparse_dates 时,返回对象 dtype (GH 35873)

  • read_csv() 中存在一个错误,当为 engine="c" 指定了 namesparse_dates 时,会抛出 TypeError (GH 33699)

  • read_clipboard()DataFrame.to_clipboard() 中存在一个错误,在 WSL 中无法工作 (GH 38527)

  • 允许为 read_sql()read_sql_query()read_sql_table()parse_dates 参数设置自定义错误值 (GH 35185)

  • DataFrame.to_hdf()Series.to_hdf() 中存在一个错误,当尝试应用于 DataFrameSeries 的子类时,会抛出 KeyError (GH 33748)

  • HDFStore.put() 中存在一个错误,当保存具有非字符串 dtype 的 DataFrame 时,会抛出错误的 TypeError (GH 34274)

  • json_normalize() 中存在一个错误,导致生成器对象的第一个元素未包含在返回的 DataFrame 中 (GH 35923)

  • read_csv() 中存在一个错误,当列应解析为日期且为 engine="python" 指定了 usecols 时,会将千位分隔符应用于日期列 (GH 39365)

  • read_excel() 中存在一个错误,当指定多个标题和索引列时,会前向填充 MultiIndex 名称 (GH 34673)

  • read_excel() 中存在一个错误,不遵守 set_option() 的设置 (GH 34252)

  • read_csv() 中存在一个错误,对于可空布尔 dtype,不切换 true_valuesfalse_values (GH 34655)

  • read_json() 中存在一个错误,当 orient="split" 时不维护数字字符串索引 (GH 28556)

  • 如果 chunksize 不为零且查询没有返回结果,read_sql() 会返回一个空的生成器。现在它返回一个包含单个空 DataFrame 的生成器 (GH 34411)

  • read_hdf() 中存在一个错误,当使用 where 参数对分类字符串列进行过滤时,返回意外的记录 (GH 39189)

  • read_sas() 中存在一个错误,当 datetimes 为空时,会抛出 ValueError (GH 39725)

  • read_excel() 中存在一个错误,会从单列电子表格中删除空值 (GH 39808)

  • read_excel() 中存在一个错误,会加载某些文件类型的末尾空行/列 (GH 41167)

  • read_excel() 中存在一个错误,当 Excel 文件具有 MultiIndex 标题后跟两个空行且无索引时,会抛出 AttributeError (GH 40442)

  • read_excel()read_csv()read_table()read_fwf()read_clipboard() 中存在一个错误,即在 MultiIndex 标题后且无索引时,会删除一个空行 (GH 40442)

  • DataFrame.to_string() 中存在一个错误,当 index=False 时,截断列位置错误 (GH 40904)

  • DataFrame.to_string() 中存在一个错误,当 index=False 时,会额外添加一个点并使截断行未对齐 (GH 40904)

  • read_orc() 中存在一个错误,总是抛出 AttributeError (GH 40918)

  • read_csv()read_table() 中存在一个错误,如果同时定义了 namesprefix,会静默忽略 prefix,现在会抛出 ValueError (GH 39123)

  • read_csv()read_excel() 中存在一个错误,当 mangle_dupe_cols 设置为 True 时,不遵守重复列名的 dtype (GH 35211)

  • read_csv() 中存在一个错误,如果同时定义了 delimitersep,会静默忽略 sep,现在会抛出 ValueError (GH 39823)

  • read_csv()read_table() 中存在一个错误,当 sys.setprofile 之前被调用时,会错误地解释参数 (GH 41069)

  • 将 PyArrow 转换为 pandas(例如读取 Parquet)时存在一个错误,当具有可空 dtype 且 PyArrow 数组的数据缓冲区大小不是 dtype 大小的倍数时 (GH 40896)

  • read_excel() 中存在一个错误,即使用户指定了 engine 参数,当 pandas 无法确定文件类型时也会抛出错误 (GH 41225)

  • read_clipboard() 中存在一个错误,如果第一列中存在空值,从 Excel 文件复制会使值移到错误的列中 (GH 41108)

  • DataFrame.to_hdf()Series.to_hdf() 中存在一个错误,当尝试将字符串列附加到不兼容的列时,会抛出 TypeError (GH 41897)

周期#

  • Period 对象或 IndexSeriesDataFrame 与不匹配的 PeriodDtype 进行比较的行为现在与其他不匹配类型比较一致:对于相等性检查返回 False,对于不相等性检查返回 True,对于不等式检查抛出 TypeError (GH 39274)

绘图#

  • plotting.scatter_matrix() 中存在一个错误,当传递 2d ax 参数时会抛出错误 (GH 16253)

  • 防止 Matplotlib 的 constrained_layout 启用时出现警告 (GH 25261)

  • DataFrame.plot() 中存在一个错误,如果函数被重复调用,并且某些调用使用了 yerr 而其他调用没有使用,则图例中会显示错误的颜色 (GH 39522)

  • DataFrame.plot() 中存在一个错误,如果函数被重复调用,并且某些调用使用了 secondary_y 而其他调用使用了 legend=False,则图例中会显示错误的颜色 (GH 40044)

  • DataFrame.plot.box() 中存在一个错误,当选择了 dark_background 主题时,绘图的上限或最小/最大标记不可见 (GH 40769)

分组/重采样/滚动#

重塑#

稀疏#

  • DataFrame.sparse.to_coo() 中存在一个错误,当列是缺少 0 的数值 Index 时会引发 KeyError (GH 18414)

  • SparseArray.astype() 中存在一个错误,当 copy=False 且从整数 dtype 转换为浮点 dtype 时会产生不正确的结果 (GH 34456)

  • SparseArray.max()SparseArray.min() 中存在一个错误,总是返回空结果 (GH 40921)

扩展数组#

样式器#

  • Styler 中存在一个错误,其中方法的 subset 参数对于某些有效的 MultiIndex 切片会引发错误 (GH 33562)

  • Styler 渲染的 HTML 输出已进行细微修改,以支持 w3 良好代码标准 (GH 39626)

  • Styler 中存在一个错误,其中渲染的 HTML 在某些表头单元格中缺少列类标识符 (GH 39716)

  • Styler.background_gradient() 中存在一个错误,其中文本颜色未正确确定 (GH 39888)

  • Styler.set_table_styles() 中存在一个错误,其中 table_styles 参数的 CSS 选择器中的多个元素未正确添加 (GH 34061)

  • Styler 中存在一个错误,从 Jupyter 复制时会丢失左上角单元格并导致表头错位 (GH 12147)

  • Styler.where 中存在一个错误,其中 kwargs 未传递给适用的可调用对象 (GH 40845)

  • Styler 中存在一个错误,导致 CSS 在多次渲染时重复 (GH 39395, GH 40334)

其他#

贡献者#

共有 251 人为本次发布贡献了补丁。名字旁边带有“+”的人是首次贡献补丁。

  • Abhishek R +

  • Ada Draginda

  • Adam J. Stewart

  • Adam Turner +

  • Aidan Feldman +

  • Ajitesh Singh +

  • Akshat Jain +

  • Albert Villanova del Moral

  • Alexandre Prince-Levasseur +

  • Andrew Hawyrluk +

  • Andrew Wieteska

  • AnglinaBhambra +

  • Ankush Dua +

  • Anna Daglis

  • Ashlan Parker +

  • Ashwani +

  • Avinash Pancham

  • Ayushman Kumar +

  • BeanNan

  • Benoît Vinot

  • Bharat Raghunathan

  • Bijay Regmi +

  • Bobin Mathew +

  • Bogdan Pilyavets +

  • Brian Hulette +

  • Brian Sun +

  • Brock +

  • Bryan Cutler

  • Caleb +

  • Calvin Ho +

  • Chathura Widanage +

  • Chinmay Rane +

  • Chris Lynch

  • Chris Withers

  • Christos Petropoulos

  • Corentin Girard +

  • DaPy15 +

  • Damodara Puddu +

  • Daniel Hrisca

  • Daniel Saxton

  • DanielFEvans

  • Dare Adewumi +

  • Dave Willmer

  • David Schlachter +

  • David-dmh +

  • Deepang Raval +

  • Doris Lee +

  • Dr. Jan-Philip Gehrcke +

  • DriesS +

  • Dylan Percy

  • Erfan Nariman

  • Eric Leung

  • EricLeer +

  • Eve

  • Fangchen Li

  • Felix Divo

  • Florian Jetter

  • Fred Reiss

  • GFJ138 +

  • Gaurav Sheni +

  • Geoffrey B. Eisenbarth +

  • Gesa Stupperich +

  • Griffin Ansel +

  • Gustavo C. Maciel +

  • Heidi +

  • Henry +

  • Hung-Yi Wu +

  • Ian Ozsvald +

  • Irv Lustig

  • Isaac Chung +

  • Isaac Virshup

  • JHM Darbyshire (MBP) +

  • JHM Darbyshire (iMac) +

  • Jack Liu +

  • James Lamb +

  • Jeet Parekh

  • Jeff Reback

  • Jiezheng2018 +

  • Jody Klymak

  • Johan Kåhrström +

  • John McGuigan

  • Joris Van den Bossche

  • Jose

  • JoseNavy

  • Josh Dimarsky

  • Josh Friedlander

  • Joshua Klein +

  • Julia Signell

  • Julian Schnitzler +

  • Kaiqi Dong

  • Kasim Panjri +

  • Katie Smith +

  • Kelly +

  • Kenil +

  • Keppler, Kyle +

  • Kevin Sheppard

  • Khor Chean Wei +

  • Kiley Hewitt +

  • Larry Wong +

  • Lightyears +

  • Lucas Holtz +

  • Lucas Rodés-Guirao

  • Lucky Sivagurunathan +

  • Luis Pinto

  • Maciej Kos +

  • Marc Garcia

  • Marco Edward Gorelli +

  • Marco Gorelli

  • MarcoGorelli +

  • Mark Graham

  • Martin Dengler +

  • Martin Grigorov +

  • Marty Rudolf +

  • Matt Roeschke

  • Matthew Roeschke

  • Matthew Zeitlin

  • Max Bolingbroke

  • Maxim Ivanov

  • Maxim Kupfer +

  • Mayur +

  • MeeseeksMachine

  • Micael Jarniac

  • Michael Hsieh +

  • Michel de Ruiter +

  • Mike Roberts +

  • Miroslav Šedivý

  • Mohammad Jafar Mashhadi

  • Morisa Manzella +

  • Mortada Mehyar

  • Muktan +

  • Naveen Agrawal +

  • Noah

  • Nofar Mishraki +

  • Oleh Kozynets

  • Olga Matoula +

  • Oli +

  • Omar Afifi

  • Omer Ozarslan +

  • Owen Lamont +

  • Ozan Öğreden +

  • Pandas Development Team

  • Paolo Lammens

  • Parfait Gasana +

  • Patrick Hoefler

  • Paul McCarthy +

  • Paulo S. Costa +

  • Pav A

  • Peter

  • Pradyumna Rahul +

  • Punitvara +

  • QP Hou +

  • Rahul Chauhan

  • Rahul Sathanapalli

  • Richard Shadrach

  • Robert Bradshaw

  • Robin to Roxel

  • Rohit Gupta

  • Sam Purkis +

  • Samuel GIFFARD +

  • Sean M. Law +

  • Shahar Naveh +

  • ShaharNaveh +

  • Shiv Gupta +

  • Shrey Dixit +

  • Shudong Yang +

  • Simon Boehm +

  • Simon Hawkins

  • Sioned Baker +

  • Stefan Mejlgaard +

  • Steven Pitman +

  • Steven Schaerer +

  • Stéphane Guillou +

  • TLouf +

  • Tegar D Pratama +

  • Terji Petersen

  • Theodoros Nikolaou +

  • Thomas Dickson

  • Thomas Li

  • Thomas Smith

  • Thomas Yu +

  • ThomasBlauthQC +

  • Tim Hoffmann

  • Tom Augspurger

  • Torsten Wörtwein

  • Tyler Reddy

  • UrielMaD

  • Uwe L. Korn

  • Venaturum +

  • VirosaLi

  • Vladimir Podolskiy

  • Vyom Pathak +

  • WANG Aiyong

  • Waltteri Koskinen +

  • Wenjun Si +

  • William Ayd

  • Yeshwanth N +

  • Yuanhao Geng

  • Zito Relova +

  • aflah02 +

  • arredond +

  • attack68

  • cdknox +

  • chinggg +

  • fathomer +

  • ftrihardjo +

  • github-actions[bot] +

  • gunjan-solanki +

  • guru kiran

  • hasan-yaman

  • i-aki-y +

  • jbrockmendel

  • jmholzer +

  • jordi-crespo +

  • jotasi +

  • jreback

  • juliansmidek +

  • kylekeppler

  • lrepiton +

  • lucasrodes

  • maroth96 +

  • mikeronayne +

  • mlondschien

  • moink +

  • morrme

  • mschmookler +

  • mzeitlin11

  • na2 +

  • nofarmishraki +

  • partev

  • patrick

  • ptype

  • realead

  • rhshadrach

  • rlukevie +

  • rosagold +

  • saucoide +

  • sdementen +

  • shawnbrown

  • sstiijn +

  • stphnlyd +

  • sukriti1 +

  • taytzehao

  • theOehrly +

  • theodorju +

  • thordisstella +

  • tonyyyyip +

  • tsinggggg +

  • tushushu +

  • vangorade +

  • vladu +

  • wertha +