diff --git a/.gitattributes b/.gitattributes index c63a5474eb62..b1c973f2d6cd 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/.gitignore b/.gitignore index 5389b17db1cd..7de0c4419340 100644 --- a/.gitignore +++ b/.gitignore @@ -153,3 +153,7 @@ docs/**/*.html .jupyterlite.doit.db docs/jupyter_lite_config.json *.quarto_ipynb + +# pixi environments +.pixi +*.egg-info diff --git a/ibis/backends/tests/test_export.py b/ibis/backends/tests/test_export.py index f7ac43e4c22a..f8c93ecbc8f9 100644 --- a/ibis/backends/tests/test_export.py +++ b/ibis/backends/tests/test_export.py @@ -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) diff --git a/ibis/expr/types/generic.py b/ibis/expr/types/generic.py index 16e0b9583346..132b98c674d9 100644 --- a/ibis/expr/types/generic.py +++ b/ibis/expr/types/generic.py @@ -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 ---------- @@ -1211,8 +1211,8 @@ def to_pandas(self, **kwargs) -> pd.Series: -------- >>> import ibis >>> ibis.options.interactive = True - >>> t = ibis.examples.penguins.fetch().limit(5) - >>> t.to_pandas() + >>> t = ibis.examples.penguins.fetch() + >>> t.to_pandas(limit=5) species island bill_length_mm ... body_mass_g sex year 0 Adelie Torgersen 39.1 ... 3750.0 male 2007 1 Adelie Torgersen 39.5 ... 3800.0 female 2007 @@ -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() + >>> t.bill_length_mm.to_list(limit=5) + [39.1, 39.5, 40.3, None, 36.7] + """ + return self.to_pyarrow(**kwargs).to_pylist() + @public class UnknownValue(Value):