1.1.0 版本更新 (2020 年 7 月 28 日)#

這是 pandas 1.1.0 版本中的更改。請參閱 釋出說明 以獲取包含其他 pandas 版本的完整變更日誌。

增強功能#

loc 引發的 KeyError 會指明丟失的標籤#

以前,如果在 `.loc` 呼叫中丟失了標籤,會引發一個 KeyError,指出這已不再受支援。

現在,錯誤訊息還包含一個丟失標籤的列表(最多 10 項,顯示寬度 80 個字元)。請參閱 GH 34272

所有 dtype 現在都可以轉換為 StringDtype#

以前,通常只有當資料已經是 str 或類似 nan 的值時,才能宣告或轉換為 StringDtypeGH 31204)。StringDtype 現在在 astype(str)dtype=str 生效的所有情況下都有效。

例如,以下程式碼現在可以正常工作

In [1]: ser = pd.Series([1, "abc", np.nan], dtype="string")

In [2]: ser
Out[2]: 
0       1
1     abc
2    <NA>
dtype: string

In [3]: ser[0]
Out[3]: '1'

In [4]: pd.Series([1, 2, np.nan], dtype="Int64").astype("string")
Out[4]: 
0       1
1       2
2    <NA>
dtype: string

非單調的 PeriodIndex 部分字串切片#

PeriodIndex 現在支援對非單調索引進行部分字串切片,與 DatetimeIndex 的行為相呼應(GH 31096

例如:

In [5]: dti = pd.date_range("2014-01-01", periods=30, freq="30D")

In [6]: pi = dti.to_period("D")

In [7]: ser_monotonic = pd.Series(np.arange(30), index=pi)

In [8]: shuffler = list(range(0, 30, 2)) + list(range(1, 31, 2))

In [9]: ser = ser_monotonic.iloc[shuffler]

In [10]: ser
Out[10]: 
2014-01-01     0
2014-03-02     2
2014-05-01     4
2014-06-30     6
2014-08-29     8
              ..
2015-09-23    21
2015-11-22    23
2016-01-21    25
2016-03-21    27
2016-05-20    29
Freq: D, Length: 30, dtype: int64
In [11]: ser["2014"]
Out[11]: 
2014-01-01     0
2014-03-02     2
2014-05-01     4
2014-06-30     6
2014-08-29     8
2014-10-28    10
2014-12-27    12
2014-01-31     1
2014-04-01     3
2014-05-31     5
2014-07-30     7
2014-09-28     9
2014-11-27    11
Freq: D, dtype: int64

In [12]: ser.loc["May 2015"]
Out[12]: 
2015-05-26    17
Freq: D, dtype: int64

比較兩個 DataFrame 或兩個 Series 並總結差異#

我們添加了 DataFrame.compare()Series.compare(),用於比較兩個 DataFrame 或兩個 SeriesGH 30429

In [13]: df = pd.DataFrame(
   ....:     {
   ....:         "col1": ["a", "a", "b", "b", "a"],
   ....:         "col2": [1.0, 2.0, 3.0, np.nan, 5.0],
   ....:         "col3": [1.0, 2.0, 3.0, 4.0, 5.0]
   ....:     },
   ....:     columns=["col1", "col2", "col3"],
   ....: )
   ....: 

In [14]: df
Out[14]: 
  col1  col2  col3
0    a   1.0   1.0
1    a   2.0   2.0
2    b   3.0   3.0
3    b   NaN   4.0
4    a   5.0   5.0
In [15]: df2 = df.copy()

In [16]: df2.loc[0, 'col1'] = 'c'

In [17]: df2.loc[2, 'col3'] = 4.0

In [18]: df2
Out[18]: 
  col1  col2  col3
0    c   1.0   1.0
1    a   2.0   2.0
2    b   3.0   4.0
3    b   NaN   4.0
4    a   5.0   5.0
In [19]: df.compare(df2)
Out[19]: 
  col1       col3      
  self other self other
0    a     c  NaN   NaN
2  NaN   NaN  3.0   4.0

有關更多詳細資訊,請參閱 使用者指南

允許 groupby 鍵中存在 NA#

groupby 中,我們向 DataFrame.groupby()Series.groupby() 添加了一個 dropna 關鍵字引數,以允許在組鍵中使用 NA 值。如果使用者希望在 groupby 鍵中包含 NA 值,可以將 dropna 設定為 False。為保持向後相容性,dropna 的預設值設定為 TrueGH 3729)。

In [20]: df_list = [[1, 2, 3], [1, None, 4], [2, 1, 3], [1, 2, 2]]

In [21]: df_dropna = pd.DataFrame(df_list, columns=["a", "b", "c"])

In [22]: df_dropna
Out[22]: 
   a    b  c
0  1  2.0  3
1  1  NaN  4
2  2  1.0  3
3  1  2.0  2
# Default ``dropna`` is set to True, which will exclude NaNs in keys
In [23]: df_dropna.groupby(by=["b"], dropna=True).sum()
Out[23]: 
     a  c
b        
1.0  2  3
2.0  2  5

# In order to allow NaN in keys, set ``dropna`` to False
In [24]: df_dropna.groupby(by=["b"], dropna=False).sum()
Out[24]: 
     a  c
b        
1.0  2  3
2.0  2  5
NaN  1  4

dropna 引數的預設設定為 True,這意味著 NA 值不包含在組鍵中。

使用鍵進行排序#

我們在 DataFrameSeries 的排序方法中添加了一個 key 引數,包括 DataFrame.sort_values()DataFrame.sort_index()Series.sort_values()Series.sort_index()。在執行排序之前,key 可以是任何可呼叫函式,它將逐列應用於用於排序的每一列(GH 27237)。有關更多資訊,請參閱 使用鍵進行 sort_values使用鍵進行 sort_index

In [25]: s = pd.Series(['C', 'a', 'B'])

In [26]: s
Out[26]: 
0    C
1    a
2    B
dtype: str
In [27]: s.sort_values()
Out[27]: 
2    B
0    C
1    a
dtype: str

注意這裡是大寫字母在前排序。如果我們應用 Series.str.lower() 方法,我們會得到

In [28]: s.sort_values(key=lambda x: x.str.lower())
Out[28]: 
1    a
2    B
0    C
dtype: str

當應用於 DataFrame 時,鍵會按列應用於所有列,或者如果指定了 by,則應用於部分列,例如:

In [29]: df = pd.DataFrame({'a': ['C', 'C', 'a', 'a', 'B', 'B'],
   ....:                    'b': [1, 2, 3, 4, 5, 6]})
   ....: 

In [30]: df
Out[30]: 
   a  b
0  C  1
1  C  2
2  a  3
3  a  4
4  B  5
5  B  6
In [31]: df.sort_values(by=['a'], key=lambda col: col.str.lower())
Out[31]: 
   a  b
2  a  3
3  a  4
4  B  5
5  B  6
0  C  1
1  C  2

有關更多詳細資訊,請參閱 DataFrame.sort_values()Series.sort_values()sort_index() 中的示例和文件。

Timestamp 建構函式中支援 fold 引數#

Timestamp: 現在支援與父類 datetime.datetime 類似的 PEP 495 中定義的 keyword-only fold 引數。它支援接受 fold 作為初始化引數,並從其他建構函式引數推斷 fold(GH 25057GH 31338)。支援僅限於 dateutil 時區,因為 pytz 不支援 fold。

例如:

In [32]: ts = pd.Timestamp("2019-10-27 01:30:00+00:00")

In [33]: ts.fold
Out[33]: 0
In [34]: ts = pd.Timestamp(year=2019, month=10, day=27, hour=1, minute=30,
   ....:                   tz="dateutil/Europe/London", fold=1)
   ....: 

In [35]: ts
Out[35]: Timestamp('2019-10-27 01:30:00+0000', tz='dateutil//usr/share/zoneinfo/Europe/London')

有關 fold 的更多資訊,請參閱使用者指南中的 Fold 小節

在 to_datetime 中解析包含不同時區的時區感知格式#

to_datetime() 現在支援解析包含時區名稱(%Z)和 UTC 偏移量(%z)的格式,這些格式來自與設定為 utc=True 的 UTC 不同的時區,然後將它們轉換為 UTC。這將返回一個在 UTC 時區的 DatetimeIndex,而不是一個 object dtype 的 Index,如果 utc=True 未設定(GH 32792)。

例如:

In [36]: tz_strs = ["2010-01-01 12:00:00 +0100", "2010-01-01 12:00:00 -0100",
   ....:            "2010-01-01 12:00:00 +0300", "2010-01-01 12:00:00 +0400"]
   ....: 

In [37]: pd.to_datetime(tz_strs, format='%Y-%m-%d %H:%M:%S %z', utc=True)
Out[37]: 
DatetimeIndex(['2010-01-01 11:00:00+00:00', '2010-01-01 13:00:00+00:00',
               '2010-01-01 09:00:00+00:00', '2010-01-01 08:00:00+00:00'],
              dtype='datetime64[us, UTC]', freq=None)
