MCPcopy Create free account
hub / github.com/IBM/AssetOpsBench / parse_csv

Function parse_csv

src/couchdb/loader.py:86–107  ·  view source on GitHub ↗
(path, cfg)

Source from the content-addressed store, hash-verified

84
85
86def 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
110def parse_json(path) -> list:

Callers 1

_parse_fileFunction · 0.85

Calls 4

_coerceFunction · 0.85
_nestFunction · 0.85
getMethod · 0.45
to_dictMethod · 0.45

Tested by

no test coverage detected