Skip to content

STYLE ruff: enable PIE #51434

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 15 commits into from
Feb 22, 2023
Merged

STYLE ruff: enable PIE #51434

merged 15 commits into from
Feb 22, 2023

Conversation

ch1booze
Copy link
Contributor

@ch1booze ch1booze commented Feb 16, 2023

@MarcoGorelli MarcoGorelli changed the title Ran pre-commit and fixed all errors STYLE ruff: enable PIE Feb 16, 2023
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

thanks for working on this!

@@ -19,6 +19,7 @@ repos:
rev: v0.0.244
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Copy link
Member

Choose a reason for hiding this comment

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

can we not add this please? there's a few false positives which risk confusing contributors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. Would remove it.

@@ -836,8 +836,6 @@ def view(self, dtype: Dtype | None = None) -> Series:

# ----------------------------------------------------------------------
# NDArray Compat
_HANDLED_TYPES = (Index, ExtensionArray, np.ndarray)
Copy link
Member

Choose a reason for hiding this comment

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

why remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The error was PIE794. The fix that was suggested was removing one of the instances.

Copy link
Member

Choose a reason for hiding this comment

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

ah you're right, it is indeed duplicated. thanks!

@@ -875,7 +875,6 @@ class StataMissingValue:
float32_base = struct.pack("<i", int_value)

float64_base: bytes = b"\x00\x00\x00\x00\x00\x00\xe0\x7f"
increment = struct.unpack("q", b"\x00\x00\x00\x00\x00\x01\x00\x00")[0]
Copy link
Member

Choose a reason for hiding this comment

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

why remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The error was PIE794. The fix that was suggested was removing one of the instances.

Copy link
Member

Choose a reason for hiding this comment

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

thanks - I don't think we can remove it though

can you rename the first one to increment_32 and the second one to increment_64 please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have corrected this.

