@@ -3764,19 +3764,25 @@ def from_csv(cls, path, sep=',', parse_dates=True, header=None,
3764
3764
return result
3765
3765
3766
3766
def to_csv (self , * args , ** kwargs ):
3767
- names = ['path_or_buf' , 'sep' , 'na_rep' , 'float_format' , 'columns' ,
3768
- 'header' , 'index' , 'index_label' , 'mode' , 'encoding' ,
3769
- 'compression' , 'quoting' , 'quotechar' , 'line_terminator' ,
3770
- 'chunksize' , 'tupleize_cols' , 'date_format' , 'doublequote' ,
3771
- 'escapechar' , 'decimal' ]
3772
-
3773
- old_names = ['path_or_buf' , 'index' , 'sep' , 'na_rep' , 'float_format' ,
3774
- 'header' , 'index_label' , 'mode' , 'encoding' ,
3775
- 'compression' , 'date_format' , 'decimal' ]
3776
-
3777
- if 'path' in kwargs :
3778
- warnings .warn ("Argument 'path' is now named 'path_or_buf'" )
3779
- kwargs ['path_or_buf' ] = kwargs .pop ('path' )
3767
+ warning_klass = FutureWarning
3768
+ stack_level = 2
3769
+
3770
+ names = ["path_or_buf" , "sep" , "na_rep" , "float_format" , "columns" ,
3771
+ "header" , "index" , "index_label" , "mode" , "encoding" ,
3772
+ "compression" , "quoting" , "quotechar" , "line_terminator" ,
3773
+ "chunksize" , "tupleize_cols" , "date_format" , "doublequote" ,
3774
+ "escapechar" , "decimal" ]
3775
+
3776
+ old_names = ["path_or_buf" , "index" , "sep" , "na_rep" , "float_format" ,
3777
+ "header" , "index_label" , "mode" , "encoding" ,
3778
+ "compression" , "date_format" , "decimal" ]
3779
+
3780
+ if "path" in kwargs :
3781
+ warnings .warn ("The signature of `Series.to_csv` was aligned "
3782
+ "to that of `DataFrame.to_csv`, and argument "
3783
+ "'path' will be renamed to 'path_or_buf'." ,
3784
+ warning_klass , stacklevel = stack_level )
3785
+ kwargs ["path_or_buf" ] = kwargs .pop ("path" )
3780
3786
3781
3787
if len (args ) > 1 :
3782
3788
# Either "index" (old signature) or "sep" (new signature) is being
@@ -3785,7 +3791,7 @@ def to_csv(self, *args, **kwargs):
3785
3791
3786
3792
if not (is_string_like (maybe_sep ) and len (maybe_sep ) == 1 ):
3787
3793
# old signature
3788
- warnings .warn ("The signature of `Series.to_csv` was aligned "
3794
+ warnings .warn ("The signature of `Series.to_csv` was aligned "
3789
3795
"to that of `DataFrame.to_csv`. Note that the "
3790
3796
"order of arguments changed, and the new one "
3791
3797
"has 'sep' in first place, for which \" {}\" is "
@@ -3794,7 +3800,7 @@ def to_csv(self, *args, **kwargs):
3794
3800
"to the documentation for `DataFrame.to_csv` "
3795
3801
"when updating your function "
3796
3802
"calls." .format (maybe_sep ),
3797
- FutureWarning , stacklevel = 2 )
3803
+ warning_klass , stacklevel = stack_level )
3798
3804
names = old_names
3799
3805
3800
3806
pos_args = dict (zip (names [:len (args )], args ))
@@ -3805,11 +3811,14 @@ def to_csv(self, *args, **kwargs):
3805
3811
"({})" .format (key , names .index (key )))
3806
3812
kwargs [key ] = pos_args [key ]
3807
3813
3808
- if kwargs .get ('header' , None ) is None :
3809
- warnings .warn ("Argument 'header' has changed default value to "
3814
+ if kwargs .get ("header" , None ) is None :
3815
+ warnings .warn ("The signature of `Series.to_csv` was aligned "
3816
+ "to that of `DataFrame.to_csv`, and argument "
3817
+ "'header' will change its default value to "
3810
3818
"True: please pass an explicit value to suppress "
3811
- "this warning" )
3812
-
3819
+ "this warning." , warning_klass ,
3820
+ stacklevel = stack_level )
3821
+ kwargs ["header" ] = False # Backwards compatibility.
3813
3822
return self .to_frame ().to_csv (** kwargs )
3814
3823
3815
3824
# This entire method is going to be removed, so the shared docstring
0 commit comments