In[37]: pd.to_datetime(tz_strs, format='%Y-%m-%d %H:%M:%S %z')
Out[37]:
Index([2010-01-01 12:00:00+01:00, 2010-01-01 12:00:00-01:00,
       2010-01-01 12:00:00+03:00, 2010-01-01 12:00:00+04:00],
      dtype='object')

Grouper 和 resample 現在支援 origin 和 offset 引數#

GrouperDataFrame.resample() 現在支援 originoffset 引數。這允許使用者控制用於調整分組的時間戳。(GH 31809

分組的 bin 是根據時間序列起始點那一天的開始時間進行調整的。這對於頻率是日倍數(如 30D)或能整除一日(如 90s1min)的情況效果很好。但是,對於某些不滿足此條件的頻率,可能會出現不一致。要更改此行為,您現在可以使用 origin 引數指定一個固定的時間戳。

現在有兩個引數已被棄用(更多資訊請參見 DataFrame.resample() 的文件)

  • base 應被替換為 offset

  • loffset 應透過在重取樣後直接將一個 offset 新增到 DataFrame 的索引來替換。

使用 origin 的小示例

In [38]: start, end = '2000-10-01 23:30:00', '2000-10-02 00:30:00'

In [39]: middle = '2000-10-02 00:00:00'

In [40]: rng = pd.date_range(start, end, freq='7min')

In [41]: ts = pd.Series(np.arange(len(rng)) * 3, index=rng)

In [42]: ts
Out[42]: 
2000-10-01 23:30:00     0
2000-10-01 23:37:00     3
2000-10-01 23:44:00     6
2000-10-01 23:51:00     9
2000-10-01 23:58:00    12
2000-10-02 00:05:00    15
2000-10-02 00:12:00    18
2000-10-02 00:19:00    21
2000-10-02 00:26:00    24
Freq: 7min, dtype: int64

使用預設行為 'start_day' 進行重取樣(origin 是 2000-10-01 00:00:00

In [43]: ts.resample('17min').sum()
Out[43]: 
2000-10-01 23:14:00     0
2000-10-01 23:31:00     9
2000-10-01 23:48:00    21
2000-10-02 00:05:00    54
2000-10-02 00:22:00    24
Freq: 17min, dtype: int64

In [44]: ts.resample('17min', origin='start_day').sum()
Out[44]: 
2000-10-01 23:14:00     0
2000-10-01 23:31:00     9
2000-10-01 23:48:00    21
2000-10-02 00:05:00    54
2000-10-02 00:22:00    24
Freq: 17min, dtype: int64

使用固定 origin 進行重取樣

In [45]: ts.resample('17min', origin='epoch').sum()
Out[45]: 
2000-10-01 23:18:00     0
2000-10-01 23:35:00    18
2000-10-01 23:52:00    27
2000-10-02 00:09:00    39
2000-10-02 00:26:00    24
Freq: 17min, dtype: int64

In [46]: ts.resample('17min', origin='2000-01-01').sum()
Out[46]: 
2000-10-01 23:24:00     3
2000-10-01 23:41:00    15
2000-10-01 23:58:00    45
2000-10-02 00:15:00    45
Freq: 17min, dtype: int64

如果需要,您可以使用 offset 引數(一個 Timedelta)來調整 bin,該引數將加到預設的 origin 上。

完整的示例請參見:使用 origin 或 offset 調整 bin 的開始時間

現在使用 fsspec 進行檔案系統處理#

對於讀取和寫入本地以外的檔案系統以及從 HTTP(S) 讀取,將使用可選依賴項 fsspec 來分派操作(GH 33452)。這將使 S3 和 GCS 儲存(已經支援)的功能保持不變,同時還增加了對其他幾種儲存實現的支援,例如 Azure Datalake 和 Blob、SSH、FTP、dropbox 和 github。有關文件和功能,請參閱 fsspec 文件

與 S3 和 GCS 介面的現有功能在此更改中不受影響,因為 fsspec 仍將引入與之前相同的包。

其他增強功能#

重要的 bug 修復#

這些 bug 修復可能帶來行為上的顯著變化。

MultiIndex.get_indexer 正確解釋了 method 引數(#)。

這恢復了 MultiIndex.get_indexer()method='backfill'method='pad' 下的行為,使其與 pandas 0.23.0 之前的行為一致。特別是,MultiIndexes 被視為元組列表,並且填充或回填是相對於這些元組列表的順序進行的(GH 29896)。

以此為例,給定

In [47]: df = pd.DataFrame({
   ....:     'a': [0, 0, 0, 0],
   ....:     'b': [0, 2, 3, 4],
   ....:     'c': ['A', 'B', 'C', 'D'],
   ....: }).set_index(['a', 'b'])
   ....: 

In [48]: mi_2 = pd.MultiIndex.from_product([[0], [-1, 0, 1, 3, 4, 5]])

使用 mi_2df 進行重索引並使用 method='backfill' 的差異可以在這裡看到:

pandas >= 0.23, < 1.1.0:

In [1]: df.reindex(mi_2, method='backfill')
Out[1]:
      c
0 -1  A
   0  A
   1  D
   3  A
   4  A
   5  C

pandas <0.23, >= 1.1.0

In [49]: df.reindex(mi_2, method='backfill')
Out[49]: 
        c
0 -1    A
   0    A
   1    B
   3    C
   4    D
   5  NaN

以及使用 method='pad'df 進行重索引並使用 mi_2 的差異可以在這裡看到:

pandas >= 0.23, < 1.1.0

In [1]: df.reindex(mi_2, method='pad')
Out[1]:
        c
0 -1  NaN
   0  NaN
   1    D
   3  NaN
   4    A
   5    C

pandas < 0.23, >= 1.1.0

In [50]: df.reindex(mi_2, method='pad')
Out[50]: 
        c
0 -1  NaN
   0    A
   1    A
   3    C
   4    D
   5    D

失敗的基於標籤的查詢始終引發 KeyError(#)。

以前,series[key]series.loc[key]frame.loc[key] 的標籤查詢會根據 key 的型別和 Index 的型別引發 KeyErrorTypeError。現在它們一致地引發 KeyErrorGH 31867)。

In [51]: ser1 = pd.Series(range(3), index=[0, 1, 2])

In [52]: ser2 = pd.Series(range(3), index=pd.date_range("2020-02-01", periods=3))

先前行為:

In [3]: ser1[1.5]
...
TypeError: cannot do label indexing on Int64Index with these indexers [1.5] of type float

In [4] ser1["foo"]
...
KeyError: 'foo'

In [5]: ser1.loc[1.5]
...
TypeError: cannot do label indexing on Int64Index with these indexers [1.5] of type float

In [6]: ser1.loc["foo"]
...
KeyError: 'foo'

In [7]: ser2.loc[1]
...
TypeError: cannot do label indexing on DatetimeIndex with these indexers [1] of type int

In [8]: ser2.loc[pd.Timestamp(0)]
...
KeyError: Timestamp('1970-01-01 00:00:00')

新行為:

In [3]: ser1[1.5]
...
KeyError: 1.5

In [4] ser1["foo"]
...
KeyError: 'foo'

In [5]: ser1.loc[1.5]
...
KeyError: 1.5

In [6]: ser1.loc["foo"]
...
KeyError: 'foo'

In [7]: ser2.loc[1]
...
KeyError: 1

In [8]: ser2.loc[pd.Timestamp(0)]
...
KeyError: Timestamp('1970-01-01 00:00:00')

類似地,如果傳遞了不相容的 key,DataFrame.at()Series.at() 將引發 TypeError 而不是 ValueError;如果傳遞了缺失的 key,將引發 KeyError,這與 .loc[] 的行為一致(GH 31722)。

MultiIndex 上的失敗整數查詢引發 KeyError(#)。

MultiIndex 的第一個級別是整數 dtype 時,使用整數進行索引,如果其中一個或多個整數 key 在索引的第一個級別中不存在,則錯誤地未能引發 KeyErrorGH 33539)。

In [53]: idx = pd.Index(range(4))

In [54]: dti = pd.date_range("2000-01-03", periods=3)

In [55]: mi = pd.MultiIndex.from_product([idx, dti])

In [56]: ser = pd.Series(range(len(mi)), index=mi)

先前行為:

In [5]: ser[[5]]
Out[5]: Series([], dtype: int64)

新行為:

In [5]: ser[[5]]
...
KeyError: '[5] not in index'

DataFrame.merge() 保留右側 DataFrame 的行順序(#)。

DataFrame.merge() 在執行右合併時現在保留右側 DataFrame 的行順序(GH 27453)。

In [57]: left_df = pd.DataFrame({'animal': ['dog', 'pig'],
   ....:                        'max_speed': [40, 11]})
   ....: 

In [58]: right_df = pd.DataFrame({'animal': ['quetzal', 'pig'],
   ....:                         'max_speed': [80, 11]})
   ....: 

In [59]: left_df
Out[59]: 
  animal  max_speed
0    dog         40
1    pig         11

In [60]: right_df
Out[60]: 
    animal  max_speed
0  quetzal         80
1      pig         11

先前行為:

>>> left_df.merge(right_df, on=['animal', 'max_speed'], how="right")
    animal  max_speed
0      pig         11
1  quetzal         80

新行為:

In [61]: left_df.merge(right_df, on=['animal', 'max_speed'], how="right")
Out[61]: 
    animal  max_speed
0  quetzal         80
1      pig         11

當 DataFrame 的某些列不存在時,向多個列進行賦值(#)。

當 DataFrame 的某些列不存在時,向多個列進行賦值,以前會將值分配給最後一列。現在,將使用正確的值構建新列。(GH 13658)。

In [62]: df = pd.DataFrame({'a': [0, 1, 2], 'b': [3, 4, 5]})

In [63]: df
Out[63]: 
   a  b
0  0  3
1  1  4
2  2  5

先前行為:

In [3]: df[['a', 'c']] = 1
In [4]: df
Out[4]:
   a  b
0  1  1
1  1  1
2  1  1

新行為:

In [64]: df[['a', 'c']] = 1

In [65]: df
Out[65]: 
   a  b  c
0  1  3  1
1  1  4  1
2  1  5  1

groupby 聚合的一致性(#)。

DataFrame.groupby()as_index=True 和聚合函式 nunique 一起使用時,會將分組列包含在結果的列中。現在,分組列僅出現在索引中,與其他聚合函式一致。(GH 32579)。

In [66]: df = pd.DataFrame({"a": ["x", "x", "y", "y"], "b": [1, 1, 2, 3]})

In [67]: df
Out[67]: 
   a  b
0  x  1
1  x  1
2  y  2
3  y  3

先前行為:

In [3]: df.groupby("a", as_index=True).nunique()
Out[4]:
   a  b
a
x  1  1
y  1  2

新行為:

In [68]: df.groupby("a", as_index=True).nunique()
Out[68]: 
   b
a   
x  1
y  2

DataFrame.groupby()as_index=False 和函式 idxmaxidxminmadnuniquesemskewstd 一起使用時,會修改分組列。現在,分組列保持不變,與其他聚合函式一致。(GH 21090, GH 10355)。

先前行為:

In [3]: df.groupby("a", as_index=False).nunique()
Out[4]:
   a  b
0  1  1
1  1  2

新行為:

In [69]: df.groupby("a", as_index=False).nunique()
Out[69]: 
   a  b
0  x  1
1  y  2

方法 DataFrameGroupBy.size() 以前會忽略 as_index=False。現在,分組列將作為列返回,使結果成為 DataFrame 而不是 Series。(GH 32599)。

先前行為:

In [3]: df.groupby("a", as_index=False).size()
Out[4]:
a
x    2
y    2
dtype: int64

新行為:

In [70]: df.groupby("a", as_index=False).size()
Out[70]: 
   a  size
0  x     2
1  y     2

當重新命名列時,DataFrameGroupby.agg()as_index=False 時丟失了結果(#)。

以前,當 as_index 選項設定為 False 並且結果列被重新命名時,DataFrameGroupby.agg() 會丟失結果列。在這種情況下,結果值會被之前的索引替換(GH 32240)。

In [71]: df = pd.DataFrame({"key": ["x", "y", "z", "x", "y", "z"],
   ....:                    "val": [1.0, 0.8, 2.0, 3.0, 3.6, 0.75]})
   ....: 

In [72]: df
Out[72]: 
  key   val
0   x  1.00
1   y  0.80
2   z  2.00
3   x  3.00
4   y  3.60
5   z  0.75

先前行為:

In [2]: grouped = df.groupby("key", as_index=False)
In [3]: result = grouped.agg(min_val=pd.NamedAgg(column="val", aggfunc="min"))
In [4]: result
Out[4]:
     min_val
 0   x
 1   y
 2   z

新行為:

In [73]: grouped = df.groupby("key", as_index=False)

In [74]: result = grouped.agg(min_val=pd.NamedAgg(column="val", aggfunc="min"))

In [75]: result
Out[75]: 
  key  min_val
0   x     1.00
1   y     0.80
2   z     0.75

DataFrame 上的 apply 和 applymap 只會計算第一行/列一次(#)。

In [76]: df = pd.DataFrame({'a': [1, 2], 'b': [3, 6]})

In [77]: def func(row):
   ....:     print(row)
   ....:     return row
   ....: 

先前行為:

In [4]: df.apply(func, axis=1)
a    1
b    3
Name: 0, dtype: int64
a    1
b    3
Name: 0, dtype: int64
a    2
b    6
Name: 1, dtype: int64
Out[4]:
   a  b
0  1  3
1  2  6

新行為:

In [78]: df.apply(func, axis=1)
a    1
b    3
Name: 0, dtype: int64
a    2
b    6
Name: 1, dtype: int64
Out[78]: 
   a  b
0  1  3
1  2  6

向後不相容的 API 更改#

testing.assert_frame_equaltesting.assert_series_equal 添加了 check_freq 引數(#)。

在 pandas 1.1.0 中,將 check_freq 引數新增到了 testing.assert_frame_equal()testing.assert_series_equal() 中,並預設為 True。現在,如果索引的頻率不相同,testing.assert_frame_equal()testing.assert_series_equal() 將引發 AssertionError。在 pandas 1.1.0 之前,不檢查索引頻率。

提高了依賴項的最低版本#

更新了一些依賴項的最低支援版本(GH 33718, GH 29766, GH 29723, pytables >= 3.4.3)。如果已安裝,我們現在需要:

最低版本

必需

已更改

numpy

1.15.4

X

X

pytz

2015.4

X

python-dateutil

2.7.3

X

X

bottleneck

1.2.1

numexpr

2.6.2

pytest (dev)

4.0.2

對於可選庫,一般建議使用最新版本。下表列出了在 pandas 開發過程中始終進行測試的每個庫的最低版本。低於最低測試版本的可選庫可能仍然有效,但未被視為受支援。

最低版本

已更改

beautifulsoup4

4.6.0

fastparquet

0.3.2

fsspec

0.7.4

gcsfs

0.6.0

X

lxml

3.8.0

matplotlib

2.2.2

numba

0.46.0

openpyxl

2.5.7

pyarrow

0.13.0

pymysql

0.7.1

pytables

3.4.3

X

s3fs

0.4.0

X

scipy

1.2.0

X

sqlalchemy

1.1.4

xarray

0.8.2

xlrd

1.1.0

xlsxwriter

0.9.8

xlwt

1.2.0

pandas-gbq

1.2.0

X

有關更多資訊,請參閱DependenciesOptional dependencies

開發變更(#)。

  • Cython 的最低版本現在是最新錯誤修復版本(0.29.16)(GH 33334)。

棄用#

  • 在具有單個專案列表的 Series 上進行查詢(例如 ser[[slice(0, 4)]])已被棄用,並在將來版本中引發錯誤。請將列表轉換為元組,或直接傳遞切片(GH 31333)。

  • DataFrame.mean()DataFrame.median()numeric_only=None 的情況下,在將來的版本中將包含 datetime64datetime64tz 列(GH 29941)。

  • 使用帶有位置切片的 .loc 進行賦值已被棄用,並在將來版本中引發錯誤。請改用帶有標籤的 .loc 或帶有位置的 .ilocGH 31840)。

  • DataFrame.to_dict() 已棄用接受 orient 的短名稱,並將在將來版本中引發錯誤(GH 32515)。

  • Categorical.to_dense() 已被棄用,並將在將來的版本中移除;請改用 np.asarray(cat)GH 32639)。

  • SingleBlockManager 建構函式中的 fastpath 關鍵字已被棄用,並將在將來的版本中移除(GH 33092)。

  • pandas.merge() 中將 suffixes 作為 set 傳遞已被棄用。請改為提供一個元組(GH 33740, GH 34741)。

  • 使用多維索引器(如 [:, None])對 Series 進行索引以返回 ndarray 現在會引發 FutureWarning。請改為先轉換為 NumPy 陣列(GH 27837)。

  • Index.is_mixed() 已被棄用,並將在將來的版本中移除;請直接檢查 index.inferred_typeGH 32922)。

  • read_html() 傳遞除第一個引數外的任何引數作為位置引數已被棄用。所有其他引數都應作為關鍵字引數給出(GH 27573)。

  • read_json() 傳遞除 path_or_buf(第一個引數)外的任何引數作為位置引數已被棄用。所有其他引數都應作為關鍵字引數給出(GH 27573)。

  • read_excel() 傳遞除前兩個引數外的任何引數作為位置引數已被棄用。所有其他引數都應作為關鍵字引數給出(GH 27573)。

  • pandas.api.types.is_categorical() 已被棄用,並將在將來的版本中移除;請改用 pandas.api.types.is_categorical_dtype()GH 33385)。

  • Index.get_value() 已被棄用,並將在將來的版本中移除(GH 19728)。

  • Series.dt.week()Series.dt.weekofyear() 已被棄用,並將在將來的版本中移除,請改用 Series.dt.isocalendar().week()GH 33595)。

  • DatetimeIndex.week()DatetimeIndex.weekofyear 已被棄用,並將在將來的版本中移除,請改用 DatetimeIndex.isocalendar().weekGH 33595)。

  • DatetimeArray.week()DatetimeArray.weekofyear 已被棄用,並將在將來的版本中移除,請改用 DatetimeArray.isocalendar().weekGH 33595)。

  • DateOffset.__call__() 已被棄用,並將在將來的版本中移除,請改用 offset + otherGH 34171)。

  • apply_index() 已被棄用,並將在將來的版本中移除。請改用 offset + otherGH 34580)。

  • DataFrame.tshift()Series.tshift() 已被棄用,並將在將來的版本中移除,請改用 DataFrame.shift()Series.shift()GH 11631)。

  • 使用浮點鍵對 Index 物件進行索引已被棄用,並將在將來引發 IndexError。您可以手動轉換為整數鍵(GH 34191)。

  • groupby() 中的 squeeze 關鍵字已被棄用,並將在將來的版本中移除(GH 32380)。

  • Period.to_timestamp() 中的 tz 關鍵字已被棄用,並將在將來的版本中移除;請改用 per.to_timestamp(...).tz_localize(tz)GH 34522)。

  • DatetimeIndex.to_perioddelta() 已被棄用,並將在將來的版本中移除。請改用 index - index.to_period(freq).to_timestamp()GH 34853)。

  • DataFrame.melt() 接受一個已存在的 value_name 已被棄用,並將在將來版本中移除(GH 34731)。

  • DataFrame.expanding() 函式中的 center 關鍵字已被棄用,並將在將來的版本中移除(GH 20647)。

