Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Series.apply() throws an error on empty series when dtype = pd.StringDtype #33559

Closed
2 of 3 tasks
IDDT opened this issue Apr 15, 2020 · 1 comment · Fixed by #33846
Closed
2 of 3 tasks

BUG: Series.apply() throws an error on empty series when dtype = pd.StringDtype #33559

IDDT opened this issue Apr 15, 2020 · 1 comment · Fixed by #33846
Labels
Bug Constructors Series/DataFrame/Index/pd.array Constructors ExtensionArray Extending pandas with custom dtypes or arrays.
Milestone

Comments

@IDDT
Copy link

IDDT commented Apr 15, 2020

  • 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.


Code Sample, a copy-pastable example

pd.Series(['a', 'b', 'c']).iloc[0:0].apply(lambda x: x) #works as expected
pd.Series(['a', 'b', 'c']).astype('string').iloc[0:0].apply(lambda x: x) #throws an exception

Problem description

Applying a function to an empty Series with dtype pd.StringDtype throws ValueError: PandasArray must be 1-dimensional..

Expected Output

Apply does nothing.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.8.1.final.0
python-bits : 64
OS : Linux
OS-release : 5.6.3-arch1-1
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.0.3
numpy : 1.18.2
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 41.2.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.8.5 (dt dec pq3 ext lo64)
jinja2 : 2.11.2
IPython : 7.13.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None

@IDDT IDDT added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 15, 2020
@TomAugspurger
Copy link
Contributor

Thanks for the report. Slightly smaller reproducer

pd.Series(dtype="string", index=[])

We try to insert np.array(<NA>).

In _init_dict

    354         elif index is not None:
    355             # fastpath for Series(data=None). Just use broadcasting a scalar
    356             # instead of reindexing.
    357             values = na_value_for_dtype(dtype)
    358             keys = index

I'm not sure if that would need to change (special case length-0?) or whether create_series_with_explicit_dtype should change.

@TomAugspurger TomAugspurger added Constructors Series/DataFrame/Index/pd.array Constructors NA - MaskedArrays Related to pd.NA and nullable extension arrays Strings String extension data type and string data labels Apr 15, 2020
simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue May 1, 2020
@simonjayhawkins simonjayhawkins added ExtensionArray Extending pandas with custom dtypes or arrays. and removed NA - MaskedArrays Related to pd.NA and nullable extension arrays Needs Triage Issue that has not been reviewed by a pandas team member Strings String extension data type and string data labels May 1, 2020
@simonjayhawkins simonjayhawkins added this to the 1.1 milestone May 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Constructors Series/DataFrame/Index/pd.array Constructors ExtensionArray Extending pandas with custom dtypes or arrays.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants