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

Update flake8 to 7.1.1. #1458

Merged
merged 4 commits into from
Sep 20, 2024
Merged

Conversation

bdice
Copy link
Contributor

@bdice bdice commented Sep 17, 2024

Description

We need to update flake8 to fix a false-positive that appears with older flake8 versions on Python 3.12.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@bdice bdice requested review from a team as code owners September 17, 2024 17:25
@github-actions github-actions bot added the Python Related to Python code label Sep 17, 2024
@mroeschke mroeschke added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Sep 17, 2024
if type(geo1) != type(geo2):
assert TypeError
if type(geo1) is not type(geo2):
raise TypeError
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 previous code assert TypeError was definitely wrong (it doesn't raise!). But now I'm seeing test failures:

___________________________ test_cudf_dataframe_init ___________________________
[gw7] linux -- Python 3.10.15 /pyenv/versions/3.10.15/bin/python

    def test_cudf_dataframe_init():
        df = cudf.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
        gdf = cuspatial.GeoDataFrame(df)
>       assert_eq_geo_df(gdf.to_pandas(), df.to_pandas())

tests/test_geodataframe.py:465: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

geo1 =    a  b
0  1  4
1  2  5
2  3  6, geo2 =    a  b
0  1  4
1  2  5
2  3  6

    def assert_eq_geo_df(geo1, geo2):
        if type(geo1) is not type(geo2):
>           raise TypeError
E           TypeError

tests/test_geodataframe.py:97: TypeError

Copy link
Member

Choose a reason for hiding this comment

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

I wanted to help so looked into this a bit.

Here's the specific error I now see in the one failing test:

FAILED tests/test_geodataframe.py::test_cudf_dataframe_init - AssertionError: assert <class 'geopandas.geodataframe.GeoDataFrame'> is <class 'pandas.core.frame.DataFrame'>
 +  where <class 'geopandas.geodataframe.GeoDataFrame'> = type(   a  b\n0  1  4\n1  2  5\n2  3  6)
 +  and   <class 'pandas.core.frame.DataFrame'> = type(   a  b\n0  1  4\n1  2  5\n2  3  6)

(build link)

Here's the source code of that test:

def test_cudf_dataframe_init():
df = cudf.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
gdf = cuspatial.GeoDataFrame(df)
assert_eq_geo_df(gdf.to_pandas(), df.to_pandas())

It looks to me like it's intentional behavior that the cuspatial.GeoDataFrame.to_pandas() method actually returns a geopandas.GeoDataFrame, not a pandas.DataFrame.

def to_pandas(self, nullable=False):
"""
Calls `self.to_geopandas`, converting GeoSeries columns into GeoPandas
columns and cudf.Series columns into pandas.Series columns, and
returning a pandas.DataFrame.
Parameters
----------
nullable: matches the cudf `to_pandas` signature, not yet supported.
"""
return self.to_geopandas(nullable=nullable)

So I guess one of these has to happen:

  • cuspatial.GeoDataFrame.to_pandas() needs to start returning a pandas.DataFrame instead (as the name implies)
  • the have-the-same-type expectation needs to be removed from that test

Copy link
Contributor

Choose a reason for hiding this comment

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

From a cursory check, it appears the intention is for this check to assert that both arguments are geopandas.GeoDataFrame objects, so I think the usage here is incorrect.

I imagine the test should have been assert_eq_geo_df(gdf.to_pandas(), gpd.GeoDataFrame(df.to_pandas()))?

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'll try that locally. Thanks, that sounds like the right direction to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, that worked on my local build. I pushed the change. Thanks @mroeschke!

jameslamb added a commit to jameslamb/cuspatial that referenced this pull request Sep 20, 2024
@bdice
Copy link
Contributor Author

bdice commented Sep 20, 2024

/merge

@rapids-bot rapids-bot bot merged commit 43776f2 into rapidsai:branch-24.10 Sep 20, 2024
75 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvement / enhancement to an existing function non-breaking Non-breaking change Python Related to Python code
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

3 participants