Closed ilexaquifolium closed 3 months ago
the following works for me with CAVEclient 5.15.2 and pandas 2.2.1:
import pandas as pd
import caveclient as cv
print(pd.__version__)
print(cv.__version__)
client = cv.CAVEclient("minnie65_public_v117")
client.materialize.query_table("synapses_pni_2", limit=5)
so i wonder if this is somehow specific to your table (but I don't have access).
also, what happens when you assign the output of query_table
to a variable? It looks like the error is coming from the repr that is implicit when you don't assign the output
Could you provide some more information about your environment?
import caveclient as cv
client = cv.CAVEclient('fanc_production_mar2021')
client.materialize.query_table("synapse_regions_v1", limit=5)
works as expected on caveclient 5.15.2
(current pypi release) and pandas 2.2.1
on OS X.
I'm using macOS Ventura 13.4.1, with python 3.11.5 and caveclient 5.15.2
>>> print(pd.__version__)
2.2.1
>>> print(cv.__version__)
5.15.2
>>> client = cv.CAVEclient("minnie65_public_v117")
>>> table = client.materialize.query_table("synapses_pni_2", limit=5)
201 - "Limited query to 5 rows
>>> table.head()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/anaconda3/lib/python3.11/site-packages/pandas/core/frame.py", line 1203, in __repr__
return self.to_string(**repr_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/anaconda3/lib/python3.11/site-packages/pandas/util/_decorators.py", line 333, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/anaconda3/lib/python3.11/site-packages/pandas/core/frame.py", line 1383, in to_string
return fmt.DataFrameRenderer(formatter).to_string(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/anaconda3/lib/python3.11/site-packages/pandas/io/formats/format.py", line 962, in to_string
string = string_formatter.to_string()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/anaconda3/lib/python3.11/site-packages/pandas/io/formats/string.py", line 29, in to_string
text = self._get_string_representation()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/anaconda3/lib/python3.11/site-packages/pandas/io/formats/string.py", line 53, in _get_string_representation
return self._fit_strcols_to_terminal_width(strcols)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/anaconda3/lib/python3.11/site-packages/pandas/io/formats/string.py", line 184, in _fit_strcols_to_terminal_width
self.fmt.truncate()
File "/usr/local/anaconda3/lib/python3.11/site-packages/pandas/io/formats/format.py", line 655, in truncate
self._truncate_horizontally()
File "/usr/local/anaconda3/lib/python3.11/site-packages/pandas/io/formats/format.py", line 673, in _truncate_horizontally
self.tr_frame = concat((left, right), axis=1)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/anaconda3/lib/python3.11/site-packages/pandas/core/reshape/concat.py", line 395, in concat
return op.get_result()
^^^^^^^^^^^^^^^
File "/usr/local/anaconda3/lib/python3.11/site-packages/pandas/core/reshape/concat.py", line 691, in get_result
return out.__finalize__(self, method="concat")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/anaconda3/lib/python3.11/site-packages/pandas/core/generic.py", line 6270, in __finalize__
have_same_attrs = all(obj.attrs == attrs for obj in other.objs[1:])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/anaconda3/lib/python3.11/site-packages/pandas/core/generic.py", line 6270, in <genexpr>
have_same_attrs = all(obj.attrs == attrs for obj in other.objs[1:])
^^^^^^^^^^^^^^^^^^
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
so it sounds like the data was downloaded successfully? there is just some issue with pandas trying to display it when you call repr implicitly?
is this from a jupyter notebook or ipython shell? does print(df.head()) work?
this is the closest issue in pandas i could find https://github.com/pandas-dev/pandas/issues/47103
Agreed, query_table
does not have an error, it's the repr
function having an issue displaying metadata with lists (which should be allowed). I can replicate the issue now in a freshly installed ipython
but not in jupyter
, so it must be happening in __repr__
but not __repr_html__
. This looks to me that it's a pandas bug.
In terms of workarounds, I see two possibilities:
1) Use Jupyter notebooks, which don't seem to have this problem.
2) Omit metadata (i.e. don't populate the .attrs
object) by adding an argument to the query_table
call:
import caveclient as cv
client = cv.CAVEclient('fanc_production_mar2021')
df = client.materialize.query_table("synapse_regions_v1", limit=5, metadata=False)
Displaying the resulting dataframe in ipython does not throw the same error for me, and most likely, you aren't using it anyway.
setting metadata=False fixes it thankyou!
can we submit a pandas bug and close this one?
@ilexaquifolium what do you think?
I'm happy with that, yes
with pandas 2.1.4
with pandas 2.2.1 the same command produces the error: