BUG: pd.Series() constructor with 2d NumPy array raises bare Exception #35744
Labels
Constructors
Series/DataFrame/Index/pd.array Constructors
Error Reporting
Incorrect or improved errors from pandas
Series
Series data structure
Milestone
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
I get this output
Problem description
Yes, creating a series from an array is invalid. But the problem is that a bare
Exception
is raised for this. A different exception type likeValueError
is expected. User code should [mostly] never be catching bare Exceptions, but may reasonable catchValueError
s orTypeError
s from pandas routines.I'm not entirely sure of the rationale for raising a bare Exception in the
sanitize_array
method, I started looking through the git blame but didn't go back that far.I think a PR that just raises a
ValueError
insanitize_array
would be an appropriate fix and I can create that if given the thumbs up.Expected Output
A
ValueError
is raised, that can be caught be user code.Output of
pd.show_versions()
INSTALLED VERSIONS
commit : d9fff27
python : 3.8.3.final.0
python-bits : 64
OS : Darwin
OS-release : 19.6.0
Version : Darwin Kernel Version 19.6.0: Sun Jul 5 00:43:10 PDT 2020; root:xnu-6153.141.1~9/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.1.0
numpy : 1.19.0
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 49.2.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.16.1
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 0.8.0
fastparquet : None
gcsfs : None
matplotlib : 3.3.0
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: