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
2 changes: 2 additions & 0 deletions leanframe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
"""LeanFrame provides a DataFrame API for BigQuery."""

from leanframe.core.session import Session
from leanframe.core.expression import col
from leanframe.core.frame import DataFrameHandler
from leanframe.core.nested_handler import NestedHandler
from leanframe.version import __version__

__all__ = [
"__version__",
"Session",
"col",
"DataFrameHandler",
"NestedHandler",
]
6 changes: 6 additions & 0 deletions leanframe/core/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@

from __future__ import annotations

import ibis
import ibis.expr.types as ibis_types


def col(name: str) -> Expression:
"""Return a new expression object which is a deferred series."""
return Expression(ibis.deferred[name])


class Expression:
"""A wrapper around an Ibis expression for deferred computation."""

Expand Down
7 changes: 2 additions & 5 deletions leanframe/core/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import ibis.expr.types as ibis_types
import pandas

from leanframe.core.expression import col

_ALPHABET = "abcdefghijklmnopqrstufwxyz"

Expand Down Expand Up @@ -67,8 +68,4 @@ def DataFrame(self, data: ibis_types.Table | pandas.DataFrame):
f"DataFrame constructor doesn't support {type(data)} data yet."
)

def col(self, name: str):
"""Return a new expression object which is a deferred series."""
import leanframe.core.expression

return leanframe.core.expression.Expression(ibis.deferred[name])
col = staticmethod(col)
44 changes: 44 additions & 0 deletions tests/unit/test_expression_col.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2025 Google LLC, LeanFrame Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests for standalone col and aliases."""

import ibis
import leanframe
from leanframe.core.session import Session
from leanframe.core.expression import Expression, col

def test_col_standalone():
"""Verify col() works as a standalone function."""
expr = col('a')
assert isinstance(expr, Expression)

def test_col_session_static():
"""Verify Session.col() works as a static method."""
expr = Session.col('a')
assert isinstance(expr, Expression)

def test_col_session_instance():
"""Verify session.col() works as an instance method (compatibility)."""
# Use sqlite backend as dummy
backend = ibis.sqlite.connect()
session = Session(backend)

expr = session.col('a')
assert isinstance(expr, Expression)

def test_col_package_alias():
"""Verify leanframe.col is available."""
expr = leanframe.col('a')
assert isinstance(expr, Expression)