question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

REGR: ValueError: setting an array element with a sequence. when assigning an array.array using .loc

See original GitHub issue

Pandas version checks

  • I have checked that this issue has not already been reported.

  • 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
from array import array

df = pd.DataFrame({"A": [2,4,6,8]})

cenlon = array('d')
cenlon.append(45.345343)

# Problem
df.loc[0, 'CenLon'] = cenlon

# Solution 1
# df.loc[0, 'CenLon'] = np.array(cenlon)

# Solution 2
# df['CenLon'] = ''
# df.loc[0, 'CenLon'] = cenlon

Issue Description

If the Example above is running in a jupyter notebook, the notebook gets stuck and no error message is shown. The error message only appears in the console where the jupyter notebook is running. From the notebook inside it looks like the cell is still computing. The Example also includes two solutions to it, but a decent error message still would be nice.

Expected Behavior

It would be great if the error message would be displayed directly in the notebook or the provided datatype should be supported again. As background info: this datatype you will get when working with geopandas (https://geopandas.org/en/stable/index.html) and shaply (https://shapely.readthedocs.io/en/stable/manual.html) and you want to extract the centre coordinates of a geometry. Further, I think this was supported in a previous pandas version as the error just appeared on an older notebook (if wanted I could try to find out up to which version or you decide it is not supported anymore then I will let shaply and geopandas know).

Installed Versions

INSTALLED VERSIONS ------------------ commit : 06d230151e6f18fdb8139d09abf539867a8cd481 python : 3.9.10.final.0 python-bits : 64 OS : Linux OS-release : 5.14.0-1024-oem Version : #26-Ubuntu SMP Thu Feb 17 14:35:50 UTC 2022 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8

pandas : 1.4.1 numpy : 1.22.3 pytz : 2021.3 dateutil : 2.8.2 pip : 22.0.4 setuptools : 59.8.0 Cython : 0.29.28 pytest : 7.0.1 hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : 3.0.3 IPython : 8.1.1 pandas_datareader: None bs4 : None bottleneck : None fastparquet : None fsspec : 2022.02.0 gcsfs : None matplotlib : 3.5.1 numba : None numexpr : 2.8.0 odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pyreadstat : None pyxlsb : None s3fs : None scipy : 1.8.0 sqlalchemy : None tables : 3.7.0 tabulate : None xarray : 2022.3.0 xlrd : None xlwt : None zstandard : None

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jorisvandenbosschecommented, Aug 12, 2022

BTW, the fact that a notebook is hanging and you see that long traceback in IPython, that was a bug in IPython that should be fixed in the latest version (https://github.com/ipython/ipython/issues/12467)

That still leaves the regression or behaviour change in pandas. I started investigating this and have an PR at https://github.com/pandas-dev/pandas/pull/48057

0reactions
simonjayhawkinscommented, Jun 22, 2022

moving to 1.4.4

Read more comments on GitHub >

github_iconTop Results From Across the Web

ValueError: setting an array element with a sequence. for ...
The basic issue is that I would like to set a certain row, column in the dataframe to a list using the ix...
Read more >
How to Fix: ValueError: setting an array element with a ...
In this article, we will discuss how to fix ValueError: setting array element with a sequence using Python.
Read more >
Setting an Array Element With A Sequence Easily - Python Pool
In python, we often encounter the error as ValueError: setting an array element with a sequence is when we are working with the...
Read more >
[FIXED] ValueError: setting an array element with a sequence
Solution: To eliminate the occurrence of the above error, you have to rectify the shape of the array. As this is a 2D...
Read more >
ValueError: setting an array element with a sequence - Statology
This error typically occurs when you attempt to cram several numbers into a single position in a NumPy array. The following example shows...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found