@@ -84,6 +84,55 @@ def test_roundtrip_matches(collection: type[dy.Collection]) -> None:
8484 assert collection .matches (decoded )
8585
8686
87+ # --------------------------------- DATAFRAME MEMBERS -------------------------------- #
88+
89+
90+ class EagerSchema (dy .Schema ):
91+ id = dy .Int64 (primary_key = True )
92+
93+
94+ class MixedEagerCollection (dy .Collection ):
95+ """Collection with mixed DataFrame and LazyFrame members."""
96+
97+ eager : dy .DataFrame [EagerSchema ]
98+ lazy : dy .LazyFrame [EagerSchema ]
99+
100+
101+ def test_serialize_includes_is_lazy () -> None :
102+ """Serialization includes the is_lazy field for each member."""
103+ serialized = MixedEagerCollection .serialize ()
104+ decoded = json .loads (serialized )
105+
106+ assert decoded ["members" ]["eager" ]["is_lazy" ] is False
107+ assert decoded ["members" ]["lazy" ]["is_lazy" ] is True
108+
109+
110+ def test_roundtrip_dataframe_members () -> None :
111+ """DataFrame members round-trip correctly through serialization."""
112+ serialized = MixedEagerCollection .serialize ()
113+ decoded = dy .deserialize_collection (serialized )
114+
115+ assert MixedEagerCollection .matches (decoded )
116+ assert not decoded .members ()["eager" ].is_lazy
117+ assert decoded .members ()["lazy" ].is_lazy
118+
119+
120+ def test_deserialize_without_is_lazy_defaults_to_lazy () -> None :
121+ """Old serialized data without is_lazy defaults to lazy for backwards compat."""
122+ collection = create_collection (
123+ "test" , {"s1" : create_schema ("schema1" , {"a" : dy .Int64 ()})}
124+ )
125+ serialized = collection .serialize ()
126+
127+ # Remove is_lazy from serialized data to simulate old format
128+ decoded_dict = json .loads (serialized )
129+ del decoded_dict ["members" ]["s1" ]["is_lazy" ]
130+ modified = json .dumps (decoded_dict )
131+
132+ result = dy .deserialize_collection (modified )
133+ assert result .members ()["s1" ].is_lazy is True
134+
135+
87136# ----------------------------- DESERIALIZATION FAILURES ----------------------------- #
88137
89138
0 commit comments