Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport release-1.7] [python] Fix race in SOMADataFrame schema with multiple enumerated columns #2198

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions apis/python/src/tiledbsoma/_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ def write(
dim_names_set = self.index_column_names
n = None

se : tiledb.schema_evolution.ArraySchemaEvolution = None

for col_info in values.schema:
name = col_info.name
col = values.column(name).combine_chunks()
Expand Down Expand Up @@ -437,7 +439,8 @@ def write(

# only extend if there are new values
if len(update_vals) != 0:
se = tiledb.ArraySchemaEvolution(self.context.tiledb_ctx)
if se is None:
se = tiledb.ArraySchemaEvolution(self.context.tiledb_ctx)
if np.issubdtype(enmr.dtype.type, np.str_):
extend_vals = np.array(update_vals, "U")
elif np.issubdtype(enmr.dtype.type, np.bytes_):
Expand All @@ -448,7 +451,6 @@ def write(
df = pd.Categorical(col.to_pandas(), new_enmr.values())
col = pa.DictionaryArray.from_pandas(df)
se.extend_enumeration(new_enmr)
se.array_evolve(uri=self.uri)

cols_map = dim_cols_map if name in dim_names_set else attr_cols_map
schema = self._handle.schema
Expand All @@ -470,6 +472,9 @@ def write(

cols_map[name] = col.to_pandas()

if se is not None:
se.array_evolve(uri=self.uri)

if n is None:
raise ValueError(f"did not find any column names in {values.schema.names}")

Expand Down
Loading