Skip to content

Commit 47c84e5

Browse files
DOC: update whatsnew section for pd.col()
1 parent dd791df commit 47c84e5

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,18 @@ and will be removed in pandas 4.0.
130130

131131
.. _whatsnew_300.enhancements.col:
132132

133-
``pd.col`` syntax can now be used in :meth:`DataFrame.assign` and :meth:`DataFrame.loc`
134-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
133+
Initial support for ``pd.col()`` syntax to create expressions
134+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
135135

136-
You can now use ``pd.col`` to create callables for use in dataframe methods which accept them. For example, if you have a dataframe
136+
This release introduces :func:`col` to refer to a DataFrame column by name
137+
and build up expressions.
138+
139+
This can be used as a simplified syntax to create callables for use in
140+
methods such as :meth:`DataFrame.assign`. In practice, where you would
141+
have to use a ``lambda`` function before, you can now use ``pd.col()``
142+
instead.
143+
144+
For example, if you have a dataframe
137145

138146
.. ipython:: python
139147
@@ -151,6 +159,18 @@ you can now write:
151159
152160
df.assign(c = pd.col('a') + pd.col('b'))
153161
162+
The expression object returned by :func:`col` supports all standard operators
163+
(like ``+``, ``-``, ``*``, ``/``, etc.) and all Series methods and namespaces
164+
(like ``pd.col("name").sum()``, ``pd.col("name").str.upper()``, etc.).
165+
166+
Currently, the ``pd.col()`` syntax can be used in any place which accepts a
167+
callable that takes the calling DataFrame as first argument and returns a
168+
Series, like ``lambda df: df[col_name]``.
169+
This includes :meth:`DataFrame.assign`, :meth:`DataFrame.loc`, and getitem/setitem.
170+
171+
It is expected that the support for ``pd.col()`` will be expanded to more methods
172+
in future releases.
173+
154174
New Deprecation Policy
155175
^^^^^^^^^^^^^^^^^^^^^^
156176
pandas 3.0.0 introduces a new 3-stage deprecation policy: using ``DeprecationWarning`` initially, then switching to ``FutureWarning`` for broader visibility in the last minor version before the next major release, and then removal of the deprecated functionality in the major release. This was done to give downstream packages more time to adjust to pandas deprecations, which should reduce the amount of warnings that a user gets from code that isn't theirs. See `PDEP 17 <https://pandas.pydata.org/pdeps/0017-backwards-compatibility-and-deprecation-policy.html>`_ for more details.

pandas/core/col.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ def col(col_name: Hashable) -> Expression:
260260
:meth:`DataFrame.assign` or :meth:`DataFrame.loc`, can also accept
261261
``pd.col(col_name)``.
262262
263+
.. versionadded:: 3.0.0
264+
263265
Parameters
264266
----------
265267
col_name : Hashable

0 commit comments

Comments
 (0)