Update to use coords from write_dict instead of calling set_index
@@ -502,19 +502,15 @@ def from_pandas(uri, dataframe, **kwargs):
A = tiledb.open(uri, 'w', ctx=ctx)
if A.schema.sparse:
- if not create_array:
- index_col_names = []
- for k in range(A.schema.ndim):
- name = A.schema.domain.dim(k).name
- if name not in dataframe.index.names:
- index_col_names.append(name)
- write_dict.pop(name, None)
-
- if index_col_names:
- dataframe.set_index(index_col_names, inplace=True, drop=True)
-
coords = []
for k in range(A.schema.ndim):
+ dim_name = A.schema.domain.dim(k).name
+ if not create_array and dim_name not in dataframe.index.names:
+ # this branch handles the situation where a user did not specify
+ # index_col and is using mode='append'. We would like to try writing
+ # with the columns corresponding to existing dimension name.
+ coords.append(write_dict.pop(dim_name))
+ else:
coords.append(dataframe.index.get_level_values(k))
# TODO ensure correct col/dim ordering
