Skip to content

Commit 67a4205

Browse files
committed
CLN: Call to_frame and return None explicitly
- There is already a method which constructs a DataFrame from a Series: to_frame. - There is no reason to check if result is None. In case result is None, simply return None explicitly.
1 parent 3da2bf8 commit 67a4205

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

pandas/core/series.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,9 +2921,9 @@ def to_csv(self, path_or_buf=None, index=True, sep=",", na_rep='',
29212921
Additional keyword arguments are passed to
29222922
:func:`pandas.DataFrame.to_csv`
29232923
"""
2924-
from pandas.core.frame import DataFrame
2925-
df = DataFrame(self)
29262924

2925+
# convert to DataFrame
2926+
df = self.to_frame()
29272927
# ensure backwards compatibility with path argument
29282928
path_or_buf = kwargs.pop('path', path_or_buf)
29292929
# result is only a string if no path_or_buf provided, otherwise None
@@ -2932,8 +2932,7 @@ def to_csv(self, path_or_buf=None, index=True, sep=",", na_rep='',
29322932
index_label=index_label, mode=mode,
29332933
encoding=encoding, compression=compression,
29342934
date_format=date_format, decimal=decimal, **kwargs)
2935-
if path is None:
2936-
return result
2935+
return result
29372936

29382937
@Appender(generic._shared_docs['to_excel'] % _shared_doc_kwargs)
29392938
def to_excel(self, excel_writer, sheet_name='Sheet1', na_rep='',

0 commit comments

Comments
 (0)