Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /BerriAI_litellm /litellm /integrations /focus /serializers /csv.py
| """CSV serializer for Focus export.""" | |
| from __future__ import annotations | |
| import io | |
| from typing import Final | |
| import polars as pl | |
| from .base import FocusSerializer | |
| class FocusCsvSerializer(FocusSerializer): | |
| """Serialize normalized Focus frames to CSV bytes.""" | |
| extension = "csv" | |
| def serialize(self, frame: pl.DataFrame) -> bytes: | |
| """Encode the provided frame as a CSV payload.""" | |
| # Cast Decimal columns to Float64 so CSV output uses standard | |
| # floating-point notation (e.g. "1.5") instead of fixed-point | |
| # strings (e.g. "1.500000") that some parsers may reject. | |
| decimal_cols: Final = [col for col, dtype in zip(frame.columns, frame.dtypes) if isinstance(dtype, pl.Decimal)] | |
| if decimal_cols: | |
| frame = frame.with_columns([pl.col(c).cast(pl.Float64) for c in decimal_cols]) | |
| buffer: Final = io.BytesIO() | |
| frame.write_csv(buffer) | |
| return buffer.getvalue() | |
Xet Storage Details
- Size:
- 951 Bytes
- Xet hash:
- 5930cab224008fee87f4fc6b929e6dfd320fa42dada73ad5088eed5fef440403
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.