Skip to content

Commit

Permalink
perf(protobuf): migrate from pandas to polars (#22080)
Browse files Browse the repository at this point in the history
  • Loading branch information
hongbo-miao authored Dec 28, 2024
1 parent 51d6a22 commit f5abd3e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 76 deletions.
1 change: 0 additions & 1 deletion computer-vision/hm-open3d/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ requires-python = "~=3.10.0"
dependencies = [
"addict==2.4.0",
"open3d==0.18.0",
"pandas==2.2.3",
"Pillow==11.0.0",
"PyYAML==6.0.2",
"scikit-learn==1.6.0",
Expand Down
2 changes: 0 additions & 2 deletions computer-vision/hm-open3d/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion data-storage/hm-protobuf/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "1.0.0"
requires-python = "~=3.13.0"
dependencies = [
"numpy==2.2.1",
"pandas==2.2.3",
"polars==1.18.0",
"protobuf==5.29.2",
]

Expand Down
8 changes: 4 additions & 4 deletions data-storage/hm-protobuf/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pathlib import Path
from typing import Any

import pandas as pd
import polars as pl
from protos.production.iot import motor_pb2


Expand All @@ -27,7 +27,7 @@ class ProtobufReader:
def __init__(self, filename: Path) -> None:
self.file = open(filename, "rb")

def get_dataframe(self) -> pd.DataFrame:
def get_dataframe(self) -> pl.DataFrame:
data: list[dict[str, Any]] = []
while True:
size_data: bytes = self.file.read(4)
Expand All @@ -53,7 +53,7 @@ def get_dataframe(self) -> pd.DataFrame:
}
data.append(row)

df: pd.DataFrame = pd.DataFrame(data)
df: pl.DataFrame = pl.DataFrame(data)
return df

def close(self) -> None:
Expand Down Expand Up @@ -92,7 +92,7 @@ def main() -> None:

# Read data
reader: ProtobufReader = ProtobufReader(motor_data_path)
df: pd.DataFrame = reader.get_dataframe()
df: pl.DataFrame = reader.get_dataframe()
reader.close()
logging.info(df)

Expand Down
84 changes: 16 additions & 68 deletions data-storage/hm-protobuf/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f5abd3e

Please sign in to comment.