Skip to content

Commit cd8251c

Browse files
author
gabriel.g.robin
committed
nullable struct
1 parent f5ce346 commit cd8251c

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

dataframely/columns/struct.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,14 @@ def pyarrow_dtype(self) -> pa.DataType:
9696
return pa.struct({name: col.pyarrow_dtype for name, col in self.inner.items()})
9797

9898
def _sample_unchecked(self, generator: Generator, n: int) -> pl.Series:
99-
return (
99+
series = (
100100
pl.DataFrame(
101101
{name: col.sample(generator, n) for name, col in self.inner.items()}
102102
)
103103
.select(pl.struct(pl.all()))
104104
.to_series()
105105
)
106+
# Apply a null mask.
107+
return generator._apply_null_mask(
108+
series, null_probability=self._null_probability
109+
)

tests/columns/test_sample.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ def test_sample_list(generator: Generator) -> None:
184184
def test_sample_struct(generator: Generator) -> None:
185185
column = dy.Struct({"a": dy.String(regex="[abc]"), "b": dy.String(regex="[a-z]xx")})
186186
samples = sample_and_validate(column, generator, n=10_000)
187+
assert samples.is_null().any()
187188
assert len(samples) == 10_000
188189

189190

0 commit comments

Comments
 (0)