Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Add docstring examples for Scalar trigonometric functions#1411

Merged
alamb merged 3 commits intoapache:mainfrom
rerun-io:nick/docstrings-scalar-trig
Mar 11, 2026
Merged

Add docstring examples for Scalar trigonometric functions#1411
alamb merged 3 commits intoapache:mainfrom
rerun-io:nick/docstrings-scalar-trig

Conversation

@ntjohnson1
Copy link
Contributor

Which issue does this PR close?

Rationale for this change

Adding doctested examples to the docstrings makes things nicer to use for humans and agents.

What changes are included in this PR?

The first PR was basically adding a docstring to everything in functions. I broke it apart into a PR (that already merged) for the infra. Then will do a variety of follow ups with groups of functions so it is easier to review. This is the first one to get feedback if this is a reasonable scope. Everything is co-authored with Claude since I used claude to extend the handwritten examples I wrote for reference and to split apart the large PR rather than doing it manually.

I've reviewed all the code prior to PR.

Are there any user-facing changes?

No

Add example usage to docstrings for Scalar trigonometric functions to improve documentation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@pytest.fixture(autouse=True)
def _doctest_namespace(doctest_namespace: dict) -> None:
"""Add common imports to the doctest namespace."""
doctest_namespace["dfn"] = dfn
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This auto imports dfn and np to save 2 lines in each example.

>>> from math import pi
>>> ctx = dfn.SessionContext()
>>> df = ctx.from_pydict({"a": [pi / 4]})
>>> import builtins
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we don't like builtins then doctest has an ellipses notation for the expected returned values as well.

Copy link
Contributor

@kosiew kosiew left a comment

Choose a reason for hiding this comment

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

@ntjohnson1

Thanks for working on this.

@@ -491,16 +491,28 @@ def abs(arg: Expr) -> Expr:
def acos(arg: Expr) -> Expr:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be helpful to extract shared example setup, or align the example style with existing docstrings.

Most of the new examples duplicate the same SessionContext / from_pydict / select / collect_column flow with only the function name and literal changing. That is fine for a few functions, but the repetition will get expensive as more scalar helpers gain examples.
It would be worth standardizing on a small doctest helper namespace or a more consistent public-facing import style so future additions do not copy-paste boilerplate across dozens of docstrings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think there is value in the examples being copy pastable/fully stand alone if it's only a few lines of boilerplate. For reference numpy https://numpy.org/doc/2.4/reference/generated/numpy.inner.html#numpy.inner.

Expensive computationally or for maintenance? This is inline with the style from the existing doc examples as far as I can tell https://github.com/rerun-io/datafusion-python/blob/231ed2b1d375fefe9aa01cdc8ae41c620c772f76/python/datafusion/dataframe.py#L324

Copy link
Contributor

Choose a reason for hiding this comment

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

I see your point and it is defensible that each example is self-contained.

Expensive computationally or for maintenance?

maintenance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, there is definitely a bit of maintenance trade off between the documentation value and pain if there is a large refactor that requires updating the docs examples.

I think there is value to the standalone but am open to opinions on this since I'm not a primary maintainer. My hope is that after the first large landing of these examples this is kind of just a small additional test surface so it's not more cumbersome than updating tests when api changes happen.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think given the rise of LLMs the maintenance is likely easier now

@alamb
Copy link
Contributor

alamb commented Mar 10, 2026

Thank you for helping this along @kosiew

Copy link
Contributor

@kosiew kosiew left a comment

Choose a reason for hiding this comment

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

lgtm

@alamb alamb merged commit 1160d5a into apache:main Mar 11, 2026
19 checks passed
@alamb
Copy link
Contributor

alamb commented Mar 11, 2026

🚀

@alamb
Copy link
Contributor

alamb commented Mar 11, 2026

Thanks again @ntjohnson1 and @kosiew

@ntjohnson1 ntjohnson1 deleted the nick/docstrings-scalar-trig branch March 11, 2026 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants