Skip to content
This repository was archived by the owner on Feb 19, 2023. It is now read-only.

Commit edef1a3

Browse files
committed
license
1 parent e6f4511 commit edef1a3

File tree

7 files changed

+63
-18
lines changed

7 files changed

+63
-18
lines changed

LICENSES/LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2017 Anthony Sottile
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

pandas_style_guide/__main__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22
import tokenize
3-
3+
import os
44

55
import ast
66
import importlib.metadata
@@ -14,8 +14,8 @@
1414

1515

1616
class Plugin:
17-
name = __name__
18-
version = 1#importlib.metadata.version(__name__)
17+
name = os.path.split(os.path.dirname(__file__))[-1]
18+
version = importlib.metadata.version(name)
1919

2020
def __init__(self, tree: ast.AST):
2121
self._tree = tree

pandas_style_guide/_data.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ def visit(funcs, tree: ast.Module) -> Dict[int, List[int]]:
4848
for name in reversed(node._fields):
4949
value = getattr(node, name)
5050
if name in {"annotation", "returns"}:
51-
next_in_annotation = True
51+
next_state = state._replace(in_annotation=True)
5252
else:
53-
next_in_annotation = state
53+
next_state = state
5454
if isinstance(value, ast.AST):
55-
nodes.append((next_in_annotation, value, node))
55+
nodes.append((next_state, value, node))
5656
elif isinstance(value, list):
5757
for value in reversed(value):
5858
if isinstance(value, ast.AST):
59-
nodes.append((next_in_annotation, value, node))
59+
nodes.append((next_state, value, node))
6060

6161
def _import_plugins() -> None:
6262
# https://github.com/python/mypy/issues/1422
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
import ast
3+
from pandas_style_guide._data import register
4+
from pandas_style_guide._ast_helpers import is_name_attr
5+
6+
MSG = 'PSG010 namespace inconsistency'
7+
@register(ast.Attribute)
8+
def visit_Attribute(state, node: ast.Attribute, parent) -> None:
9+
if node.attr in state.from_imports['pandas'] and isinstance(node.value, ast.Name) and node.value.id in {'pandas', 'pd'}:
10+
yield node.lineno, node.col_offset, MSG
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
import ast
3+
from pandas_style_guide._data import register
4+
from pandas_style_guide._ast_helpers import is_name_attr
5+
6+
MSG = 'PSG010 union'
7+
8+
@register(ast.Subscript)
9+
def visit_Subscript(state, node, parent):
10+
if isinstance(node.value, ast.Name) and node.value.id == 'Union':
11+
if isinstance(node.slice, ast.Index):
12+
tuple = node.slice.value
13+
else:
14+
tuple = node.slice
15+
names = set()
16+
if isinstance(tuple, ast.Tuple):
17+
for elt in tuple.elts:
18+
if isinstance(elt, ast.Name):
19+
names.add(elt.id)
20+
if names == {'DataFrame', 'Series'}:
21+
yield node.lineno, node.col_offset, MSG

setup.cfg

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[metadata]
22
name = pandas-style-guide
3-
version = 2.11.0
4-
description = A tool to automatically upgrade syntax for newer versions.
3+
version = 0.0.1
4+
description = Linter for contributing to pandas
55
long_description = file: README.md
66
long_description_content_type = text/markdown
7-
url = https://github.com/asottile/pyupgrade
8-
author = Anthony Sottile
7+
url = https://github.com/MarcoGorelli/pandas-style-guide
8+
author = Marco Gorelli
99
author_email = [email protected]
1010
license = MIT
1111
license_file = LICENSE

t.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
import pandas
2-
import conftest
3-
from pandas.foo.bar.dude import _foo
1+
from typing import Union
42

5-
_foo._foo('dod')
6-
os.remove('a')
7-
from os import remove
8-
remove('f')
3+
a: Union[DataFrame, Series]

0 commit comments

Comments
 (0)