@@ -47,6 +47,7 @@
"outputs": [],
"source": [
"import matplotlib.pyplot\n",
"\n",
Copy link
Member

Choose a reason for hiding this comment

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

why did this file change?

Copy link
Contributor Author

@ch1booze ch1booze Feb 16, 2023

Choose a reason for hiding this comment

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

Happened after I formatted using black by running:

black .

in bash.
It seems like it would be better if I put the reasons behind my changes in the description. Would do that next time.

Copy link
Member

Choose a reason for hiding this comment

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

no worries - let's revert this, CI isn't running black-jupyter

Copy link
Member

Choose a reason for hiding this comment

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

if you run black via pre-commit run black --all-files then that'll match what's in CI

@ch1booze
Copy link
Contributor Author

@MarcoGorelli
There is a conflict here. How should it be resolved?

@MarcoGorelli
Copy link
Member

@MarcoGorelli There is a conflict here. How should it be resolved?

hey - I'd suggest looking at https://opensource.com/article/20/4/git-merge-conflict for how to resolve conflicts

@MarcoGorelli
Copy link
Member

looks like you managed, nice!

just need to revert changes to doc/source/user_guide/style.ipynb, if you do something like

git fetch upstream
git checkout upstream/main -- doc/source/user_guide/style.ipynb
git commit -a -m 'revert changes to doc/source/user_guide/style.ipynb'
git push origin HEAD

it should work

@mroeschke mroeschke added the Code Style Code style, linting, code_checks label Feb 16, 2023
@ch1booze
Copy link
Contributor Author

@MarcoGorelli
I think I am done with the requested changes barring any changes.

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

Nice work, looks good to me pending green

@ch1booze
Copy link
Contributor Author

Nice work, looks good to me pending green

@MarcoGorelli
Does that mean I could close the pull request? The reason for my asking is that I am also seeing a lot of errors popping up in the checks that are being carried out.
By the way, this would be my first open-source contribution, when completed. Thanks for the opportunity.

Comment on lines 202 to 214
CSS_EXPANSIONS = {
**{
{
(f"border-{prop}" if prop else "border"): _border_expander(prop)
for prop in ["", "top", "right", "bottom", "left"]
},
**{
{
f"border-{prop}": _side_expander(f"border-{{:s}}-{prop}")
for prop in ["color", "style", "width"]
},
**{
{
"margin": _side_expander("margin-{:s}"),
"padding": _side_expander("padding-{:s}"),
},
Copy link
Member

Choose a reason for hiding this comment

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

looks like this one is causing some test failures

Copy link
Member

Choose a reason for hiding this comment

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

You probably want

    CSS_EXPANSIONS = {
        **{
            (f"border-{prop}" if prop else "border"): _border_expander(prop)
            for prop in ["", "top", "right", "bottom", "left"]
        },
        **{
            f"border-{prop}": _side_expander(f"border-{{:s}}-{prop}")
            for prop in ["color", "style", "width"]
        },
        "margin": _side_expander("margin-{:s}"),
        "padding": _side_expander("padding-{:s}"),
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the PIE error that was generated.

@MarcoGorelli
Copy link
Member

@MarcoGorelli Does that mean I could close the pull request? The reason for my asking is that I am also seeing a lot of errors popping up in the checks that are being carried out.

when it's ready, we will merge it - but first, the errors need fixing up

@ch1booze
Copy link
Contributor Author

@MarcoGorelli Sorry, I have been away for a while. I have re-run and I still see the errors. Looking through to see where I might have gone wrong.

"column_dtypes": DictLike(**{"A": np.int8, "B": np.float32}),
"column_dtypes": DictLike({"A": np.int8, "B": np.float32}),
Copy link
Member

Choose a reason for hiding this comment

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

this isn't right, you want

"column_dtypes": DictLike(A=np.int8, B=np.float32),

you can run this test with

pytest pandas/tests/frame/methods/test_to_records.py

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Running pytest command is giving:

ImportError while loading conftest 'C:\Users\Victor Momodu\Documents\Programming\Data Science\Code\pandas\pandas\conftest.py'.      
pandas\__init__.py:22: in <module>
    from pandas.compat import is_numpy_dev as _is_numpy_dev  # pyright: ignore # noqa:F401
pandas\compat\__init__.py:25: in <module>
    from pandas.compat.numpy import (
pandas\compat\numpy\__init__.py:4: in <module>
    from pandas.util.version import Version
pandas\util\__init__.py:2: in <module>
    from pandas.util._decorators import (  # noqa:F401
pandas\util\_decorators.py:14: in <module>
    from pandas._libs.properties import cache_readonly
pandas\_libs\__init__.py:13: in <module>
    from pandas._libs.interval import Interval
E   ModuleNotFoundError: No module named 'pandas._libs.interval'

I have checked the module that was said to be missing and it exists. I searched and found this.

I have made the required change and will be pushing it to remote.

Copy link
Member

Choose a reason for hiding this comment

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

you need to follow the instructions here to run tests https://pandas.pydata.org/docs/dev/development/contributing_environment.html

@MarcoGorelli
Copy link
Member

@MarcoGorelli Sorry, I have been away for a while. I have re-run and I still see the errors. Looking through to see where I might have gone wrong.

no worries :) I've suggested a couple of fixes, the rest looks good!

Changed dtype_mappings and CSS_EXPANSIONS respectively.
Ran black pre-commit hook.
@ch1booze
Copy link
Contributor Author

@MarcoGorelli All tests passed. I guess merging can now be done.

@MarcoGorelli
Copy link
Member

yup, should be good, I'll just wait for a few more jobs to finish

@MarcoGorelli MarcoGorelli added this to the 2.1 milestone Feb 22, 2023
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

Thanks @victorian177 !

@MarcoGorelli MarcoGorelli merged commit 1b5370a into pandas-dev:main Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Style Code style, linting, code_checks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

STYLE ruff: enable PIE
3 participants