Skip to content

DOC: Ex03 errors docstrings #56905

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

Merged
merged 12 commits into from
Jan 18, 2024

Conversation

luke396
Copy link
Contributor

@luke396 luke396 commented Jan 16, 2024

pandas.io.formats.style.Styler.map

image

pandas.io.formats.style.Styler.apply_index

image

pandas.io.formats.style.Styler.map_index

image

pandas.io.formats.style.Styler.format

image

@luke396 luke396 requested a review from attack68 as a code owner January 16, 2024 07:26
Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just there is one thing I don't fully understand, but seems like an error.

If it makes things clearer, you can check the rendered version of your changes here: https://pandas.pydata.org/preview/56905/

Maybe seeing the final result helps clarify what that variable you are changing does.

@@ -1968,7 +1968,7 @@ def apply_index(
input_note="an index value, if an Index, or a level value of a MultiIndex",
output_note="CSS styles as a string",
var="v",
ret='"background-color: yellow;" if v == "B" else None',
ret='"background-color: yellow;" if s == "B" else None',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this change, aren't we breaking things? Seems like the variable is indeed v above, no? Sorry if I'm missing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are correct. The variable in question is indeed v.

I had initially changed it to s due to another error, but upon further investigation, it appears that the error has either disappeared or was simply a result of my oversight. In any case, the correct designation for now should be v. Thank you for pointing that out!

Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @luke396, looks great.

@luke396
Copy link
Contributor Author

luke396 commented Jan 16, 2024

Uh, @datapythonista I believe the CI failure is connected to the variable we discussed earlier.

It seems related to map_index and apply_index, because the doc is dynamic.

When scripts/validate_docstrings.py --format=actions --errors=EX03 pandas.io.formats.style.Styler.map_index;

image

@luke396
Copy link
Contributor Author

luke396 commented Jan 16, 2024

And if we back to s, it seems reasonable. And indeed the ret and ret2 related to different variable.

image

Part of the output of scripts/validate_docstrings.py --format=actions --errors=EX03 pandas.io.formats.style.Styler.map_index
image

@luke396
Copy link
Contributor Author

luke396 commented Jan 16, 2024

I'm attempting to address it in a more sensible manner. When considering changing 's' in 'ret', which option do you think is preferable, @datapythonista?

@datapythonista
Copy link
Member

I think one of the tricky parts of that docstring is that it's a template reused in more than one place, so we'll have to make sure that all the resulting docstrings look good.

I guess the problem may be that linting is not happy with variables with only one character. Ideally we want to understand the example, and use a variable name that is meaningful instead. If you can't find a good name, maybe something like value can be good enough. In this case it does seem like the input of the function is the label of the index. Maybe label is an option too.

@luke396
Copy link
Contributor Author

luke396 commented Jan 16, 2024

I guess the problem may be that linting is not happy with variables with only one character.

The previous error doesn't appear to be solely due to using a one-character variable name. Instead, I believe it stems from the fact that in

https://github.com/pandas-dev/pandas/blob/e3796929283c91f0f96fed3d37b2e85bf4007ef9/pandas/io/formats/style.py#L1936-L1937C29

s is not set as {var} for reuse. Consequently, when {ret} is replaced with another value where s is not present in {ret}, it triggers an error

My latest solution involves setting s to {var}, aligning with our initial expectations. The oversight was simply due to a minor lapse in proper configuration. I'm glad to report that the CI is now passing successfully.

In this case it does seem like the input of the function is the label of the index. Maybe label is an option too

If I am not mistaken, I plan to enhance the readability and precision of the variable names in the example.

@datapythonista
Copy link
Member

Thanks @luke396, I had a look at https://pandas.pydata.org/preview/56905/docs/reference/api/pandas.io.formats.style.Styler.apply_index.html#pandas.io.formats.style.Styler.apply_index and everything seem perfect with the variable name now.

Thanks a lot for the work on this.

@datapythonista datapythonista merged commit f459437 into pandas-dev:main Jan 18, 2024
@luke396 luke396 deleted the ex03-errors-docstrings branch January 18, 2024 06:41
pmhatre1 pushed a commit to pmhatre1/pandas-pmhatre1 that referenced this pull request May 7, 2024
* Fix exo3 and remove unused code

* Remove unused in code_checks

* Fix 's' to 'v' in Styler.map_index() method

* Try set 's' to {var}

* Use `label` for more readable variable name

* Fix merge mistake

* Fix merge error

---------

Co-authored-by: Marc Garcia <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants