@@ -3760,56 +3760,141 @@ def from_csv(cls, path, sep=',', parse_dates=True, header=None,
3760
3760
3761
3761
return result
3762
3762
3763
- def to_csv (self , path = None , index = True , sep = "," , na_rep = '' ,
3763
+ def to_csv_deprecation_decoration (to_csv ):
3764
+ """Decorator used to deprecate the signature of to_csv."""
3765
+
3766
+ from functools import wraps
3767
+
3768
+ @wraps (to_csv )
3769
+ def _to_csv (* args , ** kwargs ):
3770
+ if len (args ) > 2 :
3771
+ warnings .warn (
3772
+ "The signature of `Series.to_csv` will be "
3773
+ "aligned to that of `DataFrame.to_csv` in the "
3774
+ "future. The ordering of positional "
3775
+ "arguments is different, so please refer "
3776
+ "to the documentation for `DataFrame.to_csv` when "
3777
+ "changing your function calls. To ensure "
3778
+ "future-proof calls, do not pass more than 1 "
3779
+ "positional argument." ,
3780
+ FutureWarning , stacklevel = 2 ,
3781
+ )
3782
+ if "path" in kwargs :
3783
+ assert len (args ) <= 1 , (
3784
+ "Cannot specify path both as positional "
3785
+ "argument and keyword argument."
3786
+ )
3787
+ assert "path_or_buf" not in kwargs , (
3788
+ "Can only specify path or path_or_buf, not both."
3789
+ )
3790
+ warnings .warn (
3791
+ "path is deprecated, use path_or_buf instead" ,
3792
+ FutureWarning , stacklevel = 2 ,
3793
+ )
3794
+ kwargs ["path_or_buf" ] = kwargs .pop ("path" )
3795
+ if "header" not in kwargs :
3796
+ warnings .warn (
3797
+ "The signature of `Series.to_csv` will be "
3798
+ "aligned to that of `DataFrame.to_csv` in the "
3799
+ "future. The default value of header will change. "
3800
+ "To keep the current behaviour, use header=False." ,
3801
+ FutureWarning , stacklevel = 2 ,
3802
+ )
3803
+ return to_csv (* args , ** kwargs )
3804
+
3805
+ return _to_csv
3806
+
3807
+ @to_csv_deprecation_decoration
3808
+ def to_csv (self , path_or_buf = None , index = True , sep = "," , na_rep = '' ,
3764
3809
float_format = None , header = False , index_label = None ,
3765
3810
mode = 'w' , encoding = None , compression = None , date_format = None ,
3766
- decimal = '.' ):
3767
- """
3768
- Write Series to a comma-separated values (csv) file
3811
+ decimal = '.' , columns = None , quoting = None , quotechar = '"' ,
3812
+ line_terminator = '\n ' , chunksize = None , doublequote = True ,
3813
+ escapechar = None ):
3814
+
3815
+ r"""Write Series to a comma-separated values (csv) file
3816
+
3817
+ .. deprecated:: 0.24.0
3818
+ The signature will aligned to that of :func:`DataFrame.to_csv`.
3819
+
3820
+ :func:`Series.to_csv` will align its signature with that of
3821
+ `DataFrame.to_csv`. Please pass in keyword arguments in accordance
3822
+ with that signature instead.
3769
3823
3770
3824
Parameters
3771
3825
----------
3772
- path : string or file handle, default None
3826
+ path_or_buf : string or file handle, default None
3773
3827
File path or object, if None is provided the result is returned as
3774
3828
a string.
3829
+ index : boolean, default True
3830
+ Write row names (index)
3831
+ sep : character, default ','
3832
+ Field delimiter for the output file.
3775
3833
na_rep : string, default ''
3776
3834
Missing data representation
3777
3835
float_format : string, default None
3778
3836
Format string for floating point numbers
3779
- header : boolean, default False
3780
- Write out series name
3781
- index : boolean, default True
3782
- Write row names (index)
3783
- index_label : string or sequence, default None
3837
+ header : boolean or list of string, default False
3838
+ Write out the column names. If a list of strings is given it is
3839
+ assumed to be aliases for the column names
3840
+ index_label : string or sequence, or False, default None
3784
3841
Column label for index column(s) if desired. If None is given, and
3785
3842
`header` and `index` are True, then the index names are used. A
3786
- sequence should be given if the DataFrame uses MultiIndex.
3787
- mode : Python write mode, default 'w'
3788
- sep : character, default ","
3789
- Field delimiter for the output file.
3843
+ sequence should be given if the DataFrame uses MultiIndex. If
3844
+ False do not print fields for index names. Use index_label=False
3845
+ for easier importing in R
3846
+ mode : str
3847
+ Python write mode, default 'w'
3790
3848
encoding : string, optional
3791
- a string representing the encoding to use if the contents are
3792
- non- ascii, for python versions prior to 3
3793
- compression : string, optional
3794
- A string representing the compression to use in the output file.
3795
- Allowed values are 'gzip ', 'bz2', 'zip', ' xz'. This input is only
3796
- used when the first argument is a filename .
3797
- date_format: string, default None
3798
- Format string for datetime objects.
3849
+ A string representing the encoding to use in the output file,
3850
+ defaults to ' ascii' on Python 2 and 'utf-8' on Python 3.
3851
+ compression : {'infer', 'gzip', 'bz2', 'xz', None}, default None
3852
+ If 'infer' and `path_or_buf` is path-like, then detect compression
3853
+ from the following extensions: '.gz ', '. bz2' or '. xz'
3854
+ (otherwise no compression) .
3855
+ date_format : string, default None
3856
+ Format string for datetime objects
3799
3857
decimal: string, default '.'
3800
3858
Character recognized as decimal separator. E.g. use ',' for
3801
3859
European data
3860
+ columns : sequence, optional
3861
+ Columns to write
3862
+ quoting : optional constant from csv module
3863
+ defaults to csv.QUOTE_MINIMAL. If you have set a `float_format`
3864
+ then floats are converted to strings and thus csv.QUOTE_NONNUMERIC
3865
+ will treat them as non-numeric
3866
+ quotechar : string (length 1), default '\"'
3867
+ character used to quote fields
3868
+ line_terminator : string, default ``'\n'``
3869
+ The newline character or character sequence to use in the output
3870
+ file
3871
+ chunksize : int or None
3872
+ rows to write at a time
3873
+ doublequote : boolean, default True
3874
+ Control quoting of `quotechar` inside a field
3875
+ escapechar : string (length 1), default None
3876
+ character used to escape `sep` and `quotechar` when appropriate
3877
+ path : string or file handle
3878
+ .. deprecated:: 0.21.0
3879
+ use `path_or_buf` instead
3880
+
3802
3881
"""
3882
+
3803
3883
from pandas .core .frame import DataFrame
3804
3884
df = DataFrame (self )
3805
3885
# result is only a string if no path provided, otherwise None
3806
- result = df .to_csv (path , index = index , sep = sep , na_rep = na_rep ,
3807
- float_format = float_format , header = header ,
3808
- index_label = index_label , mode = mode ,
3809
- encoding = encoding , compression = compression ,
3810
- date_format = date_format , decimal = decimal )
3811
- if path is None :
3812
- return result
3886
+ result = df .to_csv (
3887
+ path_or_buf , index = index , sep = sep , na_rep = na_rep ,
3888
+ float_format = float_format , header = header ,
3889
+ index_label = index_label , mode = mode , encoding = encoding ,
3890
+ compression = compression , date_format = date_format ,
3891
+ decimal = decimal , columns = columns , quoting = quoting ,
3892
+ quotechar = quotechar , line_terminator = line_terminator ,
3893
+ chunksize = chunksize , doublequote = doublequote ,
3894
+ escapechar = escapechar ,
3895
+ )
3896
+
3897
+ return result
3813
3898
3814
3899
@Appender (generic ._shared_docs ['to_excel' ] % _shared_doc_kwargs )
3815
3900
def to_excel (self , excel_writer , sheet_name = 'Sheet1' , na_rep = '' ,
0 commit comments