|
1 | 1 | from toolFactory import pathFilenameDatabaseAST, pythonVersionMinorMinimum |
2 | | -from typing import Any, cast |
| 2 | +from typing import Any |
3 | 3 | import pandas |
4 | | -import toolz |
5 | 4 |
|
6 | 5 | cc=[ |
7 | 6 | 'ClassDefIdentifier', |
@@ -87,7 +86,7 @@ def getElementsBe(deprecated: bool = False, versionMinorMaximum: int | None = No |
87 | 86 |
|
88 | 87 | # TODO after changing the dataframe storage from csv to something smart, make this check smarter |
89 | 88 | # match str(dataframe[sortOn].dtype): |
90 | | - dataframe = dataframe.iloc[dataframe['ClassDefIdentifier'].astype(str).str.lower().argsort()] |
| 89 | + dataframe = dataframe.iloc[dataframe['ClassDefIdentifier'].astype(str).str.lower().argsort()] # pyright: ignore[reportUnknownMemberType] |
91 | 90 |
|
92 | 91 | # Select the requested columns, in the specified order |
93 | 92 | dataframe = dataframe[listElements] |
@@ -126,17 +125,25 @@ def getElementsDOT(deprecated: bool = False, versionMinorMaximum: int | None = N |
126 | 125 |
|
127 | 126 | dataframe = dataframe[listElements].drop_duplicates() |
128 | 127 |
|
129 | | - listRows = dataframe.values.tolist() # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType] |
130 | 128 | dictionaryAttribute: dict[str, dict[str, dict[str, int | str]]] = {} |
131 | | - for attribute, listRowsByAttribute in toolz.groupby(lambda row: row[0], listRows).items(): # pyright: ignore[reportUnknownArgumentType, reportUnknownLambdaType, reportUnknownMemberType, reportUnknownVariableType] |
132 | | - dictionaryTypeAliasSubcategory: dict[str, dict[str, int | str]] = {} |
133 | | - for typeAliasSubcategory, listRowsByTypeAliasSubcategory in toolz.groupby(lambda row: row[1], listRowsByAttribute).items(): # pyright: ignore[reportUnknownArgumentType, reportUnknownLambdaType, reportUnknownMemberType, reportUnknownVariableType] |
134 | | - rowMinimum = min(listRowsByTypeAliasSubcategory, key=lambda row: row[2]) # pyright: ignore[reportUnknownLambdaType, reportUnknownArgumentType, reportUnknownVariableType] |
135 | | - dictionaryTypeAliasSubcategory[typeAliasSubcategory] = { |
136 | | - 'attributeVersionMinorMinimum': rowMinimum[2], |
137 | | - 'ast_exprType': rowMinimum[3] |
| 129 | + for _elephino, row in dataframe.iterrows(): # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType] |
| 130 | + attributeKey = str(row['attribute']) # pyright: ignore[reportUnknownArgumentType] |
| 131 | + typeAliasKey = str(row['TypeAliasSubcategory']) # pyright: ignore[reportUnknownArgumentType] |
| 132 | + attributeVersionMinorMinimum = row['attributeVersionMinorMinimum'] # pyright: ignore[reportUnknownVariableType] |
| 133 | + astExprType = row['ast_exprType'] # pyright: ignore[reportUnknownVariableType] |
| 134 | + if attributeKey not in dictionaryAttribute: |
| 135 | + dictionaryAttribute[attributeKey] = {} |
| 136 | + if typeAliasKey not in dictionaryAttribute[attributeKey]: |
| 137 | + dictionaryAttribute[attributeKey][typeAliasKey] = { |
| 138 | + 'attributeVersionMinorMinimum': attributeVersionMinorMinimum, |
| 139 | + 'ast_exprType': astExprType |
138 | 140 | } |
139 | | - dictionaryAttribute[attribute] = dictionaryTypeAliasSubcategory |
| 141 | + else: |
| 142 | + if attributeVersionMinorMinimum < dictionaryAttribute[attributeKey][typeAliasKey]['attributeVersionMinorMinimum']: |
| 143 | + dictionaryAttribute[attributeKey][typeAliasKey] = { |
| 144 | + 'attributeVersionMinorMinimum': attributeVersionMinorMinimum, |
| 145 | + 'ast_exprType': astExprType |
| 146 | + } |
140 | 147 | return dictionaryAttribute |
141 | 148 |
|
142 | 149 | def getElementsGrab(deprecated: bool = False, versionMinorMaximum: int | None = None) -> dict[str, dict[int, list[str]]]: |
@@ -256,15 +263,13 @@ def getElementsTypeAlias(deprecated: bool = False, versionMinorMaximum: int | No |
256 | 263 |
|
257 | 264 | dataframe = dataframe[listElements].drop_duplicates() |
258 | 265 |
|
259 | | - listRows: list[list[str | int]] = dataframe.values.tolist() # pyright: ignore[reportUnknownVariableType, reportUnknownMemberType] |
260 | 266 | dictionaryAttribute: dict[str, dict[str, dict[int, list[str]]]] = {} |
261 | | - for attribute, listRowsByAttribute in toolz.groupby(lambda row: row[0], listRows).items(): # pyright: ignore[reportUnknownLambdaType, reportUnknownMemberType, reportUnknownVariableType] |
262 | | - dictionaryTypeAliasSubcategory: dict[str, dict[int, list[str]]] = {} |
263 | | - for typeAliasSubcategory, listRowsByTypeAliasSubcategory in toolz.groupby(lambda row: row[1], listRowsByAttribute).items(): # pyright: ignore[reportUnknownArgumentType, reportUnknownLambdaType, reportUnknownMemberType, reportUnknownVariableType] |
264 | | - dictionaryAttributeVersionMinorMinimum: dict[int, list[str]] = {} |
265 | | - for attributeVersionMinorMinimum, listRowsByAttributeVersionMinorMinimum in toolz.groupby(lambda row: row[2], listRowsByTypeAliasSubcategory).items(): # pyright: ignore[reportUnknownArgumentType, reportUnknownLambdaType, reportUnknownMemberType, reportUnknownVariableType] |
266 | | - listClassDefIdentifier: list[str] = [row[3] for row in listRowsByAttributeVersionMinorMinimum] # pyright: ignore[reportUnknownVariableType] |
267 | | - dictionaryAttributeVersionMinorMinimum[attributeVersionMinorMinimum] = listClassDefIdentifier |
268 | | - dictionaryTypeAliasSubcategory[typeAliasSubcategory] = dictionaryAttributeVersionMinorMinimum |
269 | | - dictionaryAttribute[attribute] = dictionaryTypeAliasSubcategory |
| 267 | + grouped = dataframe.groupby(['attribute', 'TypeAliasSubcategory', 'attributeVersionMinorMinimum']) # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType] |
| 268 | + for (attribute, typeAliasSubcategory, attributeVersionMinorMinimum), group in grouped: # pyright: ignore[reportUnknownVariableType] |
| 269 | + listClassDefIdentifier = sorted(group['classAs_astAttribute'].unique(), key=lambda x: str(x).lower()) # pyright: ignore[reportUnknownArgumentType, reportUnknownMemberType] |
| 270 | + if attribute not in dictionaryAttribute: |
| 271 | + dictionaryAttribute[attribute] = {} |
| 272 | + if typeAliasSubcategory not in dictionaryAttribute[attribute]: |
| 273 | + dictionaryAttribute[attribute][typeAliasSubcategory] = {} |
| 274 | + dictionaryAttribute[attribute][typeAliasSubcategory][attributeVersionMinorMinimum] = listClassDefIdentifier |
270 | 275 | return dictionaryAttribute |
0 commit comments