Skip to content

Commit 5372529

Browse files
KashifMarcoGorelli
Kashif
authored andcommitted
Updated script to check inconsistent pandas namespace
1 parent a170e97 commit 5372529

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

scripts/check_for_inconsistent_pandas_namespace.py

+20-25
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,17 @@
1717
PATTERN = r"""
1818
(
1919
(?<!pd\.)(?<!\w) # check class_name start with pd. or character
20-
{class_name}\( # match DataFrame but not pd.DataFrame or tm.makeDataFrame
20+
([A-Z]\w+)\( # match DataFrame but not pd.DataFrame or tm.makeDataFrame
2121
.* # match anything
22-
pd\.{class_name}\( # only match e.g. pd.DataFrame
22+
pd\.\2\( # only match e.g. pd.DataFrame
2323
)|
2424
(
25-
pd\.{class_name}\( # only match e.g. pd.DataFrame
25+
pd\.([A-Z]\w+)\( # only match e.g. pd.DataFrame
2626
.* # match anything
2727
(?<!pd\.)(?<!\w) # check class_name start with pd. or character
28-
{class_name}\( # match DataFrame but not pd.DataFrame or tm.makeDataFrame
28+
\4\( # match DataFrame but not pd.DataFrame or tm.makeDataFrame
2929
)
3030
"""
31-
CLASS_NAMES = (
32-
"Series",
33-
"DataFrame",
34-
"Index",
35-
"MultiIndex",
36-
"Timestamp",
37-
"Timedelta",
38-
"TimedeltaIndex",
39-
"DatetimeIndex",
40-
"Categorical",
41-
)
4231
ERROR_MESSAGE = "Found both `pd.{class_name}` and `{class_name}` in {path}"
4332

4433

@@ -47,16 +36,22 @@ def main(argv: Optional[Sequence[str]] = None) -> None:
4736
parser.add_argument("paths", nargs="*", type=Path)
4837
args = parser.parse_args(argv)
4938

50-
for class_name in CLASS_NAMES:
51-
pattern = re.compile(
52-
PATTERN.format(class_name=class_name).encode(),
53-
flags=re.MULTILINE | re.DOTALL | re.VERBOSE,
54-
)
55-
for path in args.paths:
56-
contents = path.read_bytes()
57-
match = pattern.search(contents)
58-
assert match is None, ERROR_MESSAGE.format(
59-
class_name=class_name, path=str(path)
39+
pattern = re.compile(
40+
PATTERN.encode(),
41+
flags=re.MULTILINE | re.DOTALL | re.VERBOSE,
42+
)
43+
for path in args.paths:
44+
contents = path.read_bytes()
45+
match = pattern.search(contents)
46+
if match is None:
47+
continue
48+
if match.group(2) is not None:
49+
raise AssertionError(
50+
ERROR_MESSAGE.format(class_name=match.group(2).decode(), path=str(path))
51+
)
52+
if match.group(4) is not None:
53+
raise AssertionError(
54+
ERROR_MESSAGE.format(class_name=match.group(4).decode(), path=str(path))
6055
)
6156

6257

0 commit comments

Comments
 (0)