Skip to content

Commit e165592

Browse files
jakubpernisJakub Perniš
and
Jakub Perniš
authored
Replace NamedTuple with dataclass (AmpX-AI#24)
Co-authored-by: Jakub Perniš <jpernis@amp.energy>
1 parent 7983689 commit e165592

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

fsql/deser.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
from enum import Enum, auto, unique
5454
from functools import partial, reduce
5555
from itertools import chain
56-
from typing import Any, Generic, Iterable, NamedTuple, Tuple, TypeVar, Union
56+
from typing import Any, Generic, Iterable, Tuple, TypeVar, Union
5757

5858
import pandas as pd
5959
from fsspec.core import OpenFile
@@ -98,12 +98,14 @@ def from_url(cls, url: str):
9898
DataObject = TypeVar("DataObject")
9999

100100

101-
class DataObjectRich(NamedTuple, Generic[DataObject]):
101+
@dataclass(frozen=True)
102+
class DataObjectRich(Generic[DataObject]):
102103
data: DataObject
103104
failures: Iterable[PartitionReadFailure]
104105

105106

106-
class PartitionReadFailure(NamedTuple):
107+
@dataclass(frozen=True)
108+
class PartitionReadFailure:
107109
partition: Partition
108110
reason: str # or Any?
109111

tests/test_dict_reader.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ def test_lazy_errors(tmp_path):
3939

4040
lazy_reader = EnumeratedDictReader(lazy_errors=True)
4141
result = read_partitioned_table(f"file://{case1_path}/", Q_TRUE, data_reader=lazy_reader)
42-
assert result[0] == {0: json.loads(data1)}
43-
assert [error_line] == [e.reason for e in result[1]]
42+
assert result.data == {0: json.loads(data1)}
43+
assert [error_line] == [e.reason for e in result.failures]

tests/test_pandasreader.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ def test_lazy_errors(tmp_path):
5151
result = read_partitioned_table(f"file://{case1_path}/", Q_TRUE, data_reader=reader_eager)
5252
reader_lazy = PandasReader(columns=["c3"], lazy_errors=True)
5353
result = read_partitioned_table(f"file://{case1_path}/", Q_TRUE, data_reader=reader_lazy)
54-
assert_frame_equal(df2[["c3"]], result[0])
55-
reasons = [e.reason.split("\n")[0] for e in result[1]]
54+
assert_frame_equal(df2[["c3"]], result.data)
55+
reasons = [e.reason.split("\n")[0] for e in result.failures]
5656
assert reasons == [error_line]

0 commit comments

Comments
 (0)