(path, cfg)
| 84 | |
| 85 | |
| 86 | def parse_csv(path, cfg) -> list: |
| 87 | int_f = set(cfg.get("int_fields", [])) |
| 88 | float_f = set(cfg.get("float_fields", [])) |
| 89 | json_f = set(cfg.get("json_fields", [])) |
| 90 | df = pd.read_csv(path, dtype=str) |
| 91 | rows = [] |
| 92 | for row in df.to_dict(orient="records"): |
| 93 | doc = {} |
| 94 | for col, val in row.items(): |
| 95 | if ( |
| 96 | val is None |
| 97 | or (isinstance(val, float) and pd.isna(val)) |
| 98 | or str(val).strip() == "" |
| 99 | ): |
| 100 | continue |
| 101 | v = _coerce(col, val, int_f, float_f, json_f) |
| 102 | if "." in col: |
| 103 | _nest(doc, col, v) |
| 104 | else: |
| 105 | doc[col] = v |
| 106 | rows.append(doc) |
| 107 | return rows |
| 108 | |
| 109 | |
| 110 | def parse_json(path) -> list: |
no test coverage detected