Skip to content

Commit

Permalink
Change recommendation from .array/.to_array() to .to_numpy()
Browse files Browse the repository at this point in the history
Closes #113
  • Loading branch information
KPLauritzen committed Aug 5, 2022
1 parent cea45ee commit 60c7965
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 19 deletions.
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

0 comments on commit 60c7965

Please sign in to comment.