Skip to content

Commit

Permalink
feat(export): implement the Column.to_list() API
Browse files Browse the repository at this point in the history
  • Loading branch information
deepyaman committed Nov 15, 2024
1 parent 4d99018 commit 8e904aa
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ ibis/examples/pixi.lock linguist-generated=true
requirements-dev.txt linguist-generated=true
docs/_freeze/**/html.json linguist-generated=true
docs/**/*.excalidraw linguist-generated=true
# GitHub syntax highlighting
pixi.lock linguist-language=YAML linguist-generated=true
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,7 @@ docs/**/*.html
.jupyterlite.doit.db
docs/jupyter_lite_config.json
*.quarto_ipynb

# pixi environments
.pixi
*.egg-info
9 changes: 9 additions & 0 deletions ibis/backends/tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,15 @@ def test_column_to_memory(limit, awards_players, output_format, expected_column_
) == awards_players.count().execute()


@pytest.mark.parametrize("limit", limit_no_limit)
def test_column_to_list(limit, awards_players):
res = awards_players.awardID.to_list(limit=limit)
assert isinstance(res, list)
assert (limit is not None and len(res) == limit) or len(
res
) == awards_players.count().execute()


@pytest.mark.parametrize("limit", no_limit)
@pytest.mark.parametrize(
("output_format", "converter"),
Expand Down
20 changes: 19 additions & 1 deletion ibis/expr/types/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ def desc(self, nulls_first: bool = False) -> ir.Value:
return ops.SortKey(self, ascending=False, nulls_first=nulls_first).to_expr()

def to_pandas(self, **kwargs) -> pd.Series:
"""Convert a column expression to a pandas Series or scalar object.
"""Convert an expression to a pandas or scalar object.
Parameters
----------
Expand Down Expand Up @@ -2684,6 +2684,24 @@ def nth(self, n: int | ir.IntegerValue) -> Column:
"""
return ops.NthValue(self, n).to_expr()

def to_list(self, **kwargs) -> list:
"""Convert a column expression to a list.
Parameters
----------
kwargs
Same as keyword arguments to [`to_pyarrow`](#ibis.expr.types.core.Expr.to_pyarrow)
Examples
--------
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.examples.penguins.fetch().limit(5)
>>> t.bill_length_mm.to_list()
[39.1, 39.5, 40.3, None, 36.7]
"""
return self.to_pyarrow(**kwargs).to_pylist()


@public
class UnknownValue(Value):
Expand Down

0 comments on commit 8e904aa

Please sign in to comment.