1
- from collections import Counter
1
+ import collections
2
2
from datetime import datetime
3
3
from functools import wraps
4
4
import operator
5
5
import os
6
6
import re
7
7
import string
8
- from typing import Callable , ContextManager , List , Type
8
+ from typing import Callable , ContextManager , Counter , List , Type
9
9
import warnings
10
10
11
11
import numpy as np
@@ -568,7 +568,7 @@ def makeCustomIndex(
568
568
569
569
assert all (x > 0 for x in ndupe_l )
570
570
571
- tuples = []
571
+ list_of_lists = []
572
572
for i in range (nlevels ):
573
573
574
574
def keyfunc (x ):
@@ -579,16 +579,18 @@ def keyfunc(x):
579
579
580
580
# build a list of lists to create the index from
581
581
div_factor = nentries // ndupe_l [i ] + 1
582
- # pandas\_testing.py:2148: error: Need type annotation for 'cnt'
583
- cnt = Counter () # type: ignore[var-annotated]
582
+
583
+ # Deprecated since version 3.9: collections.Counter now supports []. See PEP 585
584
+ # and Generic Alias Type.
585
+ cnt : Counter [str ] = collections .Counter ()
584
586
for j in range (div_factor ):
585
587
label = f"{ prefix } _l{ i } _g{ j } "
586
588
cnt [label ] = ndupe_l [i ]
587
589
# cute Counter trick
588
590
result = sorted (cnt .elements (), key = keyfunc )[:nentries ]
589
- tuples .append (result )
591
+ list_of_lists .append (result )
590
592
591
- tuples = list (zip (* tuples ))
593
+ tuples = list (zip (* list_of_lists ))
592
594
593
595
# convert tuples to index
594
596
if nentries == 1 :
0 commit comments