Branch data Line data Source code
1 : : # Copyright 2021 Garena Online Private Limited
2 : : #
3 : : # Licensed under the Apache License, Version 2.0 (the "License");
4 : : # you may not use this file except in compliance with the License.
5 : : # You may obtain a copy of the License at
6 : : #
7 : : # http://www.apache.org/licenses/LICENSE-2.0
8 : : #
9 : : # Unless required by applicable law or agreed to in writing, software
10 : : # distributed under the License is distributed on an "AS IS" BASIS,
11 : : # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : : # See the License for the specific language governing permissions and
13 : : # limitations under the License.
14 : 35 : """Helper function for Python API."""
15 : :
16 : 35 : from typing import Any
17 : :
18 : 35 : import numpy as np
19 : :
20 : :
21 : 35 : def check_key_duplication(cls: Any, keytype: str, keys: list[str]) -> None:
22 : : """Check if there's any duplicated keys in ``keys``."""
23 : 35 : ukeys, counts = np.unique(keys, return_counts=True)
24 : 35 : if not np.all(counts == 1):
25 [ # ]: 0 : dup_keys = ukeys[counts > 1]
26 : 0 : raise SystemError(
27 : : f"{cls} c++ code error. {keytype} keys {list(dup_keys)} are duplicated. "
28 : : f"Please report to the author of {cls}."
29 : : )
|