Skip to content

Commit a9caea4

Browse files
committed
format
1 parent 4548266 commit a9caea4

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

gokart/file_processor.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
DATAFRAME_FRAMEWORK = 'pandas'
3030

3131

32-
class FileProcessor(object):
32+
class FileProcessor:
3333
@abstractmethod
3434
def format(self):
3535
pass
@@ -139,11 +139,10 @@ def __init__(self, sep=',', encoding: str = 'utf-8'):
139139
def format(self):
140140
return TextFormat(encoding=self._encoding)
141141

142-
def load(self, file):
143-
...
142+
def load(self, file): ...
143+
144+
def dump(self, obj, file): ...
144145

145-
def dump(self, obj, file):
146-
...
147146

148147
class PolarsCsvFileProcessor(CsvFileProcessor):
149148
def load(self, file):
@@ -191,11 +190,9 @@ def __init__(self, orient: str | None = None):
191190
def format(self):
192191
return luigi.format.Nop
193192

194-
def load(self, file):
195-
...
193+
def load(self, file): ...
196194

197-
def dump(self, obj, file):
198-
...
195+
def dump(self, obj, file): ...
199196

200197

201198
class PolarsJsonFileProcessor(JsonFileProcessor):
@@ -215,7 +212,7 @@ def dump(self, obj, file):
215212
obj = pl.from_dict(obj)
216213

217214
if self._orient == 'records':
218-
obj_write_ndjson(file)
215+
obj.write_ndjson(file)
219216
else:
220217
obj.write_json(file)
221218

@@ -272,11 +269,10 @@ def __init__(self, engine='pyarrow', compression=None):
272269
def format(self):
273270
return luigi.format.Nop
274271

275-
def load(self, file):
276-
...
272+
def load(self, file): ...
273+
274+
def dump(self, obj, file): ...
277275

278-
def dump(self, obj, file):
279-
...
280276

281277
class PolarsParquetFileProcessor(ParquetFileProcessor):
282278
def load(self, file):
@@ -314,20 +310,17 @@ def __init__(self, store_index_in_feather: bool):
314310
def format(self):
315311
return luigi.format.Nop
316312

317-
def load(self, file):
318-
...
313+
def load(self, file): ...
319314

320-
def dump(self, obj, file):
321-
...
315+
def dump(self, obj, file): ...
322316

323317

324318
class PolarsFeatherFileProcessor(FeatherFileProcessor):
325319
def load(self, file):
326320
# Since polars' DataFrame doesn't have index, just load feather file
327321
if ObjectStorage.is_buffered_reader(file):
328-
loaded_df = pl.read_ipc(file.name)
329-
else:
330-
loaded_df = pl.read_ipc(BytesIO(file.read()))
322+
return pl.read_ipc(file.name)
323+
return pl.read_ipc(BytesIO(file.read()))
331324

332325
def dump(self, obj, file):
333326
assert isinstance(obj, (pl.DataFrame)), f'requires pl.DataFrame, but {type(obj)} is passed.'
@@ -388,6 +381,7 @@ def dump(self, obj, file):
388381
ParquetFileProcessor = PandasParquetFileProcessor
389382
FeatherFileProcessor = PandasFeatherFileProcessor
390383

384+
391385
def make_file_processor(file_path: str, store_index_in_feather: bool) -> FileProcessor:
392386
extension2processor = {
393387
'.txt': TextFileProcessor(),

0 commit comments

Comments
 (0)