docs: Remove inheritable docstrings#2427
Conversation
Worse than main, since there are no examples
Using [`inspect.getdoc`](https://docs.python.org/3/library/inspect.html#inspect.getdoc) gives you the inherited doc - which is what users will see
The other way was failing because v1 reuses its parent's docstring now
May help with #2427 (comment)
Will adapt this for the other tests
`tail`, `gather_every` are actually different
Every other case omits the warning for `v1`
|
Ahhh we had a nice streak of no unrelated downstream CI issues going there for a bit 😢 https://github.com/narwhals-dev/narwhals/actions/runs/14629063988/job/41047719471?pr=2427 UpdateResolved in (#2428) |
Feedback please!We have a few options for dealing with the missing class-level docstrings. Important Method-level docstrings are fine 1. Revert that partSimplest option, lowers my code-golf score but no issues beyond that 🙂 2. Getting funkyI can get them to appear statically, but only when the constructor is called: Locally, I've adapted the typing I used in Bad newsBut that doesn't extend to hovering over the class itself 😞 3. Getting funkierIf we did something more dynamic we could get the class-level doc. It might be possible to combine 2 & 3, but I don't know if they'd interact well across all environments. Personal note99% of the time I have kernel completions disabled - since I find them too noisy with So while I'm presenting this as an option - I'd prefer an alternative for my own sake 😄 "jupyter.enableKernelCompletions": false |
|
thanks @dangotbanned ! tbh I don't think we need class-level docstrings too much, no objections to removing them |
Thanks for taking a look @MarcoGorelli I can't tell if you were saying either:
For the example I gave in (#2427 (comment)) I can understand why they might not seem like a big loss - since we're just missing an admonition. However, there's also MainV1 (currently in this PR)V1 (using 2. Getting funky)Also includes an example we didn't have before |
MarcoGorelli
left a comment
There was a problem hiding this comment.
thanks @dangotbanned , changes to docstrings look good
could you summarise the gist of the change in tests/stable_api_test.py please?
See examples in (#2427 (comment))
…ev/narwhals into remove-inherited-docs
Resolves #2427 (comment)
| def _iter_api_method_docs(obj: Any, *exclude: str) -> Iterator[tuple[str, str]]: | ||
| for name in dir(obj): | ||
| if ( | ||
| not name.startswith("_") | ||
| and name not in exclude | ||
| and (doc := getdoc(getattr(obj, name))) | ||
| ): | ||
| yield name, doc |
There was a problem hiding this comment.
could you summarise the gist of the change in tests/stable_api_test.py please?
Getting gist-y with it
@MarcoGorelli the changes are centred on this new helper generator function, which mostly is just replacing the repetition in each of:
test_dataframe_docstringstest_lazyframe_docstringstest_series_docstrings
Notes
- Used
dir(...)instead of__dir__() - Collapsed the various
if <predicate>: continuestatements into one that can be parametrized- The groups in
test_lazyframe_docstringswith comments became the name of variables passed to*exclude- This is intended to make the code self-documenting, but it seems to have not worked 😢
- The groups in
- Used
inspect.getdoc(...)instead of__doc__
|
https://github.com/narwhals-dev/narwhals/actions/runs/14693968316/job/41233109700?pr=2427 @MarcoGorelli this seems to have popped up after merging (#2325) 🤔 |










What type of PR is this? (check all applicable)
Related issues
Checklist
If you have comments or can explain your changes, please do so below
https://docs.python.org/3/library/inspect.html#inspect.getdoc
AFAIK, adding docstrings in the
v1classes/methods is probably doing more harm than good:I think we should only be adding docstrings if they are different to what is on main.
Things like deprecations, breaking changes, etc
Examples
Before
narwhals/narwhals/stable/v1/__init__.py
Lines 233 to 244 in f47ad1f
After
narwhals/narwhals/stable/v1/__init__.py
Lines 183 to 185 in a571160
Tasks
3.13is working, but all earlier versions break formattingstable_api_testwith less copy/pastingv1DataFrameLazyFrameSeriesExprSchemaDatetimeDuration