Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay Chia committed Jan 26, 2024
1 parent 633b232 commit d1d4d05
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 10 deletions.
3 changes: 2 additions & 1 deletion daft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def get_build_type() -> str:
from daft.daft import ImageFormat, ImageMode, ResourceRequest
from daft.dataframe import DataFrame
from daft.datatype import DataType, TimeUnit
from daft.expressions import col, lit
from daft.expressions import Expression, col, lit
from daft.io import from_glob_path, read_csv, read_iceberg, read_json, read_parquet
from daft.series import Series
from daft.udf import udf
Expand All @@ -85,6 +85,7 @@ def get_build_type() -> str:
"read_parquet",
"read_iceberg",
"DataFrame",
"Expression",
"col",
"DataType",
"ImageMode",
Expand Down
27 changes: 26 additions & 1 deletion daft/expressions/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,31 @@
from daft.io import IOConfig


if True:

print("*****************************DETECTED SPHINX BUILD**************************************")

from typing import Any

# when building docs (with Sphinx) we need access to the functions
# associated with the namespaces from the class, as we don't have
# an instance; @sphinx_accessor is a @property that allows this.
NS = TypeVar("NS")

class sphinx_accessor(property): # noqa: D101
def __get__( # type: ignore[override]
self,
instance: Any,
cls: type[NS],
) -> NS:
try:
return self.fget(instance if isinstance(instance, cls) else cls) # type: ignore[misc]
except (AttributeError, ImportError):
return self # type: ignore[return-value]

property = sphinx_accessor


def lit(value: object) -> Expression:
"""Creates an Expression representing a column with every value set to the provided value
Expand Down Expand Up @@ -72,7 +97,7 @@ def col(name: str) -> Expression:


class Expression:
_expr: _PyExpr
_expr: _PyExpr = None

def __init__(self) -> None:
raise NotImplementedError("We do not support creating a Expression via __init__ ")
Expand Down
2 changes: 1 addition & 1 deletion docs/source/api_docs/creation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Data Catalogs
-------------

Apache Iceberg
^^^^^^^^^^^^^^
~~~~~~~~~~~~~~

.. autosummary::
:nosignatures:
Expand Down
48 changes: 48 additions & 0 deletions docs/source/api_docs/expressions.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,54 @@
Expressions
===========

Daft Expressions allow you to express some computation that needs to happen in a DataFrame.

This page provides an overview of all the functionality that is provided by Daft Expressions.

.. currentmodule:: daft

Constructors
############

Generic
#######

Numeric
#######

Logical
#######

Strings
#######

The following methods are available under the ``expr.str`` attribute.

.. autosummary::
:toctree: doc_gen/expression_methods
:template: autosummary/accessor_method.rst

Expression.str.contains
Expression.str.startswith

Temporal
########

List
####

Struct
######

Image
#####

Partitioning
############

URLs
####

.. toctree::
:hidden:
:maxdepth: 1
Expand Down
15 changes: 11 additions & 4 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import inspect
import subprocess

import sphinx_autosummary_accessors

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
project = "Daft"
Expand Down Expand Up @@ -38,9 +40,10 @@
"IPython.sphinxext.ipython_console_highlighting",
"myst_nb",
"sphinx_copybutton",
"sphinx_autosummary_accessors",
]

templates_path = ["_templates"]
templates_path = ["_templates", sphinx_autosummary_accessors.templates_path]


# -- Options for Notebook rendering
Expand Down Expand Up @@ -91,7 +94,9 @@
def linkcode_resolve(domain, info):
assert domain == "py", "expected only Python objects"
mod = importlib.import_module(info["module"])
if "." in info["fullname"]:
if "." not in info["fullname"]:
obj = getattr(mod, info["fullname"])
elif info["fullname"].count(".") == 1:
objname, attrname = info["fullname"].split(".")
obj = getattr(mod, objname)
try:
Expand All @@ -100,8 +105,10 @@ def linkcode_resolve(domain, info):
except AttributeError:
# object is an attribute of a class
return None
else:
obj = getattr(mod, info["fullname"])
# Accessor methods with 2 "."s
elif info["fullname"].count(".") == 2:
objname, accessor_name, method_name = info["fullname"].split(".")
obj = getattr(getattr(getattr(mod, objname), accessor_name), method_name)

# Handle case where object is a decorated function
while hasattr(obj, "__wrapped__"):
Expand Down
4 changes: 1 addition & 3 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,4 @@ Sphinx==5.3.0
sphinx-book-theme==1.1.0; python_version >= "3.9"
sphinx-reredirects>=0.1.1
sphinx-copybutton>=0.5.2
# sphinxcontrib-applehelp needs to be pinned as it dropped support for older versions of Sphinx
# See: https://github.com/sphinx-doc/sphinxcontrib-applehelp/pull/15#issuecomment-1890891611
sphinxcontrib-applehelp<=1.0.4
sphinx-autosummary-accessors==2023.4.0

0 comments on commit d1d4d05

Please sign in to comment.