Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Upcoming (TBD)
==============

Bug Fixes
--------
* Infer Polars column types from all rows before transforms.


v2.32.2 (2026/11/28)
==============

Expand Down
1 change: 1 addition & 0 deletions mycli/AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ Contributors:
* goranai
* zzoraemon043
* minilan677-netizen
* Lenin Mookiah


Created by:
Expand Down
2 changes: 1 addition & 1 deletion mycli/packages/dataframes/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def run_polars_transform(
if not isinstance(result.header, list) or result.rows is None:
raise PolarsTransformError('Polars transforms require a tabular SQL result.')

dataframe = transform.polars.DataFrame(list(result.rows), schema=result.header, orient='row')
dataframe = transform.polars.DataFrame(list(result.rows), schema=result.header, orient='row', infer_schema_length=None)
try:
value = eval(
transform.code,
Expand Down
26 changes: 25 additions & 1 deletion mycli_test/pytests/test_polars_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def __init__(
rows: list[tuple[Any, ...]] | list[Any],
schema: list[str],
orient: str | None = None,
*,
infer_schema_length: int | None = 100,
) -> None:
if orient is None:
self.rows = [(value,) for value in rows]
Expand Down Expand Up @@ -97,10 +99,12 @@ def __init__(
rows: list[tuple[Any, ...]] | list[Any],
schema: list[str],
orient: str | None = None,
*,
infer_schema_length: int | None = 100,
) -> None:
if orient is None:
raise TypeError('invalid scalar')
super().__init__(rows, schema, orient)
super().__init__(rows, schema, orient, infer_schema_length=infer_schema_length)


class ScalarConstructionFailingPolars:
Expand Down Expand Up @@ -478,6 +482,26 @@ def test_run_polars_transform_materializes_and_renders_returned_dataframe() -> N
assert result == SQLResult(header=['id'], rows=[(1,), (2,)])


@pytest.mark.parametrize('later_value', [1, 'value'])
def test_run_polars_transform_infers_types_from_all_rows(later_value: Any) -> None:
pl = pytest.importorskip('polars')
rows = [(None,)] * 100 + [(later_value,)]
transform = PolarsTransform(
sql='SELECT sparse_value FROM records',
expression='df',
code=compile('df', '<test>', 'eval'),
polars=pl,
altair=None,
)

result = run_polars_transform(
transform,
iter([SQLResult(header=['sparse_value'], rows=rows)]),
)

assert result == SQLResult(header=['sparse_value'], rows=rows)


@pytest.mark.parametrize(
('expression', 'column_name', 'value'),
[
Expand Down
Loading