@@ -3760,56 +3760,138 @@ 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.
3775
3829
na_rep : string, default ''
3776
3830
Missing data representation
3777
3831
float_format : string, default None
3778
3832
Format string for floating point numbers
3779
3833
header : boolean, default False
3780
- Write out series name
3834
+ Write out Series name.
3781
3835
index : boolean, default True
3782
3836
Write row names (index)
3783
3837
index_label : string or sequence, default None
3784
3838
Column label for index column(s) if desired. If None is given, and
3785
3839
`header` and `index` are True, then the index names are used. A
3786
3840
sequence should be given if the DataFrame uses MultiIndex.
3787
- mode : Python write mode, default 'w'
3788
- sep : character, default ","
3841
+ mode : str, default 'w'
3842
+ Python write mode
3843
+ sep : character, default ','
3789
3844
Field delimiter for the output file.
3790
3845
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.
3846
+ A string representing the encoding to use in the output file,
3847
+ defaults to ' ascii' on Python 2 and 'utf-8' on Python 3.
3848
+ compression : {'infer', 'gzip', 'bz2', 'xz', None}, default None
3849
+ If 'infer' and `path_or_buf` is path-like, then detect compression
3850
+ from the following extensions: '.gz ', '. bz2' or '. xz'
3851
+ (otherwise no compression) .
3852
+ date_format : string, default None
3853
+ Format string for datetime objects
3799
3854
decimal: string, default '.'
3800
3855
Character recognized as decimal separator. E.g. use ',' for
3801
3856
European data
3857
+ columns : sequence, optional
3858
+ Columns to write
3859
+ quoting : optional constant from csv module
3860
+ defaults to csv.QUOTE_MINIMAL. If you have set a `float_format`
3861
+ then floats are converted to strings and thus csv.QUOTE_NONNUMERIC
3862
+ will treat them as non-numeric
3863
+ quotechar : string (length 1), default '\"'
3864
+ character used to quote fields
3865
+ line_terminator : string, default ``'\n'``
3866
+ The newline character or character sequence to use in the output
3867
+ file
3868
+ chunksize : int or None
3869
+ rows to write at a time
3870
+ doublequote : boolean, default True
3871
+ Control quoting of `quotechar` inside a field
3872
+ escapechar : string (length 1), default None
3873
+ character used to escape `sep` and `quotechar` when appropriate
3874
+ path : string or file handle
3875
+ .. deprecated:: 0.21.0
3876
+ use `path_or_buf` instead
3877
+
3802
3878
"""
3879
+
3803
3880
from pandas .core .frame import DataFrame
3804
3881
df = DataFrame (self )
3805
3882
# 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
3883
+ result = df .to_csv (
3884
+ path_or_buf , index = index , sep = sep , na_rep = na_rep ,
3885
+ float_format = float_format , header = header ,
3886
+ index_label = index_label , mode = mode , encoding = encoding ,
3887
+ compression = compression , date_format = date_format ,
3888
+ decimal = decimal , columns = columns , quoting = quoting ,
3889
+ quotechar = quotechar , line_terminator = line_terminator ,
3890
+ chunksize = chunksize , doublequote = doublequote ,
3891
+ escapechar = escapechar ,
3892
+ )
3893
+
3894
+ return result
3813
3895
3814
3896
@Appender (generic ._shared_docs ['to_excel' ] % _shared_doc_kwargs )
3815
3897
def to_excel (self , excel_writer , sheet_name = 'Sheet1' , na_rep = '' ,
0 commit comments