效能改進#

  • Timedelta 建構函式中的效能改進(GH 30543)。

  • Timestamp 建構函式中的效能改進(GH 30543)。

  • DataFrameSeries 之間使用 axis=0 的靈活算術運算中的效能改進(GH 31296)。

  • DataFrameSeries 之間使用 axis=1 的算術運算中的效能改進(GH 33600)。

  • 內部索引方法 _shallow_copy() 現在將快取的屬性複製到新索引,從而避免在新索引上重新建立它們。這可以加快許多依賴於建立現有索引副本的操作(GH 28584, GH 32640, GH 32669)。

  • 使用 DataFrame.sparse.from_spmatrix() 建構函式從 scipy.sparse 矩陣建立具有稀疏值的 DataFrame 時,效能顯著提升(GH 32821, GH 32825, GH 32826, GH 32856, GH 32858)。

  • groupby 方法 Groupby.first()Groupby.last() 的效能改進(GH 34178)。

  • 對可為空的(整數和布林)dtypes,factorize() 的效能改進(GH 33064)。

  • 構建 Categorical 物件的效能改進(GH 33921)。

  • 修復了 pandas.qcut()pandas.cut() 的效能迴歸(GH 33921)。

  • 對可為空的(整數和布林)dtypes 的歸約(sum, prod, min, max)的效能改進(GH 30982, GH 33261, GH 33442)。

  • 兩個 DataFrame 物件之間的算術運算的效能改進(GH 32779)。

  • RollingGroupby 的效能改進(GH 34052)。

  • pandas.MultiIndex 的算術運算(subaddmuldiv)進行效能改進(GH 34297

  • bool_indexerlist 時,對 DataFrame[bool_indexer] 進行效能改進(GH 33924

  • 使用多種方式(如 io.formats.style.Styler.apply()io.formats.style.Styler.applymap()io.formats.style.Styler.bar())新增樣式後,io.formats.style.Styler.render() 的效能有顯著提升(GH 19917

Bug 修復#

分類#

  • Categorical.take() 傳遞無效的 fill_value 時,現在會引發 ValueError 而不是 TypeErrorGH 33660

  • concat()append() 等操作中,將包含缺失值的、具有整數類別的 pandas.Categorical 與浮點數 dtype 列結合時,現在會產生一個浮點數列而不是 object dtype 列(GH 33607

  • 修復了 merge() 無法在非唯一類別索引上進行連線的錯誤(GH 28189

  • 修復了將類別資料傳遞給 pandas.Index 建構函式並指定 dtype=object 時,錯誤地返回 pandas.CategoricalIndex 而不是 object-dtype pandas.Index 的錯誤(GH 32167

  • 修復了 pandas.Categorical 的比較運算子 __ne__ 在任一元素缺失時錯誤地評估為 False 的錯誤(GH 32276

  • Categorical.fillna() 現在接受 pandas.Categorical 作為 other 引數(GH 32420

  • 修復了 pandas.Categorical 的 repr(表示形式)未區分 intstr 的問題(GH 33676

日期時間型別#

  • int64 以外的整數 dtype 傳遞給 np.array(period_index, dtype=...) 時,現在會引發 TypeError,而不是錯誤地使用 int64GH 32255

  • Series.to_timestamp() 現在如果 axis 不是 pandas.PeriodIndex,會引發 TypeError。之前會引發 AttributeErrorGH 33327

  • Series.to_period() 現在如果 axis 不是 pandas.DatetimeIndex,會引發 TypeError。之前會引發 AttributeErrorGH 33327

  • pandas.Period 不再接受元組作為 freq 引數(GH 34658

  • 修復了 pandas.Timestamp 中,從不明確的 epoch 時間構造 pandas.Timestamp 並再次呼叫建構函式時,Timestamp.value() 屬性發生更改的錯誤(GH 24329

  • 修復了 DatetimeArray.searchsorted()TimedeltaArray.searchsorted()PeriodArray.searchsorted() 未識別非 pandas 標量並錯誤地引發 ValueError 而不是 TypeError 的問題(GH 30950

  • 修復了 pandas.Timestamp 中,使用 dateutil 時區構造 pandas.Timestamp,當時間比夏令時轉換(冬季到夏季)早不到 128 納秒時,會產生不存在時間的錯誤(GH 31043

  • 修復了 Period.to_timestamp()Period.start_time() 在微秒頻率下返回比正確時間早一納秒的時間戳的錯誤(GH 31475

  • 修復了 pandas.Timestamp 在年、月或日缺失時丟擲令人困惑的錯誤訊息的問題(GH 31200

  • 修復了 pandas.DatetimeIndex 建構函式錯誤地接受 bool 型別輸入的錯誤(GH 32668

  • 修復了 DatetimeIndex.searchsorted() 不接受 listpandas.Series 作為其引數的錯誤(GH 32762

  • 修復了 pandas.PeriodIndex() 在傳入字串 pandas.Series 時引發錯誤的 bug(GH 26109

  • 修復了 pandas.Timestamp 算術運算中,新增或減去具有 timedelta64 型別的 np.ndarray 時出現的錯誤(GH 33296

  • 修復了 DatetimeIndex.to_period() 在不帶引數呼叫時,未推斷頻率的錯誤(GH 33358

  • 修復了 DatetimeIndex.tz_localize() 在某些情況下不正確地保留 freq,即使原始 freq 已不再有效(GH 30511

  • 修復了 DatetimeIndex.intersection() 在某些情況下丟失 freq 和時區的錯誤(GH 33604

  • 修復了 DatetimeIndex.get_indexer() 對於混合日期時間類目標有時會返回錯誤結果的錯誤(GH 33741

  • 修復了 pandas.DatetimeIndex 在與某些型別的 pandas.tseries.offsets.DateOffset 物件進行加減運算時,不正確地保留無效的 freq 屬性的錯誤(GH 33779

  • 修復了 pandas.DatetimeIndex 中,在設定索引的 freq 屬性時,可能會靜默更改檢視同一資料的另一個索引的 freq 屬性的問題(GH 33552

  • 當對使用空 pd.to_datetime()初始化的物件呼叫 DataFrame.min()DataFrame.max() 時,其結果與 Series.min()Series.max() 的結果不一致。

  • 修復了 DatetimeIndex.intersection()TimedeltaIndex.intersection() 的結果沒有正確 name 屬性的錯誤(GH 33904

  • 修復了 DatetimeArray.__setitem__()TimedeltaArray.__setitem__()PeriodArray.__setitem__() 錯誤地允許 int64 型別的值被靜默轉換的問題(GH 33717

  • 修復了從 pandas.Period 中減去 pandas.TimedeltaIndex 時,在某些本應成功的情況下錯誤地引發 TypeError,並在某些本應引發 TypeError 的情況下引發 IncompatibleFrequency 的錯誤(GH 33883

  • 修復了從只讀 NumPy 陣列(非納秒解析度)建立 pandas.Seriespandas.Index 時,在時間戳範圍內,會將資料轉換為 object dtype 而不是強制轉換為 datetime64[ns] dtype 的錯誤(GH 34843)。

  • Perioddate_range()period_range()pd.tseries.frequencies.to_offset() 中的 freq 關鍵字不再允許使用元組,請改用字串傳遞(GH 34703

  • 修復了 DataFrame.append() 在將包含標量時區感知 pandas.Timestamppandas.Series 追加到一個空的 pandas.DataFrame 時,錯誤地產生了一個 object 列而不是 datetime64[ns, tz] dtype 的問題(GH 35038

  • OutOfBoundsDatetime 在時間戳超出實現邊界時,提供了一個改進的錯誤訊息。(GH 32967

  • 修復了 AbstractHolidayCalendar.holidays() 在沒有定義規則時出現的錯誤(GH 31415

  • 修復了 Tick 類與 timedelta 類物件進行比較時引發 TypeError 的錯誤(GH 34088

  • 修復了 Tick 類與浮點數相乘時引發 TypeError 的錯誤(GH 34486

時間差#

  • 修復了使用高精度整數構造 pandas.Timedelta 時,會舍入 Timedelta 元件的錯誤(GH 31354

  • 修復了將 np.nanNone 除以 pandas.Timedelta 時,錯誤地返回 NaT 的問題(GH 31869

  • pandas.Timedelta 現在可以識別 µs 作為微秒的識別符號(GH 32899

  • 當納秒非零時,pandas.Timedelta 的字串表示形式現在包含納秒(GH 9309

  • 修復了比較 pandas.Timedelta 物件與具有 timedelta64 型別的 np.ndarray 時,錯誤地將所有條目視為不相等的問題(GH 33441

  • 修復了 timedelta_range() 在邊緣情況下生成額外點的錯誤(GH 30353, GH 33498

  • 修復了 DataFrame.resample() 在邊緣情況下生成額外點的錯誤(GH 30353, GH 13022, GH 33498

  • 修復了 DataFrame.resample() 在處理 timedelta 時忽略 loffset 引數的錯誤(GH 7687, GH 33498

  • 修復了 pandas.Timedeltapandas.to_timedelta() 在字串輸入時忽略 unit 引數的錯誤(GH 12136

時區#

  • 修復了 to_datetime()infer_datetime_format=True 時,無法正確解析時區名稱(例如 UTC)的錯誤(GH 33133

數值#

  • 修復了 DataFrame.floordiv()axis=0 時,除以零的處理方式與 Series.floordiv() 不同(GH 31271

  • 修復了 to_numeric() 使用字串引數 "uint64"errors="coerce" 時靜默失敗的錯誤(GH 32394

  • 修復了 to_numeric() 使用 downcast="unsigned" 時,對空資料失敗的錯誤(GH 32493

  • 修復了 DataFrame.mean()numeric_only=False 且包含 datetime64 dtype 或 PeriodDtype 列時,錯誤地引發 TypeError 的問題(GH 32426

  • 修復了 DataFrame.count() 在使用 level="foo" 且索引級別 "foo" 包含 NaN 時導致段錯誤的問題(GH 21824

  • 修復了 DataFrame.diff()axis=1 時,對於混合 dtype 返回錯誤結果的錯誤(GH 32995

  • 修復了 DataFrame.corr()DataFrame.cov() 在處理帶有 pandas.NA 的可空整數列時引發錯誤的 bug(GH 33803

  • 修復了具有非重疊列且標籤重複的 DataFrame 物件之間的算術運算導致無限迴圈的錯誤(GH 35194

  • 修復了 DataFramepandas.Series 之間 object-dtype 物件與 datetime64 dtype 物件之間的加減運算錯誤(GH 33824

  • 修復了 Index.difference() 在比較 Float64Index 和 object pandas.Index 時給出錯誤結果的錯誤(GH 35217

  • 修復了 DataFrame 約簡操作(例如 df.min()df.max())在處理 ExtensionArray dtypes 時出現的錯誤(GH 34520, GH 32651

  • Series.interpolate()DataFrame.interpolate() 現在如果 limit_direction'forward''both'method'backfill''bfill',或者 limit_direction'backward''both'method'pad''ffill',則會引發 ValueError(GH 34746

轉換#

  • 修復了從大端位元組序 datetime64 dtype 的 NumPy 陣列構造 pandas.Series 時出現的錯誤(GH 29684

  • 修復了使用較大的納秒關鍵字值構造 pandas.Timedelta 時出現的錯誤(GH 32402

  • 修復了 DataFrame 建構函式在重複集合而不是引發錯誤時出現的問題(GH 32582

  • DataFrame 建構函式不再接受 DataFrame 物件列表。由於 NumPy 的更改,DataFrame 物件現在被一致地視為二維物件,因此 DataFrame 物件列表被視為三維,不再適用於 DataFrame 建構函式(GH 32289)。

  • 修復了 DataFrame 在使用列表初始化框架併為 MultiIndex 分配帶有巢狀列表的 columns 時出現的錯誤(GH 32173

  • 改進了建立新索引時,無效的列表構造的錯誤訊息(GH 35190

字串#

  • 修復了 Series.astype() 方法在將“string” dtype 資料轉換為可空整數 dtype 時出現的錯誤(GH 32450)。

  • 修復了在 StringArray 或具有 StringDtype 型別的 Series 上取 minmax 時引發錯誤的 bug。(GH 31746

  • 修復了 Series.str.cat()otherpandas.Index 型別時返回 NaN 輸出的錯誤(GH 33425

  • pandas.api.dtypes.is_string_dtype() 不再錯誤地將類別 series 識別為字串。

Interval#

  • 修復了 IntervalArray 在設定值時錯誤地允許更改底層資料的錯誤(GH 32782

索引#

Missing#

  • 在空的 Series 上呼叫 fillna() 現在會正確返回一個淺複製的物件。該行為現在與 IndexDataFrame 和非空 Series 的行為一致 (GH 32543)。

  • Series.replace()to_replace 引數是 dict/list 型別且應用於包含 <NA>Series 時,會引發 TypeError。該方法現在透過在進行替換比較時忽略 <NA> 值來處理此問題 (GH 32621)

  • any()all() 在使用可為空的 Boolean 型別並且 skipna=False 時,對於所有 False 或所有 True 值,會錯誤地返回 <NA> (GH 33253)

  • 關於 interpolate 方法使用 method=akima 的文件已澄清。der 引數必須是標量或 None (GH 33426)

  • DataFrame.interpolate() 現在使用正確的軸約定。之前沿列插值會導致沿索引插值,反之亦然。此外,使用 padffillbfillbackfill 方法進行插值與使用 DataFrame.fillna() 進行填充方法相同 (GH 12918, GH 29146)

  • DataFrame.interpolate() 在對列名為字串型別的 DataFrame 呼叫時會引發 ValueError。現在該方法與列名型別無關 (GH 33956)

  • 現在可以將 NA 傳遞到格式字串中使用格式說明符。例如,"{:.1f}".format(pd.NA) 以前會引發 ValueError,但現在會返回字串 "<NA>" (GH 34740)

  • Series.map()na_action 無效時未引發錯誤 (GH 32815)

MultiIndex#

  • DataFrame.swaplevels() 現在如果軸不是 MultiIndex,則會引發 TypeError。之前會引發 AttributeError (GH 31126)

  • Dataframe.loc() 在與 MultiIndex 一起使用時出現錯誤。返回的值與輸入值的順序不一致 (GH 22797)

In [79]: df = pd.DataFrame(np.arange(4),
   ....:                   index=[["a", "a", "b", "b"], [1, 2, 1, 2]])
   ....: 

# Rows are now ordered as the requested keys
In [80]: df.loc[(['b', 'a'], [2, 1]), :]
Out[80]: 
     0
b 2  3
  1  2
a 2  1
  1  0
In [81]: left = pd.MultiIndex.from_arrays([["b", "a"], [2, 1]])

In [82]: right = pd.MultiIndex.from_arrays([["a", "b", "c"], [1, 2, 3]])

# Common elements are now guaranteed to be ordered by the left side
In [83]: left.intersection(right, sort=False)
Out[83]: 
MultiIndex([('b', 2),
            ('a', 1)],
           )
  • 連線兩個 MultiIndex 時,未指定級別且具有不同列的情況下出現錯誤。Return-indexers 引數被忽略。 (GH 34074)

IO#

  • set 作為 names 引數傳遞給 pandas.read_csv()pandas.read_table()pandas.read_fwf() 時,會引發 ValueError: Names should be an ordered collection. (GH 34946)

  • display.precision 為零時列印輸出出現錯誤。 (GH 20359)

  • read_json() 在 JSON 包含大數字字串時發生整數溢位錯誤 (GH 30320)

  • read_csv()headerprefix 引數均不為 None 時,將引發 ValueError。 (GH 27394)

  • DataFrame.to_json()path_or_buf 是 S3 URI 時引發 NotFoundError (GH 28375)

  • DataFrame.to_parquet() 覆蓋了 pyarrow 對 coerce_timestamps 的預設設定;遵循 pyarrow 的預設設定允許使用 version="2.0" 寫入納秒時間戳 (GH 31652)。

  • read_csv()sep=Nonecomment 關鍵字組合使用時引發 TypeError (GH 31396)

  • HDFStore 在讀取 Python 2 中寫入的固定格式 DataFrame 時,導致 datetime64 列的 dtype 被設定為 int64 (GH 31750)

  • read_sas() 現在可以處理大於 Timestamp.max 的日期和時間,並將它們返回為 datetime.datetime 物件 (GH 20927)

  • DataFrame.to_json()date_format="iso" 時,Timedelta 物件無法正確序列化 (GH 28256)

  • read_csv()parse_dates 中傳入的列名在 DataFrame 中缺失時,將引發 ValueError (GH 31251)

  • read_excel() 在 UTF-8 字串包含高位代理字元時,會導致分段錯誤 (GH 23809)

  • read_csv() 在處理空檔案時導致檔案描述符洩露 (GH 31488)

  • read_csv() 在頭部和資料行之間存在空行時,導致了段錯誤 (GH 28071)

  • read_csv() 在許可權問題時引發了誤導性的異常 (GH 23784)

  • read_csv()header=None 且存在兩個額外資料列時,引發了 IndexError

  • read_sas() 在從 Google Cloud Storage 讀取檔案時引發了 AttributeError (GH 33069)

  • DataFrame.to_sql() 中存在一個錯誤,當儲存越界日期時會引發 AttributeError (GH 26761)

  • read_excel() 中存在一個錯誤,在處理 OpenDocument 文字單元格中的多個嵌入空格時未能正確處理。 (GH 32207)

  • read_json() 中存在一個錯誤,在將布林值列表讀取到 Series 時會引發 TypeError。 (GH 31464)

  • pandas.io.json.json_normalize() 中存在一個錯誤,其中 record_path 指定的位置不指向陣列。 (GH 26284)

  • pandas.read_hdf() 在載入不支援的 HDF 檔案時會提供更明確的錯誤訊息 (GH 9539)

  • read_feather() 中存在一個錯誤,在讀取 s3 或 http 檔案路徑時會引發 ArrowIOError (GH 29055)

  • to_excel() 中存在一個錯誤,無法處理列名 'render' 並會引發 KeyError (GH 34331)

  • execute() 中存在一個錯誤,當 SQL 語句包含 '%' 字元且沒有引數時,對於某些 DB-API 驅動程式會引發 ProgrammingError (GH 34211)

  • StataReader() 中存在一個錯誤,在透過迭代器讀取資料時會導致分類變數具有不同的 dtypes。 (GH 31544)

  • HDFStore.keys() 現在有一個可選的 include 引數,允許檢索所有本地 HDF5 表名 (GH 29916)

  • read_csv() 和 read_table() 引發的 TypeError 異常,當傳入非預期的關鍵字引數時,會顯示為 parser_f (GH 25648)

  • read_excel() 對於 ODS 檔案存在一個錯誤,會刪除 0.0 值 (GH 27222)

  • ujson.encode() 中存在一個錯誤,當數字大於 sys.maxsize 時會引發 OverflowError (GH 34395)

  • HDFStore.append_to_multiple() 中存在一個錯誤,當設定 min_itemsize 引數時會引發 ValueError (GH 11238)

  • create_table() 中存在一個錯誤,現在當 data_columns 中的 column 引數未指定時會引發錯誤 (GH 28156)

  • read_json() 現在可以從檔案 URL 讀取行分隔的 JSON 檔案,其中 lines 和 chunksize 已設定。

  • DataFrame.to_sql() 中存在一個錯誤,當讀取帶有 -np.inf 條目的 DataFrame 到 MySQL 時,現在會提供更明確的 ValueError (GH 34431)

  • 大寫副檔名未被 read_* 函式解壓縮的錯誤 (GH 35164)

  • read_excel() 中存在一個錯誤,當 header=None 且 index_col 被指定為列表時會引發 TypeError (GH 31783)

  • read_excel() 中存在一個錯誤,當 datetime 值用在 MultiIndex 的 header 中時 (GH 34748)

  • read_excel() 不再接受 **kwds 引數。這意味著傳入關鍵字引數 chunksize 現在會引發 TypeError (以前引發 NotImplementedError),而傳入關鍵字引數 encoding 現在會引發 TypeError (GH 34464)

  • DataFrame.to_records() 中存在一個錯誤,在處理時區感知的 datetime64 列時會錯誤地丟失時區資訊 (GH 32535)

繪圖#

  • DataFrame.plot() 對於 line/bar 現在接受按字典顏色 (GH 8193)。

  • DataFrame.plot.hist() 中存在一個錯誤,當使用權重時,對於多個列不起作用 (GH 33173)

  • DataFrame.boxplot() 和 DataFrame.plot.boxplot() 中存在一個錯誤,會丟失 medianprops, whiskerprops, capprops 和 boxprops 的顏色屬性 (GH 30346)

  • DataFrame.hist() 中存在一個錯誤,其中 column 引數的順序被忽略 (GH 29235)

  • DataFrame.plot.scatter() 中存在一個錯誤,當使用不同的 cmap 新增多個繪圖時,色條始終使用第一個 cmap (GH 33389)

  • DataFrame.plot.scatter() 中存在一個錯誤,即使 c 引數被分配給包含顏色名稱的列,也會向繪圖新增色條 (GH 34316)

  • pandas.plotting.bootstrap_plot() 中存在一個錯誤,導致座標軸混亂和標籤重疊 (GH 34905)

  • DataFrame.plot.scatter() 中存在一個錯誤,在繪製可變標記大小時會引發錯誤 (GH 32904)

GroupBy/resample/rolling

  • 使用 count、min、max、median、skew、cov、corr 的 pandas.api.indexers.BaseIndexer 現在將為任何單調的 pandas.api.indexers.BaseIndexer 後代返回正確的結果 (GH 32865)

  • DataFrameGroupby.mean() 和 SeriesGroupby.mean() (以及 median()、std() 和 var() 類似) 現在如果傳入非接受的關鍵字引數,將引發 TypeError。以前會引發 UnsupportedFunctionCall (如果 min_count 傳入 median(),則為 AssertionError) (GH 31485)

  • DataFrameGroupBy.apply() 和 SeriesGroupBy.apply() 中存在一個錯誤,當 by 軸未排序、存在重複項,並且應用的 func 不會修改傳入的物件時會引發 ValueError (GH 30667)

  • DataFrameGroupby.transform() 中存在一個錯誤,在使用轉換函式時產生不正確的結果 (GH 30918)

  • DataFrameGroupBy.transform() 和 SeriesGroupBy.transform() 中存在一個錯誤,當按多個鍵分組,其中一些是分類的而另一些不是時,會返回錯誤的結果 (GH 32494)

  • DataFrameGroupBy.count() 和 SeriesGroupBy.count() 中存在一個錯誤,當分組列包含 NaN 時會導致分段錯誤 (GH 32841)

  • DataFrame.groupby() 和 Series.groupby() 中存在一個錯誤,當聚合布林 Series 時產生不一致的型別 (GH 32894)

  • DataFrameGroupBy.sum() 和 SeriesGroupBy.sum() 中存在一個錯誤,當非空值的數量低於 nullable integer dtypes 的 min_count 時,會返回一個很大的負數 (GH 32861)

  • SeriesGroupBy.quantile() 中存在一個錯誤,在處理 nullable integers 時會引發錯誤 (GH 33136)

  • DataFrame.resample() 中存在一個錯誤,當生成的時區感知 DatetimeIndex 在午夜發生 DST 轉換時會引發 AmbiguousTimeError (GH 25758)

  • DataFrame.groupby() 中存在一個錯誤,當按具有隻讀類別且 sort=False 的分類列分組時會引發 ValueError (GH 33410)

  • DataFrameGroupBy.agg(), SeriesGroupBy.agg(), DataFrameGroupBy.transform(), SeriesGroupBy.transform(), DataFrameGroupBy.resample(), 和 SeriesGroupBy.resample() 中存在一個錯誤,其中子類未被保留 (GH 28330)

  • SeriesGroupBy.agg() 中存在一個錯誤,之前允許 SeriesGroupBy 的命名聚合中接受任何列名。現在的行為只允許 str 和可呼叫項,否則會引發 TypeError。 (GH 34422)

  • DataFrame.groupby() 中存在一個錯誤,當 agg 鍵引用一個空列表時,會丟失 Index 的名稱 (GH 32580)

  • Rolling.apply() 中存在一個錯誤,當指定 engine='numba' 時,center=True 被忽略 (GH 34784)

  • DataFrame.ewm.cov() 中存在一個錯誤,當輸入為 MultiIndex 時會引發 AssertionError (GH 34440)

  • core.groupby.DataFrameGroupBy.quantile() 中存在一個錯誤,對於非數值型別會引發 TypeError,而不是刪除列 (GH 27892)

  • core.groupby.DataFrameGroupBy.transform() 中存在一個錯誤,當 func='nunique' 且列為 datetime64 型別時,結果也會是 datetime64 型別,而不是 int64 (GH 35109)

  • DataFrame.groupby() 中存在一個錯誤,當選擇一列並以 as_index=False 進行聚合時會引發 AttributeError (GH 35246)。

  • DataFrameGroupBy.first() 和 DataFrameGroupBy.last() 中存在一個錯誤,當按多個 Categoricals 分組時會引發不必要的 ValueError (GH 34951)

Reshaping#

  • 影響所有數值和布林歸約方法未返回子類資料型別的錯誤。 (GH 25596)

  • DataFrame.pivot_table() 中存在一個錯誤,當僅設定 MultiIndexed 列時 (GH 17038)

  • DataFrame.unstack() 和 Series.unstack() 中存在一個錯誤,可以接受 MultiIndexed 資料中的元組名稱 (GH 19966)

  • DataFrame.pivot_table() 中存在一個錯誤,當 margin 為 True 且僅定義 column 時 (GH 31016)

  • DataFrame.pivot() 中當 columns 設定為 None 時的不正確錯誤訊息已被修復。 (GH 30924)

  • crosstab() 中存在一個錯誤,當輸入是兩個 Series 且具有元組名稱時,輸出將保留一個虛擬 MultiIndex 作為列。 (GH 18321)

  • DataFrame.pivot() 現在可以接受 lists 作為 index 和 columns 引數 (GH 21425)

  • concat() 中存在一個錯誤,當 copy=True 時,結果索引未被複制 (GH 29879)

  • SeriesGroupBy.aggregate() 中存在一個錯誤,當聚合共享相同名稱時,聚合結果會被覆蓋 (GH 30880)

  • Index.astype() 在從 Float64Index 轉換為 Int64Index 或轉換為 ExtensionArray dtype 時會丟失 name 屬性的錯誤 (GH 32013)

  • Series.append() 現在當傳入 DataFrame 或包含 DataFrame 的序列時將引發 TypeError (GH 31413)

  • DataFrame.replace() 和 Series.replace() 如果 to_replace 不是預期的型別,將引發 TypeError。以前 replace 會靜默失敗 (GH 18634)

  • Series 的 inplace 操作存在錯誤,該操作將從 DataFrame 中新增一個已刪除的列 (使用 inplace=True) (GH 30484)

  • DataFrame.apply() 中存在一個錯誤,即使請求了 raw=True,回撥函式仍會以 Series 引數被呼叫。 (GH 32423)

  • DataFrame.pivot_table() 中存在一個錯誤,在從具有時區感知 dtype 的列建立 MultiIndex 級別時丟失時區資訊 (GH 32558)

  • concat() 中存在一個錯誤,當將非 dict 對映作為 objs 傳遞時會引發 TypeError (GH 32863)

  • DataFrame.agg() 現在在嘗試聚合不存在的列時提供更具描述性的 SpecificationError 訊息 (GH 32755)

  • DataFrame.unstack() 中存在一個錯誤,當使用 MultiIndex 列和 MultiIndex 行時 (GH 32624, GH 24729 and GH 28306)

  • 將字典追加到 DataFrame 而不傳遞 ignore_index=True 時,將引發 TypeError: Can only append a dict if ignore_index=True,而不是 TypeError: Can only append a :class:`Series` if ignore_index=True or if the :class:`Series` has a name (GH 30871)

  • Bug in DataFrame.corrwith(), DataFrame.memory_usage(), DataFrame.dot(), DataFrame.idxmin(), DataFrame.idxmax(), DataFrame.duplicated(), DataFrame.isin(), DataFrame.count(), Series.explode(), Series.asof() and DataFrame.asof() 未返回子類型別。( GH 31331)

  • Bug in concat() 無法連線具有重複鍵的 DataFrameSeries。( GH 33654)

  • Bug in cut() 當引數 labels 包含重複項時引發錯誤。( GH 33141)

  • 確保僅允許在 eval() 中使用已命名的函式。( GH 32460)

  • Bug in Dataframe.aggregate() and Series.aggregate() 在某些情況下導致遞迴迴圈。( GH 34224)

  • Fixed bug in melt() where melting MultiIndex columns with col_level > 0 would raise a KeyError on id_vars。( GH 34129)

  • Bug in Series.where() with an empty Series and empty cond having non-bool dtype。( GH 34592)

  • Fixed regression where DataFrame.apply() would raise ValueError for elements with S dtype。( GH 34529)

Sparse#

  • Creating a SparseArray from timezone-aware dtype will issue a warning before dropping timezone information, instead of doing so silently。( GH 32501)

  • Bug in arrays.SparseArray.from_spmatrix() wrongly read scipy sparse matrix。( GH 31991)

  • Bug in Series.sum() with SparseArray raised a TypeError。( GH 25777)

  • Bug where DataFrame containing an all-sparse SparseArray filled with NaN when indexed by a list-like。( GH 27781, GH 29563)

  • The repr of SparseDtype now includes the repr of its fill_value attribute. Previously it used fill_value’s string representation。( GH 34352)

  • Bug where empty DataFrame could not be cast to SparseDtype。( GH 33113)

  • Bug in arrays.SparseArray() was returning the incorrect type when indexing a sparse dataframe with an iterable。( GH 34526, GH 34540)

ExtensionArray#

  • Fixed bug where Series.value_counts() would raise on empty input of Int64 dtype。( GH 33317)

  • Fixed bug in concat() when concatenating DataFrame objects with non-overlapping columns resulting in object-dtype columns rather than preserving the extension dtype。( GH 27692, GH 33027)

  • Fixed bug where StringArray.isna() would return False for NA values when pandas.options.mode.use_inf_as_na was set to True。( GH 33655)

  • Fixed bug in Series construction with EA dtype and index but no data or scalar data fails。( GH 26469)

  • Fixed bug that caused Series.__repr__() to crash for extension types whose elements are multidimensional arrays。( GH 33770)

  • Fixed bug where Series.update() would raise a ValueError for ExtensionArray dtypes with missing values。( GH 33980)

  • Fixed bug where StringArray.memory_usage() was not implemented。( GH 33963)

  • Fixed bug where DataFrameGroupBy() would ignore the min_count argument for aggregations on nullable Boolean dtypes。( GH 34051)

  • Fixed bug where the constructor of DataFrame with dtype='string' would fail。( GH 27953, GH 33623)

  • Bug where DataFrame column set to scalar extension type was considered an object type rather than the extension type。( GH 34832)

  • Fixed bug in IntegerArray.astype() to correctly copy the mask as well。( GH 34931).

其他#

貢獻者#

A total of 368 people contributed patches to this release. People with a “+” by their names contributed a patch for the first time.

  • 3vts +

  • A Brooks +

  • Abbie Popa +

  • Achmad Syarif Hidayatullah +

  • Adam W Bagaskarta +

  • Adrian Mastronardi +

  • Aidan Montare +

  • Akbar Septriyan +

  • Akos Furton +

  • Alejandro Hall +

  • Alex Hall +

  • Alex Itkes +

  • Alex Kirko

  • Ali McMaster +

  • Alvaro Aleman +

  • Amy Graham +

  • Andrew Schonfeld +

  • Andrew Shumanskiy +

  • Andrew Wieteska +

  • Angela Ambroz

  • Anjali Singh +

  • Anna Daglis

  • Anthony Milbourne +

  • Antony Lee +

  • Ari Sosnovsky +

  • Arkadeep Adhikari +

  • Arunim Samudra +

  • Ashkan +

  • Ashwin Prakash Nalwade +

  • Ashwin Srinath +

  • Atsushi Nukariya +

  • Ayappan +

  • Ayla Khan +

  • Bart +

  • Bart Broere +

  • Benjamin Beier Liu +

  • Benjamin Fischer +

  • Bharat Raghunathan

  • Bradley Dice +

  • Brendan Sullivan +

  • Brian Strand +

  • Carsten van Weelden +

  • Chamoun Saoma +

  • ChrisRobo +

  • Christian Chwala

  • Christopher Whelan

  • Christos Petropoulos +

  • Chuanzhu Xu

  • CloseChoice +

  • Clément Robert +

  • CuylenE +

  • DanBasson +

  • Daniel Saxton

  • Danilo Horta +

  • DavaIlhamHaeruzaman +

  • Dave Hirschfeld

  • Dave Hughes

  • David Rouquet +

  • David S +

  • Deepyaman Datta

  • Dennis Bakhuis +

  • Derek McCammond +

  • Devjeet Roy +

  • Diane Trout

  • Dina +

  • Dom +

  • Drew Seibert +

  • EdAbati

  • Emiliano Jordan +

  • Erfan Nariman +

  • Eric Groszman +

  • Erik Hasse +

  • Erkam Uyanik +

  • Evan D +

  • Evan Kanter +

  • Fangchen Li +

  • Farhan Reynaldo +

  • Farhan Reynaldo Hutabarat +

  • Florian Jetter +

  • Fred Reiss +

  • GYHHAHA +

  • Gabriel Moreira +

  • Gabriel Tutui +

  • Galuh Sahid

  • Gaurav Chauhan +

  • George Hartzell +

  • Gim Seng +

  • Giovanni Lanzani +

  • Gordon Chen +

  • Graham Wetzler +

  • Guillaume Lemaitre

  • Guillem Sánchez +

  • HH-MWB +

  • Harshavardhan Bachina

  • How Si Wei

  • Ian Eaves

  • Iqrar Agalosi Nureyza +

  • Irv Lustig

  • Iva Laginja +

  • JDkuba

  • Jack Greisman +

  • Jacob Austin +

  • Jacob Deppen +

  • Jacob Peacock +

  • Jake Tae +

  • Jake Vanderplas +

  • James Cobon-Kerr

  • Jan Červenka +

  • Jan Škoda

  • Jane Chen +

  • Jean-Francois Zinque +

  • Jeanderson Barros Candido +

  • Jeff Reback

  • Jered Dominguez-Trujillo +

  • Jeremy Schendel

  • Jesse Farnham

  • Jiaxiang

  • Jihwan Song +

  • Joaquim L. Viegas +

  • Joel Nothman

  • John Bodley +

  • John Paton +

  • Jon Thielen +

  • Joris Van den Bossche

  • Jose Manuel Martí +

  • Joseph Gulian +

  • Josh Dimarsky

  • Joy Bhalla +

  • João Veiga +

  • Julian de Ruiter +

  • Justin Essert +

  • Justin Zheng

  • KD-dev-lab +

  • Kaiqi Dong

  • Karthik Mathur +

  • Kaushal Rohit +

  • Kee Chong Tan

  • Ken Mankoff +

  • Kendall Masse

  • Kenny Huynh +

  • Ketan +

  • Kevin Anderson +

  • Kevin Bowey +

  • Kevin Sheppard

  • Kilian Lieret +

  • Koki Nishihara +

  • Krishna Chivukula +

  • KrishnaSai2020 +

  • Lesley +

  • Lewis Cowles +

  • Linda Chen +

  • Linxiao Wu +

  • Lucca Delchiaro Costabile +

  • MBrouns +

  • Mabel Villalba

  • Mabroor Ahmed +

  • Madhuri Palanivelu +

  • Mak Sze Chun

  • Malcolm +

  • Marc Garcia

  • Marco Gorelli

  • Marian Denes +

  • Martin Bjeldbak Madsen +

  • Martin Durant +

  • Martin Fleischmann +

  • Martin Jones +

  • Martin Winkel

  • Martina Oefelein +

  • Marvzinc +

  • María Marino +

  • Matheus Cardoso +

  • Mathis Felardos +

  • Matt Roeschke

  • Matteo Felici +

  • Matteo Santamaria +

  • Matthew Roeschke

  • Matthias Bussonnier

  • Max Chen

  • Max Halford +

  • Mayank Bisht +

  • Megan Thong +

  • Michael Marino +

  • Miguel Marques +

  • Mike Kutzma

  • Mohammad Hasnain Mohsin Rajan +

  • Mohammad Jafar Mashhadi +

  • MomIsBestFriend

  • Monica +

  • Natalie Jann

  • Nate Armstrong +

  • Nathanael +

  • Nick Newman +

  • Nico Schlömer +

  • Niklas Weber +

  • ObliviousParadigm +

  • Olga Lyashevska +

  • OlivierLuG +

  • Pandas Development Team

  • Parallels +

  • Patrick +

  • Patrick Cando +

  • Paul Lilley +

  • Paul Sanders +

  • Pearcekieser +

  • Pedro Larroy +

  • Pedro Reys

  • Peter Bull +

  • Peter Steinbach +

  • Phan Duc Nhat Minh +

  • Phil Kirlin +

  • Pierre-Yves Bourguignon +

  • Piotr Kasprzyk +

  • Piotr Niełacny +

  • Prakhar Pandey

  • Prashant Anand +

  • Puneetha Pai +

  • Quang Nguyễn +

  • Rafael Jaimes III +

  • Rafif +

  • RaisaDZ +

  • Rakshit Naidu +

  • Ram Rachum +

  • Red +

  • Ricardo Alanis +

  • Richard Shadrach +

  • Rik-de-Kort

  • Robert de Vries

  • Robin to Roxel +

  • Roger Erens +

  • Rohith295 +

  • Roman Yurchak

  • Ror +

  • Rushabh Vasani

  • Ryan

  • Ryan Nazareth

  • SAI SRAVAN MEDICHERLA +

  • SHUBH CHATTERJEE +

  • Sam Cohan

  • Samira-g-js +

  • Sandu Ursu +

  • Sang Agung +

  • SanthoshBala18 +

  • Sasidhar Kasturi +

  • SatheeshKumar Mohan +

  • Saul Shanabrook

  • Scott Gigante +

  • Sebastian Berg +

  • Sebastián Vanrell

  • Sergei Chipiga +

  • Sergey +

  • ShilpaSugan +

  • Simon Gibbons

  • Simon Hawkins

  • Simon Legner +

  • Soham Tiwari +

  • Song Wenhao +

  • Souvik Mandal

  • Spencer Clark

  • Steffen Rehberg +

  • Steffen Schmitz +

  • Stijn Van Hoey

  • Stéphan Taljaard

  • SultanOrazbayev +

  • Sumanau Sareen

  • SurajH1 +

  • Suvayu Ali +

  • Terji Petersen

  • Thomas J Fan +

  • Thomas Li

  • Thomas Smith +

  • Tim Swast

  • Tobias Pitters +

  • Tom +

  • Tom Augspurger

  • Uwe L. Korn

  • Valentin Iovene +

  • Vandana Iyer +

  • Venkatesh Datta +

  • Vijay Sai Mutyala +

  • Vikas Pandey

  • Vipul Rai +

  • Vishwam Pandya +

  • Vladimir Berkutov +

  • Will Ayd

  • Will Holmgren

  • William +

  • William Ayd

  • Yago González +

  • Yosuke KOBAYASHI +

  • Zachary Lawrence +

  • Zaky Bilfagih +

  • Zeb Nicholls +

  • alimcmaster1

  • alm +

  • andhikayusup +

  • andresmcneill +

  • avinashpancham +

  • benabel +

  • bernie gray +

  • biddwan09 +

  • brock +

  • chris-b1

  • cleconte987 +

  • dan1261 +

  • david-cortes +

  • davidwales +

  • dequadras +

  • dhuettenmoser +

  • dilex42 +

  • elmonsomiat +

  • epizzigoni +

  • fjetter

  • gabrielvf1 +

  • gdex1 +

  • gfyoung

  • guru kiran +

  • h-vishal

  • iamshwin

  • jamin-aws-ospo +

  • jbrockmendel

  • jfcorbett +

  • jnecus +

  • kernc

  • kota matsuoka +

  • kylekeppler +

  • leandermaben +

  • link2xt +

  • manoj_koneni +

  • marydmit +

  • masterpiga +

  • maxime.song +

  • mglasder +

  • moaraccounts +

  • mproszewska

  • neilkg

  • nrebena

  • ossdev07 +

  • paihu

  • pan Jacek +

  • partev +

  • patrick +

  • pedrooa +

  • pizzathief +

  • proost

  • pvanhauw +

  • rbenes

  • rebecca-palmer

  • rhshadrach +

  • rjfs +

  • s-scherrer +

  • sage +

  • sagungrp +

  • salem3358 +

  • saloni30 +

  • smartswdeveloper +

  • smartvinnetou +

  • themien +

  • timhunderwood +

  • tolhassianipar +

  • tonywu1999

  • tsvikas

  • tv3141

  • venkateshdatta1993 +

  • vivikelapoutre +

  • willbowditch +

  • willpeppo +

  • za +

  • zaki-indra +