Skip to content

Commit 36c2a69

Browse files
rlyclaude
andcommitted
Fix pandas FutureWarnings in ecephys_project_cache
- Select only the needed column before groupby().apply() to avoid FutureWarning about grouping columns (compatible with pandas 1.5+) - Use None instead of 0 to initialize column, avoiding dtype incompatibility warning when storing arrays of strings Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 920e6b7 commit 36c2a69

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

allensdk/brain_observatory/ecephys/ecephys_project_cache.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -737,9 +737,12 @@ def get_grouped_uniques(this, other, foreign_key, field_key, unique_key, inplace
737737
if not inplace:
738738
this = this.copy()
739739

740-
uniques = other.groupby(foreign_key)\
741-
.apply(lambda grp: pd.DataFrame(grp)[field_key].unique())
742-
this[unique_key] = 0
740+
# Select only the field_key column before apply to avoid FutureWarning about
741+
# grouping columns in pandas 2.2+
742+
uniques = other.groupby(foreign_key)[field_key]\
743+
.apply(lambda x: x.unique())
744+
# Use object dtype to allow storing arrays of strings
745+
this[unique_key] = None
743746
this.loc[uniques.index.values, unique_key] = uniques.values
744747

745748
if not inplace:

0 commit comments

Comments
 (0)