Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: parameterize "See Also" content in read_table and read_csv so that only the other function appears #53848

Merged
merged 3 commits into from
Jun 26, 2023

Conversation

tpaxman
Copy link
Contributor

@tpaxman tpaxman commented Jun 25, 2023

Note: this was the least invasive way to update it and I think it's probably sufficient. The only duplication introduced would be repeating the "summary" lines for each of the functions. If that were a concern, I would suggest making another update where the docstring string formatting parameters are abstracted away once more by introducing something like this:

Define this function in the file:

def _generate_docstring_formatter(func_name: Literal["read_csv", "read_table"]) -> dict:
    func_details = {
        "read_csv": {
            "summary": "Read a comma-separated values (csv) file into DataFrame.",
            "_default_sep": "','",
        },
        "read_table": {
            "summary": "Read general delimited file into DataFrame.",
            "_default_sep": r"'\\t' (tab-stop)",
        }
    }
    see_also_func_name = "read_table" if (func_name == "read_csv") else "read_csv"
    return dict(
        func_name=func_name,
        summary=func_details[func_name]["summary"],
        _default_sep=func_details[func_name]["_default_sep"],
        see_also_func_name=see_also_func_name,
        see_also_func_summary=func_details[see_also_func_name]["summary"],
        storage_options=_shared_docs["storage_options"],
        decompression_options=_shared_docs["decompression_options"]
        % "filepath_or_buffer",
    )

Then replace the two @Appender decorator calls with these instead:

# for read_csv:
@Appender(_doc_read_csv_and_table.format(**_generate_docstring_formatter("read_csv")))

# for read_table:
@Appender(_doc_read_csv_and_table.format(**_generate_docstring_formatter("read_table")))

I have tested this and it also works but I was unsure whether it's worthwhile (in the maintainers' view) to make that change to avoid a one-line duplication case. Curious to hear feedback though!

@mroeschke mroeschke added Docs IO CSV read_csv, to_csv labels Jun 26, 2023
@mroeschke mroeschke added this to the 2.1 milestone Jun 26, 2023
@mroeschke mroeschke merged commit 4823492 into pandas-dev:main Jun 26, 2023
@mroeschke
Copy link
Member

Thanks @tpaxman

@tpaxman tpaxman deleted the issue53847 branch June 26, 2023 22:20
Daquisu pushed a commit to Daquisu/pandas that referenced this pull request Jul 8, 2023
…o that only the other function appears (pandas-dev#53848)

* parameterize the "see also" function for read_csv and read_table docstrings to always show the other

* fix long line formatting issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs IO CSV read_csv, to_csv
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DOC: read_csv docstring incorrectly references itself in the "See Also" section
2 participants