版本 0.15.1 (2014年11月9日)#
這是從0.15.0版本開始的一個小錯誤修復版本,它包含少量 API 更改、一些新功能、增強和效能改進,以及大量的錯誤修復。我們建議所有使用者升級到此版本。
API 更改#
s.dt.hour和其他.dt訪問器現在將為缺失值返回np.nan(而不是之前的 -1),(GH 8689)In [1]: s = pd.Series(pd.date_range("20130101", periods=5, freq="D")) In [2]: s.iloc[2] = np.nan In [3]: s Out[3]: 0 2013-01-01 1 2013-01-02 2 NaT 3 2013-01-04 4 2013-01-05 Length: 5, dtype: datetime64[us]
之前的行為
In [6]: s.dt.hour Out[6]: 0 0 1 0 2 -1 3 0 4 0 dtype: int64
當前行為
In [4]: s.dt.hour Out[4]: 0 0.0 1 0.0 2 NaN 3 0.0 4 0.0 Length: 5, dtype: float64
使用
as_index=False的groupby不會向結果新增錯誤的額外列(GH 8582)In [5]: np.random.seed(2718281) In [6]: df = pd.DataFrame(np.random.randint(0, 100, (10, 2)), columns=["jim", "joe"]) In [7]: df.head() Out[7]: jim joe 0 61 81 1 96 49 2 55 65 3 72 51 4 77 12 [5 rows x 2 columns] In [8]: ts = pd.Series(5 * np.random.randint(0, 3, 10))
之前的行為
In [4]: df.groupby(ts, as_index=False).max() Out[4]: NaN jim joe 0 0 72 83 1 5 77 84 2 10 96 65
當前行為
In [4]: df.groupby(ts, as_index=False).max() Out[4]: jim joe 0 72 83 1 77 84 2 96 65
如果列名與分組名衝突,
groupby不會錯誤地排除列(GH 8112)In [9]: df = pd.DataFrame({"jim": range(5), "joe": range(5, 10)}) In [10]: df Out[10]: jim joe 0 0 5 1 1 6 2 2 7 3 3 8 4 4 9 [5 rows x 2 columns] In [11]: gr = df.groupby(df["jim"] < 2)
之前的行為(排除輸出中的第一列)
In [4]: gr.apply("sum") Out[4]: joe jim False 24 True 11
當前行為
In [12]: gr.apply("sum") Out[12]: jim joe jim False 9 24 True 1 11 [2 rows x 2 columns]
支援使用單調遞減索引進行切片,即使
start或stop不在索引中(GH 7860)In [13]: s = pd.Series(["a", "b", "c", "d"], [4, 3, 2, 1]) In [14]: s Out[14]: 4 a 3 b 2 c 1 d Length: 4, dtype: str
之前的行為
In [8]: s.loc[3.5:1.5] KeyError: 3.5
當前行為
In [15]: s.loc[3.5:1.5] Out[15]: 3 b 2 c Length: 2, dtype: str
io.data.Options已針對 Yahoo 期權頁面格式的更改進行了修復(GH 8612),(GH 8741)注意
由於 Yahoo 期權頁面佈局的更改,當給出到期日期時,
Options方法現在返回單個到期日期的資料。以前,方法會返回所選月份的所有資料。month和year引數已取消棄用,可用於獲取給定月份的所有期權資料。如果給出了無效的到期日期,則返回給定日期之後的下一個到期日期的資料。
期權資料框現在儲存為例項的
callsYYMMDD或putsYYMMDD。以前它們儲存為callsMMYY和putsMMYY。下一個到期日期儲存為calls和puts。新功能
到期引數現在可以是單個日期或包含日期的列表類物件。
添加了一個新屬性
expiry_dates,它返回所有可用的到期日期。
當前行為
In [17]: from pandas.io.data import Options In [18]: aapl = Options('aapl', 'yahoo') In [19]: aapl.get_call_data().iloc[0:5, 0:1] Out[19]: Last Strike Expiry Type Symbol 80 2014-11-14 call AAPL141114C00080000 29.05 84 2014-11-14 call AAPL141114C00084000 24.80 85 2014-11-14 call AAPL141114C00085000 24.05 86 2014-11-14 call AAPL141114C00086000 22.76 87 2014-11-14 call AAPL141114C00087000 21.74 In [20]: aapl.expiry_dates Out[20]: [datetime.date(2014, 11, 14), datetime.date(2014, 11, 22), datetime.date(2014, 11, 28), datetime.date(2014, 12, 5), datetime.date(2014, 12, 12), datetime.date(2014, 12, 20), datetime.date(2015, 1, 17), datetime.date(2015, 2, 20), datetime.date(2015, 4, 17), datetime.date(2015, 7, 17), datetime.date(2016, 1, 15), datetime.date(2017, 1, 20)] In [21]: aapl.get_near_stock_price(expiry=aapl.expiry_dates[0:3]).iloc[0:5, 0:1] Out[21]: Last Strike Expiry Type Symbol 109 2014-11-22 call AAPL141122C00109000 1.48 2014-11-28 call AAPL141128C00109000 1.79 110 2014-11-14 call AAPL141114C00110000 0.55 2014-11-22 call AAPL141122C00110000 1.02 2014-11-28 call AAPL141128C00110000 1.32
pandas 現在還將
datetime64dtype 註冊到 matplotlib 的單位登錄檔中,以便將此類值繪製為日期時間。一旦匯入 pandas,就會啟用此功能。在以前的版本中,繪製datetime64值陣列會導致繪製整數值。要保留之前的行為,可以執行del matplotlib.units.registry[np.datetime64](GH 8614)。
增強功能#
concat允許將更廣泛的 pandas 物件可迭代物件傳遞給第一個引數(GH 8645)In [16]: from collections import deque In [17]: df1 = pd.DataFrame([1, 2, 3]) In [18]: df2 = pd.DataFrame([4, 5, 6])
之前的行為
In [7]: pd.concat(deque((df1, df2))) TypeError: first argument must be a list-like of pandas objects, you passed an object of type "deque"
當前行為
In [19]: pd.concat(deque((df1, df2))) Out[19]: 0 0 1 1 2 2 3 0 4 1 5 2 6 [6 rows x 1 columns]
使用基於記憶體使用量的 dtype 來表示
MultiIndex標籤,具體取決於級別大小。在先前版本中,每個級別的記憶體使用量為 8 位元組。此外,在先前版本中,報告的記憶體使用量不正確,因為它沒有顯示底層資料陣列佔用的記憶體使用量。(GH 8456)In [20]: dfi = pd.DataFrame( ....: 1, index=pd.MultiIndex.from_product([["a"], range(1000)]), columns=["A"] ....: ) ....:
之前的行為
# this was underreported in prior versions In [1]: dfi.memory_usage(index=True) Out[1]: Index 8000 # took about 24008 bytes in < 0.15.1 A 8000 dtype: int64
當前行為
In [21]: dfi.memory_usage(index=True) Out[21]: Index 3174 A 8000 Length: 2, dtype: int64
添加了 Index 屬性
is_monotonic_increasing和is_monotonic_decreasing(GH 8680)。添加了在匯入 Stata 檔案時選擇列的選項(GH 7935)
在
DataFrame.info()中透過新增+來限定記憶體使用量,如果它是下界的話(GH 8578)在某些聚合情況下引發錯誤,例如
numeric_only引數未被處理(GH 8592)。在
io.wb.download()中添加了對 3 字元 ISO 和非標準國家程式碼的支援(GH 8482)世界銀行資料請求現在將根據
errors引數以及硬編碼的國家程式碼列表和世界銀行的 JSON 響應進行警告/引發錯誤。在先前版本中,錯誤訊息沒有檢視世界銀行的 JSON 響應。問題輸入在請求之前就被丟棄了。問題在於,許多好的國家在硬編碼方法中被裁剪掉了。現在所有國家都會正常工作,但一些壞的國家將引發異常,因為一些邊緣情況會破壞整個響應。(GH 8482)在
Series.str.split()中添加了返回DataFrame而不是Series的選項(GH 8428)在
df.info(null_counts=None|True|False)中添加了選項,以覆蓋預設顯示選項並強制顯示 null 計數(GH 8701)
Bug 修復#
取消對
CustomBusinessDay物件的 unpickling 的錯誤(GH 8591)將
Categorical強制轉換為記錄陣列(例如df.to_records())的錯誤(GH 8626)使用
Series.to_frame()無法正確建立Categorical的錯誤(GH 8626)在
Categorical的 astype 強制轉換中,傳入pd.Categorical的錯誤(此操作現在會正確引發TypeError),(GH 8626)在
cut/qcut中使用Series和retbins=True的錯誤(GH 8589)使用
to_sql將 Categorical 列寫入 SQL 資料庫的錯誤(GH 8624)。比較 datetime 的
Categorical與標量 datetime 時引發錯誤的錯誤(GH 8687)使用
.iloc選擇Categorical的錯誤(GH 8623)groupby-transform 與 Categorical 的錯誤(GH 8623)
duplicated/drop_duplicates 與 Categorical 的錯誤(GH 8623)
Categorical反射比較運算子在第一個引數是 numpy 陣列標量(例如 np.int64)時引發錯誤的錯誤(GH 8658)Panel 索引使用列表類(GH 8710)的錯誤
當
options.mode.use_inf_as_null為 True 時,DataFrame.dtypes的相容性問題(GH 8722)read_csv中dialect引數無法接受字串的錯誤(GH 8703)使用空列表切片 MultiIndex 級別的錯誤(GH 8737)
數值索引操作的 add/sub 操作,使用 Float/Index Index 與 numpy 陣列的錯誤(GH 8608)
使用空索引器進行 setitem 時出現意外的 dtype 強制轉換的錯誤(GH 8669)
ix/loc 塊在 setitem 上的拆分錯誤(在整數類 dtype(例如 datetime64)上表現出來)(GH 8607)
使用不在索引中的整數進行基於標籤的索引,但索引是唯一的但單調的索引時的錯誤(GH 8680)。
在 numpy 1.7 上使用
np.nan索引 Float64Index 時的錯誤(GH 8980)。修復
MultiIndex的shape屬性(GH 8609)修復了繪製列
y並指定標籤時會修改原始 DataFrame 的索引名稱的錯誤(GH 8494)修復了直接使用 matplotlib 繪製 DatetimeIndex 的迴歸錯誤(GH 8614)。
date_range中,部分指定的日期會包含當前日期的錯誤(GH 6961)使用標量值透過索引器設定混合 dtype
Panel4d時失敗的錯誤(GH 8702)DataReader在傳遞的符號無效時會失敗的錯誤。現在為有效符號返回資料,為無效符號返回 np.nan(GH 8494)get_quote_yahoo中不允許非浮點返回值(GH 5229)的錯誤。
貢獻者#
共有 23 人為本次釋出貢獻了補丁。名字旁有“+”的人是首次貢獻補丁。
Aaron Staple +
Andrew Rosenfeld
Anton I. Sipos
Artemy Kolchinsky
Bill Letson +
Dave Hughes +
David Stephens
Guillaume Horel +
Jeff Reback
Joris Van den Bossche
Kevin Sheppard
Nick Stahl +
Sanghee Kim +
Stephan Hoyer
Tom Augspurger
TomAugspurger
WANG Aiyong +
behzad nouri
immerrr
jnmclarty
jreback
pallav-fdsi +
unutbu