Skip to content
Open
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
33 changes: 33 additions & 0 deletions doc/source/reference/api.typing.Expression.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
pandas.API.typing.expression
Copy link
Member

Choose a reason for hiding this comment

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

The API documentation is generated from docstrings, not added as files here directly.

Copy link
Author

Choose a reason for hiding this comment

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

You mean I should move this documentation into the Expression class docstring and remove the separate .rst page, index entry, correct?

Copy link
Member

Choose a reason for hiding this comment

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

We'd also need to add the Expression class to one of the API doc pages, yes. But as indicated in #63084 (comment), this might be opposed by others on the core team. I think we should ensure the core team is aligned here before moving forward.

============================

.. currentmodule:: pandas.api.typing

.. autoclass:: Expression
:members:
:undoc-members:
:show-inheritance:

**Description**

An ``Expression`` represents a symbolic reference to a DataFrame column.
Copy link
Member

Choose a reason for hiding this comment

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

This is false, pd.col("a") + 5 is not a reference to a column, but it is an expression.

It can be used inside functions like ``DataFrame.assign`` or ``DataFrame.loc`` to
refer to columns in a declarative way.

Example
-------

.. code-block:: python

import pandas as pd

df = pd.DataFrame({"a": [1, 2, 3]})
df.assign(b=pd.col("a") + 5)

**Supported Operations**

- Arithmetic: ``+``, ``-``, ``*``, ``/``
- Comparison: ``<``, ``>``, ``==``, ``!=``
- Universal functions (ufuncs): can be applied directly
- Series accessors: ``.dt``, ``.str``, ``.cat``
- Series methods: ``.sum()``, ``.mean()``, ``.astype()``, etc.
Comment on lines +29 to +33
Copy link
Member

@rhshadrach rhshadrach Nov 16, 2025

Choose a reason for hiding this comment

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

We should generate the methods that an expression supports when building the API docs, not hardcode them.

2 changes: 2 additions & 0 deletions doc/source/reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ to be stable.
testing
missing_value
aliases
api.typing.Expression


.. This is to prevent warnings in the doc build. We don't want to encourage
.. these methods.
Expand Down
Loading