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

Change recommendation from .array/.to_array() to .to_numpy() #115

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ black --check pandas_vet setup.py tests --exclude tests/data

**PD010** '.pivot_table' is preferred to '.pivot' or '.unstack'; provides same functionality

**PD011** Use '.array' or '.to_array()' instead of '.values'; 'values' is ambiguous
**PD011** Use '.to_numpy()' instead of '.values'; 'values' is ambiguous

**PDO12** '.read_csv' is preferred to '.read_table'; provides same functionality

Expand Down
5 changes: 2 additions & 3 deletions pandas_vet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,7 @@ def check_for_values(node: ast.Attribute) -> List:
"""
Check occurence of the `.values` attribute on the pandas data frame.

Error/warning message to recommend use of `.array` data frame attribute
for PandasArray, or `.to_array()` method for NumPy array.
Error/warning message to recommend use of `.to_numpy()` method for NumPy array.

In order to discriminate `df.values` (where this check should raise) vs
calls, like `dict().values()` (where this should not), this function
Expand Down Expand Up @@ -430,7 +429,7 @@ def check_for_df(node: ast.Name) -> List:
"provides same functionality"
)
PD011 = VetError(
message="PD011 Use '.array' or '.to_array()' instead of '.values'; 'values' is ambiguous"
message="PD011 Use '.to_numpy()' instead of '.values'; 'values' is ambiguous"
)
PD012 = VetError(
message="PDO12 '.read_csv' is preferred to '.read_table'; provides same functionality"
Expand Down
18 changes: 3 additions & 15 deletions tests/test_PD011.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
"""
Test to check for use of the pandas dataframe `.array` attribute
or `.to_array()` method in preference to `.values` attribute.
Test to check for use of the pandas dataframe `.to_numpy()` method in preference to `.values` attribute.
"""
import ast

from pandas_vet import VetPlugin
from pandas_vet import PD011


def test_PD011_pass_to_array():
def test_PD011_pass_to_numpy():
"""
Test that using .to_array() explicitly does not result in an error.
Test that using .to_numpy() explicitly does not result in an error.
"""
statement = "result = df.to_array()"
tree = ast.parse(statement)
Expand All @@ -19,17 +18,6 @@ def test_PD011_pass_to_array():
assert actual == expected


def test_PD011_pass_array():
"""
Test that using .array explicitly does not result in an error.
"""
statement = "result = df.array"
tree = ast.parse(statement)
actual = list(VetPlugin(tree).run())
expected = []
assert actual == expected


def test_PD011_fail_values():
"""
Test that using .values data frame attribute results in an error.
Expand Down