Skip to content

Commit f4cbfdf

Browse files
authored
Merge pull request #74 from swen128/fix-csv-processor
let CsvFileProcessor.dump accepts a pd.Series argument
2 parents c819f8e + 7158e07 commit f4cbfdf

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

gokart/file_processor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ def load(self, file):
104104
return pd.DataFrame()
105105

106106
def dump(self, obj, file):
107-
assert isinstance(obj, pd.DataFrame), f'requires pd.DataFrame, but {type(obj)} is passed.'
108-
obj.to_csv(file, index=False, sep=self._sep)
107+
assert isinstance(obj, (pd.DataFrame, pd.Series)), \
108+
f'requires pd.DataFrame or pd.Series, but {type(obj)} is passed.'
109+
obj.to_csv(file, index=False, sep=self._sep, header=True)
109110

110111

111112
class GzipFileProcessor(FileProcessor):

test/test_target.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ def test_last_modified_time_without_file(self):
8383
with self.assertRaises(FileNotFoundError):
8484
target.last_modification_time()
8585

86+
def test_save_pandas_series(self):
87+
obj = pd.Series(data=[1, 2], name='column_name')
88+
file_path = os.path.join(_get_temporary_directory(), 'test.csv')
89+
90+
target = make_target(file_path=file_path, unique_id=None)
91+
target.dump(obj)
92+
loaded = target.load()
93+
94+
pd.testing.assert_series_equal(loaded['column_name'], obj)
95+
8696

8797
class S3TargetTest(unittest.TestCase):
8898
@mock_s3

0 commit comments

Comments
 (0)