Skip to content

Commit d5625d3

Browse files
committed
datacenter: toolz -> pandas
1 parent bb8919c commit d5625d3

2 files changed

Lines changed: 28 additions & 23 deletions

File tree

toolFactory/datacenter.py

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from toolFactory import pathFilenameDatabaseAST, pythonVersionMinorMinimum
2-
from typing import Any, cast
2+
from typing import Any
33
import pandas
4-
import toolz
54

65
cc=[
76
'ClassDefIdentifier',
@@ -87,7 +86,7 @@ def getElementsBe(deprecated: bool = False, versionMinorMaximum: int | None = No
8786

8887
# TODO after changing the dataframe storage from csv to something smart, make this check smarter
8988
# 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]
9190

9291
# Select the requested columns, in the specified order
9392
dataframe = dataframe[listElements]
@@ -126,17 +125,25 @@ def getElementsDOT(deprecated: bool = False, versionMinorMaximum: int | None = N
126125

127126
dataframe = dataframe[listElements].drop_duplicates()
128127

129-
listRows = dataframe.values.tolist() # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType]
130128
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
138140
}
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+
}
140147
return dictionaryAttribute
141148

142149
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
256263

257264
dataframe = dataframe[listElements].drop_duplicates()
258265

259-
listRows: list[list[str | int]] = dataframe.values.tolist() # pyright: ignore[reportUnknownVariableType, reportUnknownMemberType]
260266
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
270275
return dictionaryAttribute

toolFactory/factory3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ def create_ast_stmt():
192192
, ast.Return(ast.Name('workhorse'))]
193193
returns=ast.Subscript(ast.Name('Callable'), ast.Tuple([ast.List([ast.Attribute(ast.Name('ast'), attr='AST')]), buffaloBuffalo_workhorse_returnsAnnotation])) # pyright: ignore[reportUnknownArgumentType]
194194

195-
196195
del dictionaryVersionsTypeAliasSubcategory[attributeVersionMinorMinimum]
197196
orelse = [create_ast_stmt()]
198197

@@ -483,4 +482,5 @@ def append_ast_stmtTypeAlias():
483482
makeToolClassIsAndAttribute()
484483
makeToolDOT()
485484
makeToolGrab()
485+
# makeToolMake()
486486
makeTypeAlias()

0 commit comments

Comments
 (0)