Skip to content

Commit da34885

Browse files
committed
Use named tuple instead of tuple to improve type hints
1 parent 25b922c commit da34885

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/datanomy/reader/parquet.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
"""Parquet file reader."""
22

33
from pathlib import Path
4-
from typing import Any
4+
from typing import Any, NamedTuple
55

66
import pyarrow.parquet as pq
77
from pyarrow.lib import ArrowInvalid
88

99

10+
class RowGroupSize(NamedTuple):
11+
"""Size information for a row group."""
12+
13+
compressed: int
14+
uncompressed: int
15+
16+
1017
class RowGroup:
1118
"""Class to represent a Parquet row group."""
1219

@@ -71,14 +78,13 @@ def has_compression(self) -> bool:
7178
return False
7279

7380
@property
74-
def total_sizes(self) -> tuple[int, int]:
81+
def total_sizes(self) -> RowGroupSize:
7582
"""
7683
Get total compressed and uncompressed size of the row group in bytes.
7784
7885
Returns
7986
-------
80-
Total compressed and uncompressed size of the row group in bytes.
81-
Tuple of (compressed_size, uncompressed_size)
87+
RowGroupSize named tuple with compressed and uncompressed sizes
8288
"""
8389
compressed_sum = sum(
8490
self.column(j).total_compressed_size for j in range(self.num_columns)
@@ -88,7 +94,7 @@ def total_sizes(self) -> tuple[int, int]:
8894
uncompressed_sum = sum(
8995
self.column(j).total_uncompressed_size for j in range(self.num_columns)
9096
)
91-
return compressed_sum, uncompressed_sum
97+
return RowGroupSize(compressed=compressed_sum, uncompressed=uncompressed_sum)
9298

9399

94100
class ParquetReader:

0 commit comments

Comments
 (0)