Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[ ] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
import numpy as np
attrs = {"A": "B", "G": np.array([1.2, 2.4])}
# This one works
arr = np.random.rand(60, 1)
df_named = pd.DataFrame(arr)
df_named.attrs = attrs
print(df_named[0])
# This one works
arr = np.random.rand(61, 1)
df_named = pd.DataFrame(arr)
df_named.attrs = {"A": "B", "G": "A"}
print(df_named[0])
# This one does not works
arr = np.random.rand(61, 1)
df_named = pd.DataFrame(arr)
df_named.attrs = attrs
print(df_named) # This works
print(df_named[0]) # This does not works
Issue Description
Hello,
I have a dataFrame of size (61,1) with 2 attributes (one is an array) and I can't print the first Serie of the DataFrame. I have the following Error :
Traceback (most recent call last):
File ~\miniforge-pypy3\envs\h5pandas_dev\Lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
exec(code, globals, locals)
File d:\documents\perso\travail\mbda\pandas_extension\h5pandas\tests\debug.py:23
print(df_named[0]) # This does not works
File ~\miniforge-pypy3\envs\h5pandas_dev\Lib\site-packages\pandas\core\series.py:1784 in __repr__
return self.to_string(**repr_params)
File ~\miniforge-pypy3\envs\h5pandas_dev\Lib\site-packages\pandas\core\series.py:1871 in to_string
formatter = fmt.SeriesFormatter(
File ~\miniforge-pypy3\envs\h5pandas_dev\Lib\site-packages\pandas\io\formats\format.py:225 in __init__
self._chk_truncate()
File ~\miniforge-pypy3\envs\h5pandas_dev\Lib\site-packages\pandas\io\formats\format.py:247 in _chk_truncate
series = concat((series.iloc[:row_num], series.iloc[-row_num:]))
File ~\miniforge-pypy3\envs\h5pandas_dev\Lib\site-packages\pandas\core\reshape\concat.py:395 in concat
return op.get_result()
File ~\miniforge-pypy3\envs\h5pandas_dev\Lib\site-packages\pandas\core\reshape\concat.py:650 in get_result
return result.__finalize__(self, method="concat")
File ~\miniforge-pypy3\envs\h5pandas_dev\Lib\site-packages\pandas\core\generic.py:6273 in __finalize__
have_same_attrs = all(obj.attrs == attrs for obj in other.objs[1:])
File ~\miniforge-pypy3\envs\h5pandas_dev\Lib\site-packages\pandas\core\generic.py:6273 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()
However I can print the DataFrame, it does not raise the ValueError. If the DataFrame hasn't got the array attribute, I do not have ValueError. If the DataFrame has only 60 rows, I do not have ValueError.
Expected Behavior
I should not have this ValueError.
Installed Versions
Comment From: crspencer11
take
Comment From: Anurag-Varma
Just did a debugging:
By default display.max_rows
in pandas is set to 60.
But if you have more than 60 rows, its failing as mentioned in your above case.
To avoid it, you can do this - For example, if you want 100 rows max, then:
pd.set_option("display.max_rows", 100)
Then it will work, in case of any other value, replace 100 with that value.
Comment From: Anurag-Varma
take
Comment From: yuanx749
This issue has been fixed in #60574, where the code series = concat((series.iloc[:row_num], series.iloc[-row_num:]))
causing the error is replaced.
Comment From: Anurag-Varma
Hi @yuanx749
Thanks, I tried the above code in the latest version of pandas and it seems this error has been fixed. Now no longer getting the issue.
Any member can close this issue @rhshadrach