--OSS développé par M3 et fringe81
class DataTask(gokart.TaskOnKart):
task_namespace = 'sample'
def run(self):
df = pd.DataFrame(dict(user=[1, 2], item=['a', 'b']))
self.dump(df)
class TaskA(gokart.TaskOnKart):
task_namespace = 'sample'
def requires(self):
return DataTask()
def run(self):
df = self.load_data_frame()
#Quand df est vide`KeyError`Se produit.
df['user'] = df['user'].apply(lambda x: f'user_{x}')
self.dump(df)
if __name__ == '__main__':
gokart.run()
--test-run-pandas
et --test-run-namespace = sample
.$ python main.py sample.TaskA --local-scheduler --test-run-pandas --test-run-namespace=sample
--Message
gokart test results:
status=OK; namespace=sample; name=DataTask; id=10f87ddcf3df71d786a023ae5e0bbc98;
status=NG; namespace=sample; name=TaskA; id=44e9690a4d2182a9bed6b6d9730291bd; message=<class 'KeyError'>: user
gokart.PandasTypeConfig
'et définir les règles dans l'espace de noms.class SamplePandasTypeCheck(gokart.PandasTypeConfig):
task_namespace = 'sample'
@classmethod
def type_dict(cls) -> Dict[str, Any]:
return {'user': int}
class DataTask(gokart.TaskOnKart):
task_namespace = 'sample'
def run(self):
df = pd.DataFrame(dict(user=[1, 2], item=['a', 'b']))
self.dump(df)
class TaskA(gokart.TaskOnKart):
task_namespace = 'sample'
def requires(self):
return DataTask()
def run(self):
df = self.load_data_frame()
#Le type d'utilisateur est passé de int à str.
df['user'] = df['user'].apply(lambda x: f'user_{x}')
self.dump(df)
if __name__ == '__main__':
gokart.run()
--Si vous exécutez la tâche normalement, le type sera vérifié automatiquement.
TaskA
échoue car ʻuser a été changé en
str`.$ python main.py sample.TaskA --local-scheduler
--Message
gokart.pandas_type_config.PandasTypeError: expected type is "<class 'int'>", but "<class 'str'>" is passed in column "user".
...
===== Luigi Execution Summary =====
Scheduled 2 tasks of which:
* 1 ran successfully:
- 1 sample.DataTask(...)
* 1 failed:
- 1 sample.TaskA(...)
This progress looks :( because there were failed tasks
===== Luigi Execution Summary =====
Recommended Posts