MCPcopy Create free account
hub / github.com/treeverse/dvc / Serializer

Class Serializer

dvc/database.py:49–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47
48@dataclass
49class Serializer:
50 sql: "Union[str, Selectable]"
51 con: "Union[str, Connectable]"
52 chunksize: int = 10_000
53
54 def to_csv(self, file: StrOrBytesPath, progress=noop):
55 import pandas as pd
56
57 idfs = pd.read_sql(self.sql, self.con, chunksize=self.chunksize)
58 with atomic_file(file) as f:
59 for i, df in enumerate(idfs):
60 df.to_csv(f, header=i == 0, index=False)
61 progress(len(df))
62
63 def to_json(self, file: StrOrBytesPath, progress=noop): # noqa: ARG002
64 import pandas as pd
65
66 df = pd.read_sql(self.sql, self.con)
67 with atomic_file(file) as f:
68 df.to_json(f, orient="records")
69
70 def export(self, file: StrOrBytesPath, format: str = "csv", progress=noop): # noqa: A002
71 if format == "json":
72 return self.to_json(file, progress=progress)
73 return self.to_csv(file, progress=progress)
74
75
76@dataclass

Callers 1

exportMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…