Skip to content

Commit 45a03c0

Browse files
AntropathDavid SauerweinDavidjaidisido
authored
fix: reset index and handle last index (#2531)
* bugfix: reset index and handle last index * replace iteration over index by enumerate in neptune.to_rdf_graph * [skip ci] - fix: validate.sh --------- Co-authored-by: David Sauerwein <[email protected]> Co-authored-by: David <[email protected]> Co-authored-by: Abdel Jaidi <[email protected]>
1 parent fa68082 commit 45a03c0

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

awswrangler/neptune/_neptune.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ def to_rdf_graph(
218218
instance of the neptune client to use
219219
df (pandas.DataFrame) :
220220
Pandas DataFrame https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html
221+
batch_size (int) :
222+
The number of rows in the DataFrame (i.e. triples) to write into Amazon Neptune in one query. Defaults to 50
221223
subject_column (str, optional) :
222224
The column name in the DataFrame for the subject. Defaults to 's'
223225
predicate_column (str, optional) :
@@ -254,7 +256,7 @@ def to_rdf_graph(
254256

255257
query = ""
256258
# Loop through items in the DF
257-
for index, row in df.iterrows():
259+
for i, (_, row) in enumerate(df.iterrows()):
258260
# build up a query
259261
if is_quads:
260262
insert = f"""INSERT DATA {{ GRAPH <{row[graph_column]}> {{<{row[subject_column]}>
@@ -265,11 +267,11 @@ def to_rdf_graph(
265267
<{row[object_column]}> . }}; """
266268
query = query + insert
267269
# run the query
268-
if index > 0 and index % batch_size == 0:
270+
if i > 0 and i % batch_size == 0:
269271
res = client.write_sparql(query)
270272
if res:
271273
query = ""
272-
return client.write_sparql(query)
274+
return client.write_sparql(query) if query else res
273275

274276

275277
BULK_LOAD_IN_PROGRESS_STATES = {"LOAD_IN_QUEUE", "LOAD_NOT_STARTED", "LOAD_IN_PROGRESS"}

0 commit comments

Comments
 (0)