Skip to content

Commit e77838b

Browse files
svsgooglecopybara-github
authored andcommitted
Remove the with_descendants argument from DataSliceManagerView.get().
Its functionality is now covered by the `populate_including_descendants` parameter: the old call `view.get(with_descendants=True)` can now be expressed as `view.get(populate_including_descendants=[view])`. PiperOrigin-RevId: 862125204 Change-Id: I8c92a3e6a0a15839d82cd6ab9da30dcb39544f61
1 parent 584b9c4 commit e77838b

File tree

3 files changed

+37
-53
lines changed

3 files changed

+37
-53
lines changed

py/koladata/ext/persisted_data/colab/Persisted_incremental_DataSlice_basics.ipynb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,9 @@
610610
}
611611
],
612612
"source": [
613-
"root.query[:].doc[:].get_data_slice(with_descendants=True)"
613+
"root.query[:].doc[:].get_data_slice(\n",
614+
" populate_including_descendants=[root.query[:].doc[:]]\n",
615+
")"
614616
]
615617
},
616618
{
@@ -1344,7 +1346,7 @@
13441346
}
13451347
],
13461348
"source": [
1347-
"branch_root.get_data_slice(with_descendants=True)"
1349+
"branch_root.get_data_slice(populate_including_descendants=[branch_root])"
13481350
]
13491351
},
13501352
{
@@ -1674,7 +1676,7 @@
16741676
}
16751677
],
16761678
"source": [
1677-
"root.query.get_data_slice(with_descendants=True)[0]"
1679+
"root.query.get_data_slice(populate_including_descendants=[root.query])[0]"
16781680
]
16791681
},
16801682
{

py/koladata/ext/persisted_data/data_slice_manager_view.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ def get_schema(self) -> kd.types.SchemaItem:
9898
def get_data_slice(
9999
self,
100100
*,
101-
with_descendants: bool = False,
102101
populate: Collection[DataSliceManagerView] | None = None,
103102
populate_including_descendants: (
104103
Collection[DataSliceManagerView] | None
@@ -109,8 +108,6 @@ def get_data_slice(
109108
The view path must be valid, i.e. self.is_view_valid() must be True.
110109
111110
Args:
112-
with_descendants: If True, then the DataSlice will include the data of all
113-
the descendants of the view path.
114111
populate: Additional views whose DataSlicePaths will be populated. Their
115112
paths must be descendants of this view's path for you to see their data
116113
in the returned DataSlice.
@@ -119,13 +116,10 @@ def get_data_slice(
119116
"""
120117
self._check_path_from_root_is_valid()
121118
populate = {v.get_path_from_root() for v in populate or []}
119+
populate.add(self._path_from_root)
122120
populate_including_descendants = {
123121
v.get_path_from_root() for v in populate_including_descendants or []
124122
}
125-
if with_descendants:
126-
populate_including_descendants.add(self._path_from_root)
127-
else:
128-
populate.add(self._path_from_root)
129123
ds = self._data_slice_manager.get_data_slice(
130124
populate=populate,
131125
populate_including_descendants=populate_including_descendants,
@@ -135,7 +129,6 @@ def get_data_slice(
135129
def get(
136130
self,
137131
*,
138-
with_descendants: bool = False,
139132
populate: Collection[DataSliceManagerView] | None = None,
140133
populate_including_descendants: (
141134
Collection[DataSliceManagerView] | None
@@ -146,16 +139,13 @@ def get(
146139
The view path must be valid, i.e. self.is_view_valid() must be True.
147140
148141
Args:
149-
with_descendants: If True, then the DataSlice will include the data of all
150-
the descendants of the view path.
151142
populate: Additional views whose DataSlicePaths will be populated. Their
152143
paths must be descendants of this view's path for you to see their data
153144
in the returned DataSlice.
154145
populate_including_descendants: Additional views whose DataSlicePaths and
155146
all their descendants will be populated.
156147
"""
157148
return self.get_data_slice(
158-
with_descendants=with_descendants,
159149
populate=populate,
160150
populate_including_descendants=populate_including_descendants,
161151
)

py/koladata/ext/persisted_data/data_slice_manager_view_test.py

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def test_typical_usage(self):
6161
kd.slice(['How tall is Obama', 'How high is the Eiffel tower']),
6262
)
6363
kd.testing.assert_equivalent(
64-
queries.get(with_descendants=True),
64+
queries.get(populate_including_descendants=[queries]),
6565
kd.slice([
6666
expected_query_schema.new(query_id=0, text='How tall is Obama'),
6767
expected_query_schema.new(
@@ -772,7 +772,7 @@ def branch_and_filter(
772772
root = DataSliceManagerView(manager)
773773
filtered_root = DataSliceManagerView(filtered_manager)
774774
kd.testing.assert_equivalent(
775-
root.get_data_slice(with_descendants=True),
775+
root.get_data_slice(populate_including_descendants=[root]),
776776
kd.new(
777777
query=kd.list([
778778
kd.named_schema('query').new(
@@ -802,7 +802,9 @@ def branch_and_filter(
802802
)
803803
# The filtering recipe above results in one query with one doc:
804804
kd.testing.assert_equivalent(
805-
filtered_root.get_data_slice(with_descendants=True),
805+
filtered_root.get_data_slice(
806+
populate_including_descendants=[filtered_root]
807+
),
806808
kd.new(
807809
query=kd.list([
808810
kd.named_schema('query').new(
@@ -953,7 +955,7 @@ def _test_filter_docs_from_view(
953955
),
954956
)
955957
kd.testing.assert_equivalent(
956-
root.get_data_slice(with_descendants=True),
958+
root.get_data_slice(populate_including_descendants=[root]),
957959
trunk_initial_data_manager.get_schema().new(
958960
query=kd.list([
959961
query_schema.new(
@@ -1010,8 +1012,10 @@ def _test_filter_docs_from_view(
10101012
description='Filtered docs by selecting all of them',
10111013
)
10121014
kd.testing.assert_equivalent(
1013-
root.get_data_slice(with_descendants=True),
1014-
trunk_root.get_data_slice(with_descendants=True),
1015+
root.get_data_slice(populate_including_descendants=[root]),
1016+
trunk_root.get_data_slice(
1017+
populate_including_descendants=[trunk_root]
1018+
),
10151019
ids_equality=True,
10161020
)
10171021
branch_manager_revision_descriptions = [
@@ -1038,7 +1042,7 @@ def _test_filter_docs_from_view(
10381042
description='Filtered all docs',
10391043
)
10401044
kd.testing.assert_equivalent(
1041-
root.get_data_slice(with_descendants=True),
1045+
root.get_data_slice(populate_including_descendants=[root]),
10421046
trunk_root.get_data_slice()
10431047
.with_attr('query', None)
10441048
.with_schema(trunk_root.get_schema()),
@@ -1079,7 +1083,7 @@ def _test_filter_docs_from_view(
10791083
),
10801084
)
10811085
kd.testing.assert_equivalent(
1082-
root.get_data_slice(with_descendants=True),
1086+
root.get_data_slice(populate_including_descendants=[root]),
10831087
trunk_initial_data_manager.get_schema().new(
10841088
query=kd.list([
10851089
query_schema.new(
@@ -1114,8 +1118,16 @@ def _test_filter_docs_from_view(
11141118
trunk_root.query[:].get_data_slice().S[1].get_itemid(),
11151119
)
11161120
kd.testing.assert_equivalent(
1117-
root.query[:].doc[:].get_data_slice(with_descendants=True).L[0],
1118-
trunk_root.query[:].doc[:].get_data_slice(with_descendants=True).L[1],
1121+
root.query[:]
1122+
.doc[:]
1123+
.get_data_slice(populate_including_descendants=[root.query[:].doc[:]])
1124+
.L[0],
1125+
trunk_root.query[:]
1126+
.doc[:]
1127+
.get_data_slice(
1128+
populate_including_descendants=[trunk_root.query[:].doc[:]]
1129+
)
1130+
.L[1],
11191131
ids_equality=True,
11201132
)
11211133
branch_manager_revision_descriptions = [
@@ -1144,7 +1156,7 @@ def _test_filter_docs_from_view(
11441156
description='Filtered token keys to keep only those that are "hands"',
11451157
)
11461158
kd.testing.assert_equivalent(
1147-
root.get_data_slice(with_descendants=True),
1159+
root.get_data_slice(populate_including_descendants=[root]),
11481160
trunk_initial_data_manager.get_schema().new(
11491161
query=kd.list([
11501162
query_schema.new(
@@ -1182,7 +1194,7 @@ def _test_filter_docs_from_view(
11821194
)
11831195

11841196
kd.testing.assert_equivalent(
1185-
root.get_data_slice(with_descendants=True),
1197+
root.get_data_slice(populate_including_descendants=[root]),
11861198
trunk_initial_data_manager.get_schema().new(
11871199
query=kd.list([
11881200
query_schema.new(
@@ -1234,7 +1246,7 @@ def _test_filter_docs_from_view(
12341246
)
12351247

12361248
kd.testing.assert_equivalent(
1237-
root.get_data_slice(with_descendants=True),
1249+
root.get_data_slice(populate_including_descendants=[root]),
12381250
trunk_initial_data_manager.get_schema().new(
12391251
query=kd.list([
12401252
query_schema.new(
@@ -1322,7 +1334,7 @@ def _test_filter_docs_from_view(
13221334
description='Filtered docs to keep only those with tokens',
13231335
)
13241336
kd.testing.assert_equivalent(
1325-
root.get(with_descendants=True),
1337+
root.get_data_slice(populate_including_descendants=[root]),
13261338
trunk_initial_data_manager.get_schema().new(
13271339
query=kd.list([
13281340
query_schema.new(
@@ -1370,7 +1382,7 @@ def _test_filter_docs_from_view(
13701382
),
13711383
)
13721384
kd.testing.assert_equivalent(
1373-
root.get(with_descendants=True),
1385+
root.get(populate_including_descendants=[root]),
13741386
trunk_initial_data_manager.get_schema().new(
13751387
query=kd.list([
13761388
query_schema.new(
@@ -1435,7 +1447,8 @@ def test_error_messages_when_sugar_does_not_apply_to_attribute_name(self):
14351447

14361448
# IPython auto-complete should not suggest the reserved attribute names.
14371449
self.assertEqual(
1438-
kd.dir(root.get_data_slice(with_descendants=True)), ['fingerprint']
1450+
kd.dir(root.get_data_slice(populate_including_descendants=[root])),
1451+
['fingerprint'],
14391452
)
14401453
self.assertNotIn('fingerprint', root.__all__)
14411454
self.assertEqual(
@@ -1842,19 +1855,9 @@ def test_get_with_populate_arguments(self):
18421855
schemas_equality=False,
18431856
)
18441857

1845-
kd.testing.assert_equivalent(
1846-
doc_view.get(populate_including_descendants=[doc_view]),
1847-
doc_view.get(with_descendants=True),
1848-
ids_equality=True,
1849-
)
1850-
kd.testing.assert_equivalent(
1851-
query_view.get(populate_including_descendants=[query_view]),
1852-
query_view.get(with_descendants=True),
1853-
ids_equality=True,
1854-
)
18551858
kd.testing.assert_equivalent(
18561859
doc_view.get(populate_including_descendants=[query_view]),
1857-
doc_view.get(with_descendants=True),
1860+
doc_view.get(populate_including_descendants=[doc_view]),
18581861
ids_equality=True,
18591862
)
18601863
kd.testing.assert_equivalent(
@@ -1866,18 +1869,7 @@ def test_get_with_populate_arguments(self):
18661869
root_view.get(
18671870
populate=[doc_view], populate_including_descendants=[query_view]
18681871
),
1869-
root_view.get(with_descendants=True),
1870-
ids_equality=True,
1871-
)
1872-
kd.testing.assert_equivalent(
1873-
root_view.get(
1874-
populate=[query_view.text, query_view.query_id],
1875-
populate_including_descendants=[doc_view],
1876-
),
1877-
root_view.get(
1878-
populate=[query_view.text, query_view.query_id],
1879-
populate_including_descendants=[doc_view],
1880-
),
1872+
root_view.get(populate_including_descendants=[root_view]),
18811873
ids_equality=True,
18821874
)
18831875

0 commit comments

Comments
 (0)