Skip to content

Commit aaaada1

Browse files
committed
add test
1 parent fd22734 commit aaaada1

File tree

6 files changed

+69
-21
lines changed

6 files changed

+69
-21
lines changed

pydough/qdag/collections/range_collection.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ def __init__(
2828
end: int,
2929
step: int,
3030
) -> None:
31-
super().__init__(name=name, columns=[column_name])
31+
super().__init__(
32+
name=name,
33+
columns=[
34+
column_name,
35+
],
36+
)
3237
self.start = start
3338
self.end = end
3439
self.step = step

pydough/qdag/collections/user_collection_qdag.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,28 @@ def clone_with_parent(
3535
"""
3636
return PyDoughUserGeneratedCollectionQDag(new_ancestor, self._collection)
3737

38+
def to_tree_form_isolated(self, is_last: bool) -> CollectionTreeForm:
39+
# if self.ancestor_context is not None:
40+
# return CollectionTreeForm(
41+
# self.tree_item_string,
42+
# 0,
43+
# has_predecessor=True,
44+
# )
45+
# else:
46+
return CollectionTreeForm(self.tree_item_string, 0)
47+
3848
def to_tree_form(self, is_last: bool) -> CollectionTreeForm:
39-
raise NotImplementedError
49+
# if self.ancestor_context is not None:
50+
# predecessor: CollectionTreeForm = self.ancestor_context.to_tree_form(
51+
# is_last
52+
# )
53+
# predecessor.has_children = True
54+
# tree_form: CollectionTreeForm = self.to_tree_form_isolated(is_last)
55+
# tree_form.depth = predecessor.depth + 1
56+
# tree_form.predecessor = predecessor
57+
# return tree_form
58+
# else:
59+
return self.to_tree_form_isolated(is_last)
4060

4161
@property
4262
def collection(self) -> PyDoughUserGeneratedCollection:
@@ -102,7 +122,7 @@ def standalone_string(self) -> str:
102122
Returns a string representation of the collection in a standalone form.
103123
This is used for debugging and logging purposes.
104124
"""
105-
return f"UserGeneratedCollection({self.name}, {', '.join(self.collection.columns)})"
125+
return f"UserGeneratedCollection[{self.name}, {', '.join(self.collection.columns)}]"
106126

107127
@property
108128
def key(self) -> str:
@@ -114,4 +134,4 @@ def to_string(self) -> str:
114134

115135
@property
116136
def tree_item_string(self) -> str:
117-
return f"UserGeneratedCollection({self.name})"
137+
return f"UserGeneratedCollection[{self.name}: {', '.join(self.collection.columns)}]"

pydough/unqualified/unqualified_transform.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,8 @@ def transform_code(
360360
source: str, graph_dict: dict[str, GraphMetadata], known_names: set[str]
361361
) -> ast.AST:
362362
"""
363-
Transforms the source code into a new Python QDAG that has had the PyDough
364-
decorator removed, had the definition of `_ROOT` injected at the top of the
363+
Transforms the source code into a new Python QDAG that has the PyDough
364+
decorator removed, has the definition of `_ROOT` injected at the top of the
365365
function body, and prepend unknown variables with `_ROOT.`
366366
367367
Args:

pydough/user_collections/range_collection.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

66
__all__ = ["range_collection"]
77

8-
from pydough.qdag.collections.range_collection import RangeGeneratedCollection
8+
from pydough.unqualified.unqualified_node import UnqualifiedGeneratedCollection
99

1010

11-
def range_collection(name: str, column: str, *args: int) -> RangeGeneratedCollection:
11+
def range_collection(
12+
name: str, column: str, *args: int
13+
) -> UnqualifiedGeneratedCollection:
1214
"""
1315
Creates a collection of integer ranges over a specified column.
1416
@@ -63,10 +65,18 @@ def range_collection(name: str, column: str, *args: int) -> RangeGeneratedCollec
6365
if step <= 0:
6466
raise ValueError(f"Expected 'step' to be a positive integer, got {step}")
6567

66-
return RangeGeneratedCollection(
67-
name=name,
68-
column_name=column,
69-
start=start,
70-
end=end,
71-
step=step,
68+
# return RangeGeneratedCollection(
69+
# name=name,
70+
# column_name=column,
71+
# start=start,
72+
# end=end,
73+
# step=step,
74+
# )
75+
range_args = [start, end, step]
76+
return UnqualifiedGeneratedCollection(
77+
name,
78+
[
79+
column,
80+
],
81+
range_args,
7282
)

tests/test_pydough_functions/user_collections.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@
66
# mypy: ignore-errors
77
# ruff & mypy should not try to typecheck or verify any of this
88

9-
import pandas as pd
10-
import datetime
11-
129
import pydough
1310

1411

15-
def simple_range():
12+
def simple_range_1():
13+
return pydough.range_collection(
14+
"simple_range",
15+
"value",
16+
10, # end value
17+
)
18+
19+
20+
def simple_range_2():
1621
return pydough.range_collection(
1722
"simple_range",
1823
"value",

tests/test_qualification.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@
6464
impl_tpch_q22,
6565
)
6666
from tests.test_pydough_functions.user_collections import (
67-
simple_range,
67+
simple_range_1,
68+
simple_range_2,
6869
)
6970
from tests.testing_utilities import (
7071
graph_fetcher,
@@ -946,10 +947,17 @@
946947
id="simple_cross_6",
947948
),
948949
pytest.param(
949-
simple_range,
950+
simple_range_1,
950951
"""
952+
UserGeneratedCollection[simple_range: value]
951953
""",
952-
id="simple_range",
954+
id="simple_range_1",
955+
),
956+
pytest.param(
957+
simple_range_2,
958+
"""
959+
""",
960+
id="simple_range_2",
953961
),
954962
],
955963
)

0 commit comments

Comments
 (0)