Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(export): implement the Column.to_list() API #10498

Merged
merged 3 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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
19 changes: 16 additions & 3 deletions ibis/backends/tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,22 @@ def test_column_to_memory(limit, awards_players, output_format, expected_column_
method = methodcaller(f"to_{output_format}", limit=limit)
res = method(awards_players.awardID)
assert isinstance(res, getattr(mod, expected_column_type))
assert (limit is not None and len(res) == limit) or len(
res
) == awards_players.count().execute()
assert (
(len(res) == limit)
if limit is not None
else len(res) == 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 (
(len(res) == limit)
if limit is not None
else len(res) == awards_players.count().execute()
)


@pytest.mark.parametrize("limit", no_limit)
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is technically a broken link, since the docs aren't published... but so is

[`execute`]((#ibis.expr.types.core.Expr.execute)

used elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if want to start publishing the docs so the links work? A linkchecker might be nice at some point. :D

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a link checker -- maybe it doesn't work on quartodoc-generated links? But yeah, lychee is the link checker and there's a checklinks rule in the justfile, so I dunno.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, interesting, we do publish Column docs, but not inherited methods, so we're missing out on things like to_pyarrow.

Well, that's a separate concern


Examples
--------
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.examples.penguins.fetch().limit(5)
>>> t.bill_length_mm.to_list()
deepyaman marked this conversation as resolved.
Show resolved Hide resolved
[39.1, 39.5, 40.3, None, 36.7]
"""
return self.to_pyarrow(**kwargs).to_pylist()


@public
class UnknownValue(Value):
Expand Down