Skip to content

Commit 8aa5826

Browse files
committed
progress on getElementsMake
1 parent e6d3db5 commit 8aa5826

1 file changed

Lines changed: 46 additions & 44 deletions

File tree

toolFactory/datacenter.py

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class DictionaryToolBe(TypedDict):
2020

2121
class DictionaryMatchArgs(TypedDict):
2222
listFunctionDef_args: list[str]
23-
kwargAnnotation: str
23+
kwarg: str
2424
defaults: list[str]
2525
listCall_args: list[tuple[str, str]]
2626

@@ -125,28 +125,11 @@ def getElementsGrab(deprecated: bool = False, versionMinorMaximum: Version | Non
125125

126126
def getElementsMake(deprecated: bool = False, versionMinorMaximum: int | None = None) -> list[DictionaryToolMake]:
127127
listElementsHARDCODED = [
128-
'ClassDefIdentifier',
129-
'attribute',
130-
'attributeRename',
131-
'attributeKind',
132-
'ast_arg',
133-
'defaultValue',
134-
'classAs_astAttribute',
135-
'classVersionMinorMinimum',
136-
'attributeVersionMinorMinimum',
137-
'keywordArguments',
138-
'kwargAnnotation',
139-
'match_args',
140-
'match_argsVersionMinorMinimum',
128+
'ClassDefIdentifier', 'classAs_astAttribute', 'match_args', 'attribute', 'attributeRename', 'ast_arg', 'defaultValue',
129+
'keywordArguments', 'kwargAnnotation', 'classVersionMinorMinimum', 'attributeVersionMinorMinimum', 'match_argsVersionMinorMinimum',
141130
]
142131
listElements = listElementsHARDCODED
143132

144-
"""
145-
Only ast class with parameters that can be set in the constructor. (__init__ method), which should mean I can filter out 'attributeKind' == 'No'.
146-
Approximately 40 methods in `Make` will only have the four `_attribute` attributes. Instead of treating those as `**keywordArguments`, I could make them args with default values.
147-
The same top-level order as getElementsBe
148-
"""
149-
150133
"""What to return, identifiers for the return are tentative.
151134
ClassDefIdentifier
152135
listFunctionDef_args: list[str] if `keywordArguments` is False, add `ast_arg` in the order of 'match_args'
@@ -157,44 +140,63 @@ def getElementsMake(deprecated: bool = False, versionMinorMaximum: int | None =
157140
listCall_args: list[tuple(str, str)] ('attribute', if `keywordArguments` is False, 'attributeRename' | if `keywordArguments` is True and there is a 'defaultValue', then 'defaultValue' | 'attribute')
158141
'keywordArguments'
159142
160-
'ClassDefIdentifier',
161-
'classAs_astAttribute',
162-
163-
'match_args',
164-
165-
'attribute',
166-
'attributeRename',
167-
'attributeKind',
168-
'ast_arg',
169-
'defaultValue',
170-
'keywordArguments',
171-
172-
'kwargAnnotation',
173-
174-
'classVersionMinorMinimum', -1
175-
'attributeVersionMinorMinimum', -1
176-
'match_argsVersionMinorMinimum', -1
177-
178-
The simplest case all version are -1:
179-
get 'match_args': it is one or more comma separated identifiers that have a 1:1 correspondence with the row values in column 'attribute'.
180-
put the rows in the same order as 'match_args'. (if there are additional attribute values, put them at the end of the list)
181-
182143
pythonVersionMinorMinimum = 10
183144
df = df[~df['deprecated']]
184145
df['classVersionMinorMinimum'] = df['classVersionMinorMinimum'].where(df['classVersionMinorMinimum'] > pythonVersionMinorMinimum, -1)
185146
df['attributeVersionMinorMinimum'] = df['attributeVersionMinorMinimum'].where(df['attributeVersionMinorMinimum'] > pythonVersionMinorMinimum, -1)
186147
df['match_argsVersionMinorMinimum'] = df['match_argsVersionMinorMinimum'].where(df['match_argsVersionMinorMinimum'] > pythonVersionMinorMinimum, -1)
187148
188149
listElements = ['ClassDefIdentifier', 'classAs_astAttribute', 'match_args', 'attribute', 'attributeRename', 'ast_arg', 'defaultValue', 'keywordArguments', 'kwargAnnotation', 'classVersionMinorMinimum', 'attributeVersionMinorMinimum', 'match_argsVersionMinorMinimum',]
189-
df = df[listElements].drop_duplicates()
190150
df = df[df['attribute'] != "No"]
151+
subset = [element for element in listElements if element not in ['match_args', 'match_argsVersionMinorMinimum']]
152+
df = df[listElements].drop_duplicates()
153+
154+
# Create a new column 'listFunctionDef_args' based on conditions
155+
def compute_listFunctionDef_args(row):
156+
listAttributes = row['match_args'].replace("'","").replace(" ","").split(',') # Split 'match_args' into a list
157+
className = row['ClassDefIdentifier'] # Get 'ClassDefIdentifier'
158+
version = row['match_argsVersionMinorMinimum'] # Get 'match_argsVersionMinorMinimum'
159+
collected_args: list[str] = []
160+
collected_defaultValue: list[str] = []
161+
for attributeTarget in listAttributes:
162+
# Find the row matching the conditions
163+
matching_row = df[
164+
(df['attribute'] == attributeTarget) &
165+
(df['ClassDefIdentifier'] == className) &
166+
(df['match_argsVersionMinorMinimum'] == version)
167+
]
168+
if not matching_row.empty:
169+
if not matching_row.iloc[0]['keywordArguments']: # Check 'keywordArguments'
170+
collected_args.append(matching_row.iloc[0]['ast_arg']) # Collect 'ast_arg'
171+
if matching_row.iloc[0]['defaultValue'] != "No":
172+
collected_defaultValue.append(matching_row.iloc[0]['defaultValue']) # Collect 'defaultValue'
173+
# Format the collected arguments as a string
174+
listFunctionDef_args = ', '.join(f'"{arg}"' for arg in collected_args)
175+
defaults = 'No'
176+
if collected_defaultValue:
177+
defaults = ', '.join(f'"{defaultValue}"' for defaultValue in collected_defaultValue)
178+
return pd.Series([listFunctionDef_args, defaults], index=['listFunctionDef_args', 'defaults'])
179+
# Apply the function to create the new column
180+
# df['listFunctionDef_args'] = df.apply(compute_listFunctionDef_args, axis=1)
181+
df[['listFunctionDef_args', 'defaults']] = df.apply(compute_listFunctionDef_args, axis=1)
182+
183+
# Compute 'kwarg' column based on 'kwargAnnotation'
184+
def compute_kwarg(group):
185+
list_kwargAnnotation = sorted(val for val in group.unique() if val != "No")
186+
return 'OR'.join(list_kwargAnnotation) if list_kwargAnnotation else "No"
187+
df['kwarg'] = (
188+
df.groupby(['ClassDefIdentifier', 'match_argsVersionMinorMinimum'])['kwargAnnotation']
189+
.transform(compute_kwarg)
190+
)
191191
"""
192192

193193
dataframe = getDataframe(deprecated, versionMinorMaximum)
194194

195195
dd = [DictionaryToolMake(ClassDefIdentifier='', classAs_astAttribute='', versionMinimum={}, classVersionMinorMinimum=-1, attributeVersionMinorMinimum=-1, match_argsVersionMinorMinimum=-1)]
196196
return dd
197-
"""Additional notes
197+
198+
199+
"""Additional notes
198200
classVersionMinorMinimum: more than one if applicable, and with different values for some of the above returns; we should create the code to handle:
199201
class,classVersionMinorMinimum,match_argsVersionMinorMinimum
200202
AsyncFunctionDef,-1,-1

0 commit comments

Comments
 (0)