Skip to content

Commit 951a792

Browse files
felbrocopybara-github
authored andcommitted
Change kd.slice([]).get_schema() == kd.NONE
Additionally: * kd.list() -> LIST[OBJECT] * kd.list([]) -> LIST[NONE] * kd.slice([]) -> NONE * kd.dict() -> DICT[OBJECT, OBJECT] * kd.dict({}) -> DICT[NONE, NONE] I have not addressed the intended `from_py([]) -> LIST[NONE]` as `from_py` requires more generic changes (e.g. `from_py([1]).get_schema() == OBJECT` right now). PiperOrigin-RevId: 717956799 Change-Id: I10f6c2912e6762f6c2b92c41c49a9efcca046892
1 parent c30cc92 commit 951a792

33 files changed

+137
-55
lines changed

koladata/internal/schema_utils.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,8 @@ bool VerifySchemaForItemIds(const internal::DataItem& schema_item) {
338338
}
339339

340340
absl::Status VerifyDictKeySchema(const internal::DataItem& schema_item) {
341-
if (schema_item == kNone || schema_item == kFloat32 ||
342-
schema_item == kFloat64 || schema_item == kExpr) {
341+
if (schema_item == kFloat32 || schema_item == kFloat64 ||
342+
schema_item == kExpr) {
343343
return absl::InvalidArgumentError(
344344
absl::StrFormat("dict keys cannot be %v", schema_item));
345345
}

koladata/internal/schema_utils_test.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,13 +516,12 @@ TEST(SchemaUtilsTest, VerifySchemaForItemIds) {
516516

517517
TEST(SchemaUtilsTest, VerifyDictKeySchema) {
518518
EXPECT_THAT(VerifyDictKeySchema(DataItem(schema::kInt32)), IsOk());
519+
EXPECT_THAT(VerifyDictKeySchema(DataItem(schema::kNone)), IsOk());
519520
EXPECT_THAT(VerifyDictKeySchema(DataItem(schema::kFloat32)),
520521
StatusIs(absl::StatusCode::kInvalidArgument,
521522
HasSubstr("dict keys cannot be FLOAT32")));
522523
EXPECT_THAT(VerifyDictKeySchema(DataItem(schema::kFloat64)),
523524
StatusIs(absl::StatusCode::kInvalidArgument));
524-
EXPECT_THAT(VerifyDictKeySchema(DataItem(schema::kNone)),
525-
StatusIs(absl::StatusCode::kInvalidArgument));
526525
EXPECT_THAT(VerifyDictKeySchema(DataItem(schema::kExpr)),
527526
StatusIs(absl::StatusCode::kInvalidArgument));
528527
}

koladata/operators/slices.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ absl::StatusOr<DataSlice> ConcatOrStackImpl(bool stack, int64_t ndim,
140140
return DataSlice::Create(
141141
internal::DataSliceImpl::CreateEmptyAndUnknownType(0),
142142
DataSlice::JaggedShape::FlatFromSize(0),
143-
internal::DataItem(schema::kObject), nullptr);
143+
internal::DataItem(schema::kNone), nullptr);
144144
}
145145

146146
const int64_t rank = args[0].GetShape().rank();

py/koladata/ext/experimental/parallel_call/call.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,9 @@ def _schedule_call(
391391
"""
392392
inputs = bind_args(fn, args, kwargs)
393393
debug = parent_debug.get_bag().obj(
394-
name=debug_name, start_time=kd.item(time.time(), kd.FLOAT64), children=[]
394+
name=debug_name,
395+
start_time=kd.item(time.time(), kd.FLOAT64),
396+
children=kd.list(),
395397
)
396398
parent_debug.children.append(debug)
397399
fn_call = _FunctorCall(fn, inputs, debug)
@@ -435,7 +437,7 @@ def call_multithreaded_with_debug(
435437
kwargs = {k: kd.optools.as_qvalue(v) for k, v in kwargs.items()}
436438
repo = task_repository.TaskRepository()
437439
debug_db = kd.bag()
438-
root_debug = debug_db.obj(children=[])
440+
root_debug = debug_db.obj(children=kd.list())
439441
final_result_task = _schedule_call(
440442
repo, fn, args, kwargs, root_debug, '<root>'
441443
)

py/koladata/functions/tests/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ py_test(
605605
name = "to_py_test",
606606
srcs = ["to_py_test.py"],
607607
deps = [
608+
"//py/koladata/exceptions",
608609
"//py/koladata/functions",
609610
"//py/koladata/operators:kde_operators",
610611
"//py/koladata/types:data_slice",

py/koladata/functions/tests/concat_lists_test.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""Tests for kd.concat_lists."""
16-
1715
from absl.testing import absltest
1816
from absl.testing import parameterized
1917
from koladata.functions import functions as fns
@@ -45,7 +43,7 @@ def test_mutability(self):
4543
@parameterized.parameters(
4644
(
4745
(),
48-
fns.list([]),
46+
fns.list(),
4947
),
5048
(
5149
(fns.list([1, 2, 3]),),

py/koladata/functions/tests/dict_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ def test_empty(self):
5353
d[keys], ds([1, None, 1], schema_constants.OBJECT).with_bag(d.get_bag())
5454
)
5555

56+
def test_no_input_values(self):
57+
d = fns.dict({})
58+
self.assertIsInstance(d, dict_item.DictItem)
59+
testing.assert_dicts_keys_equal(d, ds([]))
60+
testing.assert_dicts_values_equal(d, ds([]))
61+
5662
def test_dict_with_uuid(self):
5763
db = fns.bag()
5864
testing.assert_equal(

py/koladata/functions/tests/from_proto_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class FromProtoTest(absltest.TestCase):
2929

3030
def test_zero_messages(self):
3131
x = fns.from_proto([])
32-
testing.assert_equal(x.no_bag(), ds([]))
32+
testing.assert_equal(x.no_bag(), ds([], schema_constants.OBJECT))
3333

3434
def test_single_none(self):
3535
x = fns.from_proto(None)

py/koladata/functions/tests/from_py_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ def test_list_from_dim(self):
272272
l3 = fns.from_py([1, 2], from_dim=1)
273273
testing.assert_equal(l3, ds([1, 2]))
274274

275+
def test_empty_from_dim(self):
276+
l0 = fns.from_py([], from_dim=1)
277+
testing.assert_equal(l0, ds([]).with_bag(l0.get_bag()))
278+
275279
def test_list_from_dim_with_schema(self):
276280
input_list = [[1, 2.0], [3, 4]]
277281

py/koladata/functions/tests/list_like_test.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ def test_mutability(self):
3737
def test_item(self):
3838
l = fns.list_like(ds(1)).fork_db()
3939
self.assertIsInstance(l, list_item.ListItem)
40-
testing.assert_equal(l[:], ds([]).with_bag(l.get_bag()))
40+
testing.assert_equal(
41+
l[:], ds([], schema_constants.OBJECT).with_bag(l.get_bag())
42+
)
4143
l.append(1)
4244
testing.assert_equal(
4345
l[:], ds([1], schema_constants.OBJECT).with_bag(l.get_bag())
@@ -54,12 +56,15 @@ def test_empty_item(self):
5456
l = fns.list_like(ds(None)).fork_db()
5557
testing.assert_equal(l.no_bag(), ds(None, l.get_schema().no_bag()))
5658
l.append(1)
57-
testing.assert_equal(l[:].no_bag(), ds([]))
59+
testing.assert_equal(l[:].no_bag(), ds([], schema_constants.OBJECT))
5860

5961
def test_slice(self):
6062
l = fns.list_like(ds([[1, None], [3]])).fork_db()
6163
self.assertIsInstance(l, data_slice.DataSlice)
62-
testing.assert_equal(l[:], ds([[[], []], [[]]]).with_bag(l.get_bag()))
64+
testing.assert_equal(
65+
l[:],
66+
ds([[[], []], [[]]], schema_constants.OBJECT).with_bag(l.get_bag()),
67+
)
6368
l.append(1)
6469
testing.assert_equal(
6570
l[:],
@@ -69,9 +74,15 @@ def test_slice(self):
6974
def test_all_missing_slice(self):
7075
l = fns.list_like(ds([[None, None], [None]])).fork_db()
7176
self.assertIsInstance(l, data_slice.DataSlice)
72-
testing.assert_equal(l[:], ds([[[], []], [[]]]).with_bag(l.get_bag()))
77+
testing.assert_equal(
78+
l[:],
79+
ds([[[], []], [[]]], schema_constants.OBJECT).with_bag(l.get_bag()),
80+
)
7381
l.append(1)
74-
testing.assert_equal(l[:], ds([[[], []], [[]]]).with_bag(l.get_bag()))
82+
testing.assert_equal(
83+
l[:],
84+
ds([[[], []], [[]]], schema_constants.OBJECT).with_bag(l.get_bag()),
85+
)
7586

7687
def test_slice_with_scalar_items(self):
7788
l = fns.list_like(ds([[1, None], [3]]), 1).fork_db()

0 commit comments

Comments
 (0)