Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data catalog: set the min_rows_per_goup when writing a parquet datase… #1281

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion nautilus_trader/persistence/catalog/parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,14 @@ def write_chunk(
self._fast_write(table=table, path=path, fs=self.fs)
else:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking is that it works without the partitioning flag here, perhaps an other check can be used here to enter the write_dataset code block.

# Write parquet file
min_max_rows_per_group = 5000
pds.write_dataset(
data=table,
base_dir=path,
format="parquet",
filesystem=self.fs,
max_rows_per_group=5000,
min_rows_per_group=min_max_rows_per_group,
max_rows_per_group=min_max_rows_per_group,
**self.dataset_kwargs,
**kwargs,
)
Expand Down
46 changes: 46 additions & 0 deletions tests/unit_tests/persistence/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,49 @@ def test_list_live_runs(

# Assert
assert result == ["abc"]

def test_partioning_min_rows_per_group(
self,
betfair_catalog: ParquetDataCatalog,
) -> None:
# Arrange
instrument = Equity(
instrument_id=InstrumentId(symbol=Symbol("AAPL"), venue=Venue("NASDAQ")),
raw_symbol=Symbol("AAPL"),
currency=USD,
price_precision=2,
price_increment=Price.from_str("0.01"),
multiplier=Quantity.from_int(1),
lot_size=Quantity.from_int(1),
isin="US0378331005",
ts_event=0,
ts_init=0,
margin_init=Decimal("0.01"),
margin_maint=Decimal("0.005"),
maker_fee=Decimal("0.005"),
taker_fee=Decimal("0.01"),
)
quote_ticks = []

# Num quotes needs to be less than 5000 (default value for min_rows_per_group)
expected_num_quotes = 100

for _ in range(expected_num_quotes):
quote_tick = QuoteTick(
instrument_id=instrument.id,
bid_price=Price.from_str("2.1"),
ask_price=Price.from_str("2.0"),
bid_size=Quantity.from_int(10),
ask_size=Quantity.from_int(10),
ts_event=0,
ts_init=0,
)
quote_ticks.append(quote_tick)

# Act
self.catalog.write_data(data=quote_ticks, partitioning=["ts_event"])

result = len(self.catalog.quote_ticks())

# Assert
assert result == expected_num_quotes