41
41
from pandas .compat import (range , zip , lrange , lmap , lzip , StringIO , u ,
42
42
OrderedDict , raise_with_traceback )
43
43
from pandas import compat
44
- from pandas .util .decorators import deprecate , Appender , Substitution
44
+ from pandas .util .decorators import deprecate , Appender , Substitution , \
45
+ deprecate_kwarg
45
46
46
47
from pandas .tseries .period import PeriodIndex
47
48
from pandas .tseries .index import DatetimeIndex
@@ -1067,8 +1068,9 @@ def to_panel(self):
1067
1068
1068
1069
to_wide = deprecate ('to_wide' , to_panel )
1069
1070
1071
+ @deprecate_kwarg (old_arg_name = 'cols' , new_arg_name = 'columns' )
1070
1072
def to_csv (self , path_or_buf = None , sep = "," , na_rep = '' , float_format = None ,
1071
- cols = None , header = True , index = True , index_label = None ,
1073
+ columns = None , header = True , index = True , index_label = None ,
1072
1074
mode = 'w' , nanRep = None , encoding = None , quoting = None ,
1073
1075
quotechar = '"' , line_terminator = '\n ' , chunksize = None ,
1074
1076
tupleize_cols = False , date_format = None , doublequote = True ,
@@ -1086,7 +1088,7 @@ def to_csv(self, path_or_buf=None, sep=",", na_rep='', float_format=None,
1086
1088
Missing data representation
1087
1089
float_format : string, default None
1088
1090
Format string for floating point numbers
1089
- cols : sequence, optional
1091
+ columns : sequence, optional
1090
1092
Columns to write
1091
1093
header : boolean or list of string, default True
1092
1094
Write out column names. If a list of string is given it is assumed
@@ -1124,6 +1126,7 @@ def to_csv(self, path_or_buf=None, sep=",", na_rep='', float_format=None,
1124
1126
or new (expanded format) if False)
1125
1127
date_format : string, default None
1126
1128
Format string for datetime objects
1129
+ cols : kwarg only alias of columns [deprecated]
1127
1130
"""
1128
1131
if nanRep is not None : # pragma: no cover
1129
1132
warnings .warn ("nanRep is deprecated, use na_rep" ,
@@ -1134,7 +1137,7 @@ def to_csv(self, path_or_buf=None, sep=",", na_rep='', float_format=None,
1134
1137
line_terminator = line_terminator ,
1135
1138
sep = sep , encoding = encoding ,
1136
1139
quoting = quoting , na_rep = na_rep ,
1137
- float_format = float_format , cols = cols ,
1140
+ float_format = float_format , cols = columns ,
1138
1141
header = header , index = index ,
1139
1142
index_label = index_label , mode = mode ,
1140
1143
chunksize = chunksize , quotechar = quotechar ,
@@ -1148,8 +1151,9 @@ def to_csv(self, path_or_buf=None, sep=",", na_rep='', float_format=None,
1148
1151
if path_or_buf is None :
1149
1152
return formatter .path_or_buf .getvalue ()
1150
1153
1154
+ @deprecate_kwarg (old_arg_name = 'cols' , new_arg_name = 'columns' )
1151
1155
def to_excel (self , excel_writer , sheet_name = 'Sheet1' , na_rep = '' ,
1152
- float_format = None , cols = None , header = True , index = True ,
1156
+ float_format = None , columns = None , header = True , index = True ,
1153
1157
index_label = None , startrow = 0 , startcol = 0 , engine = None ,
1154
1158
merge_cells = True , encoding = None ):
1155
1159
"""
@@ -1189,6 +1193,7 @@ def to_excel(self, excel_writer, sheet_name='Sheet1', na_rep='',
1189
1193
encoding: string, default None
1190
1194
encoding of the resulting excel file. Only necessary for xlwt,
1191
1195
other writers support unicode natively.
1196
+ cols : kwarg only alias of columns [deprecated]
1192
1197
1193
1198
Notes
1194
1199
-----
@@ -1202,6 +1207,7 @@ def to_excel(self, excel_writer, sheet_name='Sheet1', na_rep='',
1202
1207
>>> writer.save()
1203
1208
"""
1204
1209
from pandas .io .excel import ExcelWriter
1210
+
1205
1211
need_save = False
1206
1212
if encoding == None :
1207
1213
encoding = 'ascii'
@@ -1212,7 +1218,7 @@ def to_excel(self, excel_writer, sheet_name='Sheet1', na_rep='',
1212
1218
1213
1219
formatter = fmt .ExcelFormatter (self ,
1214
1220
na_rep = na_rep ,
1215
- cols = cols ,
1221
+ cols = columns ,
1216
1222
header = header ,
1217
1223
float_format = float_format ,
1218
1224
index = index ,
@@ -2439,27 +2445,28 @@ def dropna(self, axis=0, how='any', thresh=None, subset=None,
2439
2445
else :
2440
2446
return result
2441
2447
2442
- def drop_duplicates (self , cols = None , take_last = False , inplace = False ):
2448
+ @deprecate_kwarg (old_arg_name = 'cols' , new_arg_name = 'subset' )
2449
+ def drop_duplicates (self , subset = None , take_last = False , inplace = False ):
2443
2450
"""
2444
2451
Return DataFrame with duplicate rows removed, optionally only
2445
2452
considering certain columns
2446
2453
2447
2454
Parameters
2448
2455
----------
2449
- cols : column label or sequence of labels, optional
2456
+ subset : column label or sequence of labels, optional
2450
2457
Only consider certain columns for identifying duplicates, by
2451
2458
default use all of the columns
2452
2459
take_last : boolean, default False
2453
2460
Take the last observed row in a row. Defaults to the first row
2454
2461
inplace : boolean, default False
2455
2462
Whether to drop duplicates in place or to return a copy
2463
+ cols : kwargs only argument of subset [deprecated]
2456
2464
2457
2465
Returns
2458
2466
-------
2459
2467
deduplicated : DataFrame
2460
2468
"""
2461
-
2462
- duplicated = self .duplicated (cols , take_last = take_last )
2469
+ duplicated = self .duplicated (subset , take_last = take_last )
2463
2470
2464
2471
if inplace :
2465
2472
inds , = (- duplicated ).nonzero ()
@@ -2468,18 +2475,20 @@ def drop_duplicates(self, cols=None, take_last=False, inplace=False):
2468
2475
else :
2469
2476
return self [- duplicated ]
2470
2477
2471
- def duplicated (self , cols = None , take_last = False ):
2478
+ @deprecate_kwarg (old_arg_name = 'cols' , new_arg_name = 'subset' )
2479
+ def duplicated (self , subset = None , take_last = False ):
2472
2480
"""
2473
2481
Return boolean Series denoting duplicate rows, optionally only
2474
2482
considering certain columns
2475
2483
2476
2484
Parameters
2477
2485
----------
2478
- cols : column label or sequence of labels, optional
2486
+ subset : column label or sequence of labels, optional
2479
2487
Only consider certain columns for identifying duplicates, by
2480
2488
default use all of the columns
2481
2489
take_last : boolean, default False
2482
2490
Take the last observed row in a row. Defaults to the first row
2491
+ cols : kwargs only argument of subset [deprecated]
2483
2492
2484
2493
Returns
2485
2494
-------
@@ -2491,19 +2500,19 @@ def _m8_to_i8(x):
2491
2500
return x .view (np .int64 )
2492
2501
return x
2493
2502
2494
- if cols is None :
2503
+ if subset is None :
2495
2504
values = list (_m8_to_i8 (self .values .T ))
2496
2505
else :
2497
- if np .iterable (cols ) and not isinstance (cols , compat .string_types ):
2498
- if isinstance (cols , tuple ):
2499
- if cols in self .columns :
2500
- values = [self [cols ].values ]
2506
+ if np .iterable (subset ) and not isinstance (subset , compat .string_types ):
2507
+ if isinstance (subset , tuple ):
2508
+ if subset in self .columns :
2509
+ values = [self [subset ].values ]
2501
2510
else :
2502
- values = [_m8_to_i8 (self [x ].values ) for x in cols ]
2511
+ values = [_m8_to_i8 (self [x ].values ) for x in subset ]
2503
2512
else :
2504
- values = [_m8_to_i8 (self [x ].values ) for x in cols ]
2513
+ values = [_m8_to_i8 (self [x ].values ) for x in subset ]
2505
2514
else :
2506
- values = [self [cols ].values ]
2515
+ values = [self [subset ].values ]
2507
2516
2508
2517
keys = lib .fast_zip_fillna (values )
2509
2518
duplicated = lib .duplicated (keys , take_last = take_last )
0 commit comments