Skip to content

Commit eda120c

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 eda120c

937 files changed

Lines changed: 349373 additions & 3 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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:

build/lib/allensdk/__init__.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Allen Institute Software License - This software license is the 2-clause BSD
2+
# license plus a third clause that prohibits redistribution for commercial
3+
# purposes without further permission.
4+
#
5+
# Copyright 2017. Allen Institute. All rights reserved.
6+
#
7+
# Redistribution and use in source and binary forms, with or without
8+
# modification, are permitted provided that the following conditions are met:
9+
#
10+
# 1. Redistributions of source code must retain the above copyright notice,
11+
# this list of conditions and the following disclaimer.
12+
#
13+
# 2. Redistributions in binary form must reproduce the above copyright notice,
14+
# this list of conditions and the following disclaimer in the documentation
15+
# and/or other materials provided with the distribution.
16+
#
17+
# 3. Redistributions for commercial purposes are not permitted without the
18+
# Allen Institute's written permission.
19+
# For purposes of this license, commercial purposes is the incorporation of the
20+
# Allen Institute's software into anything for which you will charge fees or
21+
# other compensation. Contact terms@alleninstitute.org for commercial licensing
22+
# opportunities.
23+
#
24+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
28+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34+
# POSSIBILITY OF SUCH DAMAGE.
35+
#
36+
import logging
37+
38+
__version__ = '2.16.2'
39+
40+
41+
try:
42+
from logging import NullHandler
43+
except ImportError:
44+
class NullHandler(logging.Handler):
45+
def emit(self, record):
46+
pass
47+
48+
49+
class OneResultExpectedError(RuntimeError):
50+
pass
51+
52+
53+
def one(x):
54+
if isinstance(x, str):
55+
return x
56+
try:
57+
xlen = len(x)
58+
except TypeError:
59+
return x
60+
if xlen != 1:
61+
raise OneResultExpectedError("Expected length one result, received: "
62+
f"{x} results from query")
63+
if isinstance(x, set):
64+
return list(x)[0]
65+
else:
66+
return x[0]
67+
68+
69+
logging.getLogger(__name__).addHandler(NullHandler())
70+
71+
if True:
72+
file_download_log = logging.getLogger(
73+
'allensdk.api.api.retrieve_file_over_http')
74+
file_download_log.setLevel(logging.INFO)
75+
console = logging.StreamHandler()
76+
formatter = logging.Formatter("%(asctime)s %(name)-12s "
77+
"%(levelname)-8s %(message)s")
78+
console.setFormatter(formatter)
79+
file_download_log.addHandler(console)

build/lib/allensdk/api/__init__.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Allen Institute Software License - This software license is the 2-clause BSD
2+
# license plus a third clause that prohibits redistribution for commercial
3+
# purposes without further permission.
4+
#
5+
# Copyright 2017. Allen Institute. All rights reserved.
6+
#
7+
# Redistribution and use in source and binary forms, with or without
8+
# modification, are permitted provided that the following conditions are met:
9+
#
10+
# 1. Redistributions of source code must retain the above copyright notice,
11+
# this list of conditions and the following disclaimer.
12+
#
13+
# 2. Redistributions in binary form must reproduce the above copyright notice,
14+
# this list of conditions and the following disclaimer in the documentation
15+
# and/or other materials provided with the distribution.
16+
#
17+
# 3. Redistributions for commercial purposes are not permitted without the
18+
# Allen Institute's written permission.
19+
# For purposes of this license, commercial purposes is the incorporation of the
20+
# Allen Institute's software into anything for which you will charge fees or
21+
# other compensation. Contact terms@alleninstitute.org for commercial licensing
22+
# opportunities.
23+
#
24+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
28+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34+
# POSSIBILITY OF SUCH DAMAGE.
35+
#
36+
''' Subclasses of allensdk.api.api.Api to implement specific queries to the
37+
`Allen Brain Atlas Data Portal <http://www.brain-map.org/api/index.html>`_.
38+
'''

0 commit comments

Comments
 (0)