pandas_vet#

class pandas_vet.__init__.Visitor(errors=_Nothing.NOTHING)[source]#

Bases: NodeVisitor

ast.NodeVisitor calls the appropriate method for a given node type

i.e. calling self.visit on an Import node calls visit_import

The check functions should be called from the visit_ method that would produce a ‘fail’ condition.

visit_Import(node)[source]#

Called for import .. and import .. as .. nodes.

visit_Call(node)[source]#

Called for .method() nodes.

visit_Subscript(node)[source]#

Called for [slicing] nodes.

visit_Attribute(node)[source]#

Called for .attribute nodes.

visit_Name(node)[source]#

Called for Assignment nodes.

check(node)[source]#
generic_visit(node)[source]#

Called if no explicit visitor function exists for a node.

This also attaches breadcrumbs before visiting a node so we can later look up the syntax tree. This way, there’s more information to decide whether or not to raise.

The breadcrumb name is __pandas_vet_parent (name mangled) to avoid all reasonable name collisions.

See also

check_for_values.

exception pandas_vet.__init__.PandasVetException[source]#

Bases: Exception

class pandas_vet.__init__.VetPlugin(tree)[source]#

Bases: object

name = 'flake8-pandas-vet'#
version = '2023.8.2'#
run()[source]#
static add_options(optmanager)[source]#

Informs flake8 to ignore PD9xx by default.

static parse_options(optmanager, options, args)[source]#

Receives the parsed options and values.

pandas_vet.__init__.check_import_name(node: Import) List[source]#

Check AST for imports of pandas not using the preferred alias ‘pd’.

Error/warning message to recommend use of ‘pd’ alias.

Parameters

node (ast.Call) – An AST node of type Call

Returns

list of errors of type PD001 with line number and column offset

Return type

errors (List)

pandas_vet.__init__.check_inplace_false(node: Call) List[source]#

Check AST for function calls using inplace=True keyword argument.

Disapproved:

df.method(inplace=True)

Approved:

df = df.method(inplace=False)

Error/warning message to recommend avoidance of inplace=True due to inconsistent behavior.

Parameters

node (ast.Call) – An AST node of type Call

Returns

list of errors of type PD002 with line number and column offset

Return type

errors (List)

pandas_vet.__init__.check_for_isnull(node: Call) List[source]#

Check AST for function calls using the isnull() method.

Disapproved:

df.isnull()

Approved:

df.isna()

Error/warning message to recommend usage of .isna() instead of .isnull(). Functionality is equivalent.

Parameters

node (ast.Call) – An AST node of type Call

Returns

list of errors of type PD003 with line number and column offset

Return type

errors (List)

pandas_vet.__init__.check_for_notnull(node: Call) List[source]#

Check AST for function calls using the notnull() method.

Disapproved:

df.notnull()

Approved:

df.notna()

Error/warning message to recommend usage of .notna() instead of .notnull(). Functionality is equivalent.

Parameters

node (ast.Call) – An AST node of type Call

Returns

list of errors of type PD004 with line number and column offset

Return type

errors (List)

pandas_vet.__init__.check_for_arithmetic_methods(node: Call) List[source]#

Check AST for occurence of explicit arithmetic methods.

Error/warning message to recommend use of binary arithmetic operators.

pandas_vet.__init__.check_for_comparison_methods(node: Call) List[source]#

Check AST for occurence of explicit comparison methods.

Error/warning message to recommend use of binary comparison operators.

pandas_vet.__init__.check_for_ix(node: Subscript) List[source]#

Check AST for use of deprecated .ix[] attribute on data frame.

Error/warning message to recommend use of explicit .iloc[] or .loc[] instead.

pandas_vet.__init__.check_for_at(node: Subscript) List[source]#

Check AST for use of deprecated .at[] attribute on data frame.

Error/warning message to recommend use of explicit .loc[] instead.

pandas_vet.__init__.check_for_iat(node: Subscript) List[source]#

Check AST for use of deprecated .iat[] attribute on data frame.

Error/warning message to recommend use of explicit .iloc[] instead.

pandas_vet.__init__.check_for_pivot(node: Call) List[source]#

Check AST for occurence of the .pivot() method on the pandas data frame.

Error/warning message to recommend use of .pivot_table() method instead. This check should work for both the df.pivot() method, as well as the pd.pivot(df) function.

pandas_vet.__init__.check_for_unstack(node: Call) List[source]#

Check occurence of the .unstack() method on the pandas data frame.

Error/warning message to recommend use of .pivot_table() method.

pandas_vet.__init__.check_for_stack(node: Call) List[source]#

Check AST for occurence of the .stack() method on the pandas data frame.

Error/warning message to recommend use of .melt() method instead.

pandas_vet.__init__.check_for_values(node: Attribute) List[source]#

Check occurence of the .values attribute on the pandas data frame.

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 needs to check the node breadcrumb defined at Visitor.generic_visit, raising only in the first case.

See also

Visitor.generic_visit.

pandas_vet.__init__.check_for_read_table(node: Call) List[source]#

Check AST for occurence of the .read_table() method on the pandas object.

Error/warning message to recommend use of .read_csv() method instead.

pandas_vet.__init__.check_for_merge(node: Call) List[source]#

Check for use of .merge() method on the pandas object.

Error/warning message to recommend use of df.merge() method instead.

pandas_vet.__init__.check_for_df(node: Name) List[source]#

Check for variables named df

pandas_vet.__init__.error#

alias of Error