@@ -5,12 +5,6 @@ v0.19.0 (October 2, 2016)
5
5
6
6
{{ header }}
7
7
8
- .. ipython :: python
9
- :suppress:
10
-
11
- from pandas import * # noqa F401, F403
12
-
13
-
14
8
This is a major release from 0.18.1 and includes number of API changes, several new features,
15
9
enhancements, and performance improvements along with a large number of bug fixes. We recommend that all
16
10
users upgrade to this version.
@@ -105,9 +99,8 @@ This also illustrates using the ``by`` parameter to group data before merging.
105
99
' 20160525 13:30:00.049' ,
106
100
' 20160525 13:30:00.072' ,
107
101
' 20160525 13:30:00.075' ]),
108
- ' ticker' : [' GOOG' , ' MSFT' , ' MSFT' ,
109
- ' MSFT' , ' GOOG' , ' AAPL' , ' GOOG' ,
110
- ' MSFT' ],
102
+ ' ticker' : [' GOOG' , ' MSFT' , ' MSFT' , ' MSFT' ,
103
+ ' GOOG' , ' AAPL' , ' GOOG' , ' MSFT' ],
111
104
' bid' : [720.50 , 51.95 , 51.97 , 51.99 ,
112
105
720.50 , 97.99 , 720.50 , 52.01 ],
113
106
' ask' : [720.93 , 51.96 , 51.98 , 52.00 ,
@@ -143,7 +136,8 @@ See the full documentation :ref:`here <stats.moments.ts>`.
143
136
.. ipython :: python
144
137
145
138
dft = pd.DataFrame({' B' : [0 , 1 , 2 , np.nan, 4 ]},
146
- index = pd.date_range(' 20130101 09:00:00' , periods = 5 , freq = ' s' ))
139
+ index = pd.date_range(' 20130101 09:00:00' ,
140
+ periods = 5 , freq = ' s' ))
147
141
dft
148
142
149
143
This is a regular frequency index. Using an integer window parameter works to roll along the window frequency.
@@ -164,13 +158,13 @@ Using a non-regular, but still monotonic index, rolling with an integer window d
164
158
.. ipython :: python
165
159
166
160
167
- dft = DataFrame({' B' : [0 , 1 , 2 , np.nan, 4 ]},
168
- index = pd.Index([pd.Timestamp(' 20130101 09:00:00' ),
169
- pd.Timestamp(' 20130101 09:00:02' ),
170
- pd.Timestamp(' 20130101 09:00:03' ),
171
- pd.Timestamp(' 20130101 09:00:05' ),
172
- pd.Timestamp(' 20130101 09:00:06' )],
173
- name = ' foo' ))
161
+ dft = pd. DataFrame({' B' : [0 , 1 , 2 , np.nan, 4 ]},
162
+ index = pd.Index([pd.Timestamp(' 20130101 09:00:00' ),
163
+ pd.Timestamp(' 20130101 09:00:02' ),
164
+ pd.Timestamp(' 20130101 09:00:03' ),
165
+ pd.Timestamp(' 20130101 09:00:05' ),
166
+ pd.Timestamp(' 20130101 09:00:06' )],
167
+ name = ' foo' ))
174
168
175
169
dft
176
170
dft.rolling(2 ).sum()
@@ -277,10 +271,10 @@ Categorical Concatenation
277
271
278
272
.. ipython :: python
279
273
280
- from pandas.api.types import union_categoricals
281
- a = pd.Categorical([" b" , " c" ])
282
- b = pd.Categorical([" a" , " b" ])
283
- union_categoricals([a, b])
274
+ from pandas.api.types import union_categoricals
275
+ a = pd.Categorical([" b" , " c" ])
276
+ b = pd.Categorical([" a" , " b" ])
277
+ union_categoricals([a, b])
284
278
285
279
- ``concat `` and ``append `` now can concat ``category `` dtypes with different ``categories `` as ``object `` dtype (:issue: `13524 `)
286
280
@@ -289,18 +283,18 @@ Categorical Concatenation
289
283
s1 = pd.Series([' a' , ' b' ], dtype = ' category' )
290
284
s2 = pd.Series([' b' , ' c' ], dtype = ' category' )
291
285
292
- **Previous behavior **:
286
+ **Previous behavior **:
293
287
294
- .. code-block :: ipython
288
+ .. code-block :: ipython
295
289
296
- In [1]: pd.concat([s1, s2])
297
- ValueError: incompatible categories in categorical concat
290
+ In [1]: pd.concat([s1, s2])
291
+ ValueError: incompatible categories in categorical concat
298
292
299
- **New behavior **:
293
+ **New behavior **:
300
294
301
- .. ipython :: python
295
+ .. ipython :: python
302
296
303
- pd.concat([s1, s2])
297
+ pd.concat([s1, s2])
304
298
305
299
.. _whatsnew_0190.enhancements.semi_month_offsets :
306
300
@@ -313,31 +307,31 @@ These provide date offsets anchored (by default) to the 15th and end of month, a
313
307
314
308
.. ipython :: python
315
309
316
- from pandas.tseries.offsets import SemiMonthEnd, SemiMonthBegin
310
+ from pandas.tseries.offsets import SemiMonthEnd, SemiMonthBegin
317
311
318
312
**SemiMonthEnd **:
319
313
320
314
.. ipython :: python
321
315
322
- Timestamp(' 2016-01-01' ) + SemiMonthEnd()
316
+ pd. Timestamp(' 2016-01-01' ) + SemiMonthEnd()
323
317
324
- pd.date_range(' 2015-01-01' , freq = ' SM' , periods = 4 )
318
+ pd.date_range(' 2015-01-01' , freq = ' SM' , periods = 4 )
325
319
326
320
**SemiMonthBegin **:
327
321
328
322
.. ipython :: python
329
323
330
- Timestamp(' 2016-01-01' ) + SemiMonthBegin()
324
+ pd. Timestamp(' 2016-01-01' ) + SemiMonthBegin()
331
325
332
- pd.date_range(' 2015-01-01' , freq = ' SMS' , periods = 4 )
326
+ pd.date_range(' 2015-01-01' , freq = ' SMS' , periods = 4 )
333
327
334
328
Using the anchoring suffix, you can also specify the day of month to use instead of the 15th.
335
329
336
330
.. ipython :: python
337
331
338
- pd.date_range(' 2015-01-01' , freq = ' SMS-16' , periods = 4 )
332
+ pd.date_range(' 2015-01-01' , freq = ' SMS-16' , periods = 4 )
339
333
340
- pd.date_range(' 2015-01-01' , freq = ' SM-14' , periods = 4 )
334
+ pd.date_range(' 2015-01-01' , freq = ' SM-14' , periods = 4 )
341
335
342
336
.. _whatsnew_0190.enhancements.index :
343
337
@@ -367,7 +361,7 @@ For ``MultiIndex``, values are dropped if any level is missing by default. Speci
367
361
.. ipython :: python
368
362
369
363
midx = pd.MultiIndex.from_arrays([[1 , 2 , np.nan, 4 ],
370
- [1 , 2 , np.nan, np.nan]])
364
+ [1 , 2 , np.nan, np.nan]])
371
365
midx
372
366
midx.dropna()
373
367
midx.dropna(how = ' all' )
@@ -377,7 +371,7 @@ For ``MultiIndex``, values are dropped if any level is missing by default. Speci
377
371
.. ipython :: python
378
372
379
373
idx = pd.Index([" a1a2" , " b1" , " c1" ])
380
- idx.str.extractall(" [ab](?P<digit>\d)" )
374
+ idx.str.extractall(r " [ab ]( ?P<digit> \d ) " )
381
375
382
376
``Index.astype() `` now accepts an optional boolean argument ``copy ``, which allows optional copying if the requirements on dtype are satisfied (:issue: `13209 `)
383
377
@@ -453,7 +447,7 @@ The following are now part of this API:
453
447
454
448
import pprint
455
449
from pandas.api import types
456
- funcs = [ f for f in dir (types) if not f.startswith(' _' ) ]
450
+ funcs = [f for f in dir (types) if not f.startswith(' _' )]
457
451
pprint.pprint(funcs)
458
452
459
453
.. note ::
@@ -470,20 +464,21 @@ Other enhancements
470
464
471
465
.. ipython :: python
472
466
473
- pd.Timestamp(2012 , 1 , 1 )
467
+ pd.Timestamp(2012 , 1 , 1 )
474
468
475
- pd.Timestamp(year = 2012 , month = 1 , day = 1 , hour = 8 , minute = 30 )
469
+ pd.Timestamp(year = 2012 , month = 1 , day = 1 , hour = 8 , minute = 30 )
476
470
477
471
- The ``.resample() `` function now accepts a ``on= `` or ``level= `` parameter for resampling on a datetimelike column or ``MultiIndex `` level (:issue: `13500 `)
478
472
479
473
.. ipython :: python
480
474
481
475
df = pd.DataFrame({' date' : pd.date_range(' 2015-01-01' , freq = ' W' , periods = 5 ),
482
476
' a' : np.arange(5 )},
483
- index = pd.MultiIndex.from_arrays([
484
- [1 ,2 ,3 ,4 ,5 ],
485
- pd.date_range(' 2015-01-01' , freq = ' W' , periods = 5 )],
486
- names = [' v' ,' d' ]))
477
+ index = pd.MultiIndex.from_arrays([[1 , 2 , 3 , 4 , 5 ],
478
+ pd.date_range(' 2015-01-01' ,
479
+ freq = ' W' ,
480
+ periods = 5 )
481
+ ], names = [' v' , ' d' ]))
487
482
df
488
483
df.resample(' M' , on = ' date' ).sum()
489
484
df.resample(' M' , level = ' d' ).sum()
@@ -547,7 +542,7 @@ API changes
547
542
548
543
.. ipython :: python
549
544
550
- s = pd.Series([1 ,2 , 3 ])
545
+ s = pd.Series([1 , 2 , 3 ])
551
546
552
547
**Previous behavior **:
553
548
@@ -953,7 +948,7 @@ of integers (:issue:`13988`).
953
948
954
949
In [6]: pi = pd.PeriodIndex(['2011-01', '2011-02'], freq='M')
955
950
In [7]: pi.values
956
- array([492, 493])
951
+ Out[7]: array([492, 493])
957
952
958
953
**New behavior **:
959
954
@@ -981,23 +976,23 @@ Previous behavior:
981
976
982
977
.. code-block :: ipython
983
978
984
- In [1]: pd.Index(['a', 'b']) + pd.Index(['a', 'c'])
985
- FutureWarning: using '+' to provide set union with Indexes is deprecated, use '|' or .union()
986
- Out[1]: Index(['a', 'b', 'c'], dtype='object')
979
+ In [1]: pd.Index(['a', 'b']) + pd.Index(['a', 'c'])
980
+ FutureWarning: using '+' to provide set union with Indexes is deprecated, use '|' or .union()
981
+ Out[1]: Index(['a', 'b', 'c'], dtype='object')
987
982
988
983
**New behavior **: the same operation will now perform element-wise addition:
989
984
990
985
.. ipython :: python
991
986
992
- pd.Index([' a' , ' b' ]) + pd.Index([' a' , ' c' ])
987
+ pd.Index([' a' , ' b' ]) + pd.Index([' a' , ' c' ])
993
988
994
989
Note that numeric Index objects already performed element-wise operations.
995
990
For example, the behavior of adding two integer Indexes is unchanged.
996
991
The base ``Index `` is now made consistent with this behavior.
997
992
998
993
.. ipython :: python
999
994
1000
- pd.Index([1 , 2 , 3 ]) + pd.Index([2 , 3 , 4 ])
995
+ pd.Index([1 , 2 , 3 ]) + pd.Index([2 , 3 , 4 ])
1001
996
1002
997
Further, because of this change, it is now possible to subtract two
1003
998
DatetimeIndex objects resulting in a TimedeltaIndex:
@@ -1006,15 +1001,17 @@ DatetimeIndex objects resulting in a TimedeltaIndex:
1006
1001
1007
1002
.. code-block :: ipython
1008
1003
1009
- In [1]: pd.DatetimeIndex(['2016-01-01', '2016-01-02']) - pd.DatetimeIndex(['2016-01-02', '2016-01-03'])
1004
+ In [1]: (pd.DatetimeIndex(['2016-01-01', '2016-01-02'])
1005
+ ...: - pd.DatetimeIndex(['2016-01-02', '2016-01-03']))
1010
1006
FutureWarning: using '-' to provide set differences with datetimelike Indexes is deprecated, use .difference()
1011
1007
Out[1]: DatetimeIndex(['2016-01-01'], dtype='datetime64[ns]', freq=None)
1012
1008
1013
1009
**New behavior **:
1014
1010
1015
1011
.. ipython :: python
1016
1012
1017
- pd.DatetimeIndex([' 2016-01-01' , ' 2016-01-02' ]) - pd.DatetimeIndex([' 2016-01-02' , ' 2016-01-03' ])
1013
+ (pd.DatetimeIndex([' 2016-01-01' , ' 2016-01-02' ])
1014
+ - pd.DatetimeIndex([' 2016-01-02' , ' 2016-01-03' ]))
1018
1015
1019
1016
1020
1017
.. _whatsnew_0190.api.difference :
@@ -1063,7 +1060,8 @@ Previously, most ``Index`` classes returned ``np.ndarray``, and ``DatetimeIndex`
1063
1060
In [1]: pd.Index([1, 2, 3]).unique()
1064
1061
Out[1]: array([1, 2, 3])
1065
1062
1066
- In [2]: pd.DatetimeIndex(['2011-01-01', '2011-01-02', '2011-01-03'], tz='Asia/Tokyo').unique()
1063
+ In [2]: pd.DatetimeIndex(['2011-01-01', '2011-01-02',
1064
+ ...: '2011-01-03'], tz='Asia/Tokyo').unique()
1067
1065
Out[2]:
1068
1066
DatetimeIndex(['2011-01-01 00:00:00+09:00', '2011-01-02 00:00:00+09:00',
1069
1067
'2011-01-03 00:00:00+09:00'],
@@ -1074,7 +1072,8 @@ Previously, most ``Index`` classes returned ``np.ndarray``, and ``DatetimeIndex`
1074
1072
.. ipython :: python
1075
1073
1076
1074
pd.Index([1 , 2 , 3 ]).unique()
1077
- pd.DatetimeIndex([' 2011-01-01' , ' 2011-01-02' , ' 2011-01-03' ], tz = ' Asia/Tokyo' ).unique()
1075
+ pd.DatetimeIndex([' 2011-01-01' , ' 2011-01-02' , ' 2011-01-03' ],
1076
+ tz = ' Asia/Tokyo' ).unique()
1078
1077
1079
1078
.. _whatsnew_0190.api.multiindex :
1080
1079
@@ -1236,29 +1235,29 @@ Operators now preserve dtypes
1236
1235
1237
1236
- Sparse data structure now can preserve ``dtype `` after arithmetic ops (:issue: `13848 `)
1238
1237
1239
- .. ipython :: python
1238
+ .. ipython :: python
1240
1239
1241
- s = pd.SparseSeries([0 , 2 , 0 , 1 ], fill_value = 0 , dtype = np.int64)
1242
- s.dtype
1240
+ s = pd.SparseSeries([0 , 2 , 0 , 1 ], fill_value = 0 , dtype = np.int64)
1241
+ s.dtype
1243
1242
1244
- s + 1
1243
+ s + 1
1245
1244
1246
1245
- Sparse data structure now support ``astype `` to convert internal ``dtype `` (:issue: `13900 `)
1247
1246
1248
- .. ipython :: python
1247
+ .. ipython :: python
1249
1248
1250
- s = pd.SparseSeries([1 ., 0 ., 2 ., 0 .], fill_value = 0 )
1251
- s
1252
- s.astype(np.int64)
1249
+ s = pd.SparseSeries([1 ., 0 ., 2 ., 0 .], fill_value = 0 )
1250
+ s
1251
+ s.astype(np.int64)
1253
1252
1254
1253
`` astype`` fails if data contains values which cannot be converted to specified `` dtype`` .
1255
1254
Note that the limitation is applied to `` fill_value`` which default is `` np.nan`` .
1256
1255
1257
- .. code-block :: ipython
1256
+ .. code-block :: ipython
1258
1257
1259
- In [7]: pd.SparseSeries([1., np.nan, 2., np.nan], fill_value=np.nan).astype(np.int64)
1260
- Out[7]:
1261
- ValueError: unable to coerce current fill_value nan to int64 dtype
1258
+ In [7]: pd.SparseSeries([1., np.nan, 2., np.nan], fill_value=np.nan).astype(np.int64)
1259
+ Out[7]:
1260
+ ValueError: unable to coerce current fill_value nan to int64 dtype
1262
1261
1263
1262
Other sparse fixes
1264
1263
""""""""""""""""""
0 commit comments