Skip to content

TYP: remove ignore from makeCustomIndex #39057

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

Merged
merged 1 commit into from
Jan 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions pandas/_testing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from collections import Counter
import collections
from datetime import datetime
from functools import wraps
import operator
import os
import re
import string
from typing import Callable, ContextManager, List, Type
from typing import Callable, ContextManager, Counter, List, Type
import warnings

import numpy as np
Expand Down Expand Up @@ -568,7 +568,7 @@ def makeCustomIndex(

assert all(x > 0 for x in ndupe_l)

tuples = []
list_of_lists = []
for i in range(nlevels):

def keyfunc(x):
Expand All @@ -579,16 +579,18 @@ def keyfunc(x):

# build a list of lists to create the index from
div_factor = nentries // ndupe_l[i] + 1
# pandas\_testing.py:2148: error: Need type annotation for 'cnt'
cnt = Counter() # type: ignore[var-annotated]

# Deprecated since version 3.9: collections.Counter now supports []. See PEP 585
# and Generic Alias Type.
cnt: Counter[str] = collections.Counter()
for j in range(div_factor):
label = f"{prefix}_l{i}_g{j}"
cnt[label] = ndupe_l[i]
# cute Counter trick
result = sorted(cnt.elements(), key=keyfunc)[:nentries]
tuples.append(result)
list_of_lists.append(result)

tuples = list(zip(*tuples))
tuples = list(zip(*list_of_lists))

# convert tuples to index
if nentries == 1:
Expand Down