Skip to content

Docstring guidelines #1943

@MarcoGorelli

Description

@MarcoGorelli

In #1942 I mentioned a desire to keep the package size down. One way to do this is by reducing overly-long docstrings.

Here are some general guidelines:

  • The examples should be clear and to-the-point
  • Most docstrings should just be:
    • import dataframe library (usually pandas, pyarrow, or duckdb)
    • import narwhals
    • construct native dataframe. Make it as small as possible: 2 rows and 2 columns should be plenty for most docstrings
    • call nw.from_native and apply operation
    • only show a single example
  • Variety between docstrings is encouraged, they don't all need to follow the same exact template. They can use different libraries, some can end with to_native, some can use selectors or nw.all...this is all OK. Just keep it minimal
  • Essential functionality (such as DataFrame.filter, DataFrame.with_columns, DataFrame.select), it's OK to have even 2-3 examples showing different ways to use it
  • For examples which use null values, use a library with proper support for them (i.e. not pandas with classical data types). Such docstrings should also link to the pandas null handling page

Also, the reason many of the current docstrings are so long is because that's how I'd originally encouraged them to be. I think that was a mistake on my part, I need to acknowledge this, and as the project has evolved, it's time to revisit

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions