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

Double click on function parameter selects parameter type as well #427

Closed
12rambau opened this issue Aug 29, 2022 · 4 comments
Closed

Double click on function parameter selects parameter type as well #427

12rambau opened this issue Aug 29, 2022 · 4 comments
Assignees
Milestone

Comments

@12rambau
Copy link

This issue was initially opened by @rok here: pydata/pydata-sphinx-theme#388.

When I want to copy a name of a function parameter I typically double-click it to select. Normally that would select the entire parameter and I can now copy and paste it elsewhere.
Here however there seems to be a css or js setting that causes the double click to select the parameter type as well. When I copy it the name of parameter is concatenated to type string without space in between. E.g. double clicking and copy-pasting parameter data from here will result in a string datastructured. Ideally it would result only in data.

After some digging and some help from SO, I think I identified the issue. The problem comes from the structure of the dt line. if everything is written without spaces and without line break it behave as described in the issue:

<dt>
  <strong>data</strong><span class="classifier">structured ndarray, sequence of tuples or dicts, or DataFrame</span>
</dt>

if on the other hand you add an extra space you are good to go

<dt>
  <strong>data</strong> <span class="classifier">structured ndarray, sequence of tuples or dicts, or DataFrame</span>
</dt>

If you can point me to where this html is generated, I would be happy to make a PR

PS: see this copen to have a demo of the different behaviours: https://codepen.io/12rambau/pen/mdXQayr

@jarrodmillman jarrodmillman added this to the 1.5.0 milestone Sep 9, 2022
@rossbar
Copy link
Contributor

rossbar commented Sep 9, 2022

If you can point me to where this html is generated, I would be happy to make a PR

The html is not directly generated by numpydoc - rather, numpydoc converts from numpydoc-flavored rst -> sphinx-flavored rst, which is then parsed by docutils and eventually converted to html via the sphinx html builder.

FWIW you can see what numpydoc produces via something like (using the original docstring as an example):

>>> from numpydoc.docscrape_sphinx import SphinxDocString
>>> import pandas as pd
>>> sds = SphinxDocString(pd.DataFrame.from_records.__doc__)
>>> print(sds)

Which gives (only showing printed output through the Parameters section):

Convert structured or record ndarray to DataFrame.

Creates a DataFrame object from a structured ndarray, sequence of
tuples or dicts, or DataFrame.

:Parameters:

    **data** : structured ndarray, sequence of tuples or dicts, or DataFrame
        Structured input data.

    **index** : str, list of fields, array-like
        Field of array to use as the index, alternately a specific set of
        input labels to use.

    **exclude** : sequence, default None
        Columns or fields to exclude.

    **columns** : sequence, default None
        Column names to use. If the passed data do not have names
        associated with them, this argument provides names for the
        columns. Otherwise this argument indicates the order of the columns
        in the result (any names not found in the data will become all-NA
        columns).

    **coerce_float** : bool, default False
        Attempt to convert values of non-string, non-numeric objects (like
        decimal.Decimal) to floating point, useful for SQL result sets.

    **nrows** : int, default None
        Number of rows to read if data is an iterator.

The subsequent conversion to html is handled by docutils/sphinx.

PS: see this copen to have a demo of the different behaviours: https://codepen.io/12rambau/pen/mdXQayr

Maybe I've misunderstood, but I see the same behavior for all three lines from the linked example w.r.t double-clicking the type description (the whole row is highlighted, including the data)

@12rambau
Copy link
Author

12rambau commented Sep 11, 2022

Maybe I've misunderstood, but I see the same behavior for all three lines from the linked example w.r.t double-clicking the type description (the whole row is highlighted, including the data)

yep my point is when you double click on data, the selection won't be the same. specificatlly in this case, double clicking on data in the first case select "data" and "structured".

The subsequent conversion to html is handled by docutils/sphinx.

Let me port this issue to sphinx then

@12rambau
Copy link
Author

I found a solution in pydata/pydata-sphinx-theme#1015. A simple CSS trick and the problem was gone. As numpydoc is not setting extra CSS I'll close this issue.

@larsoner
Copy link
Collaborator

Great, thanks for following up @12rambau !

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

No branches or pull requests

4 participants