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/BUG: 'See Also' section in Index.item error #58436

Closed
1 task done
shriyakalakata opened this issue Apr 25, 2024 · 2 comments
Closed
1 task done

DOC/BUG: 'See Also' section in Index.item error #58436

shriyakalakata opened this issue Apr 25, 2024 · 2 comments
Labels
Docs Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@shriyakalakata
Copy link
Contributor

Pandas version checks

  • I have checked that the issue still exists on the latest versions of the docs on main here

Location of the documentation

https://pandas.pydata.org/docs/reference/api/pandas.Index.item.html

Documentation problem

The source code for pandas.Index.item points to a function that doesn't have the See Also section. However, the function in the source code does have the See Also function. Yet, the See Also section is not displayed in the pandas.Index.item docstring. Furthermore, running the scripts/validate_docstrings.py --format=actions pandas.Index.item command doesn't raise a SA01 error (i.e. See Also section isn't missing).

The source link in the pandas.Index.item page points towards

    @final
    def item(self):
        """
        Return the first element of the underlying data as a Python scalar.

        Returns
        -------
        scalar
            The first element of Series or Index.

        Raises
        ------
        ValueError
            If the data is not length = 1.

        Examples
        --------
        >>> s = pd.Series([1])
        >>> s.item()
        1

        For an index:

        >>> s = pd.Series([1], index=['a'])
        >>> s.index.item()
        'a'
        """
        if len(self) == 1:
            return next(iter(self))
        raise ValueError("can only convert an array of size 1 to a Python scalar")

However, when looking at that file and function, we see the following code:

@final
    def item(self):
        """
        Return the first element of the underlying data as a Python scalar.

        Returns
        -------
        scalar
            The first element of Series or Index.

        Raises
        ------
        ValueError
            If the data is not length = 1.

        See Also
        --------
        Index.values : Returns an array representing the data in the Index.
        Series.head : Returns the first `n` rows.

        Examples
        --------
        >>> s = pd.Series([1])
        >>> s.item()
        1

        For an index:

        >>> s = pd.Series([1], index=["a"])
        >>> s.index.item()
        'a'
        """
        if len(self) == 1:
            return next(iter(self))
        raise ValueError("can only convert an array of size 1 to a Python scalar")

Suggested fix for documentation

@shriyakalakata shriyakalakata added Docs Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 25, 2024
@Aloqeely
Copy link
Contributor

You are viewing the stable docs (v2.2.2) and at the time of the release there wasn't a 'See Also' section in the docstring. If you view the dev docs then you will see the 'See Also' section

https://pandas.pydata.org/docs/dev/reference/api/pandas.Index.item.html

@shriyakalakata
Copy link
Contributor Author

@Aloqeely I see thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

2 participants