Skip to content

BUG: Series constructor incorrectly assumes that any dtype with .kind == 'V...' is a “compound dtype” #54810

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

Open
3 tasks done
flying-sheep opened this issue Aug 28, 2023 · 6 comments · May be fixed by #61637
Open
3 tasks done
Labels
Bug Constructors Series/DataFrame/Index/pd.array Constructors

Comments

@flying-sheep
Copy link
Contributor

flying-sheep commented Aug 28, 2023

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

pd.Series([b"hi"], dtype="V2")

Issue Description

I assume you mean what numpy calls “structured dtype” when you say “compound dtype” here:

# a compound dtype
if dtype.kind == "V":
raise NotImplementedError(
"compound dtypes are not implemented "
f"in the {cls.__name__} constructor"
)

Unless you mean something totally different, that code is wrong. There’s other applications for void dtypes than structured arrays. void means “we don’t validate bit patterns here”, i.e. it corresponds to builtins.bytes (unlike S, a, which according to numpy are “zero terminated byte strings (not recommended)” so those codes aren’t a valid alternative).

If I’m right about your intention and you want to prevent structured arrays / recarrays, you should instead check if getattr(dtype, "fields", None) is not None.

Expected Behavior

Being able to create an ExtensionDtype with kind = 'V...' and sticking it into a Series.

Installed Versions

INSTALLED VERSIONS

commit : 0f43794
python : 3.11.3.final.0
python-bits : 64
OS : Linux
OS-release : 6.4.12-zen1-1-zen
Version : #1 ZEN SMP PREEMPT_DYNAMIC Thu, 24 Aug 2023 00:37:46 +0000
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : de_DE.UTF-8
LOCALE : de_DE.UTF-8

pandas : 2.0.3
numpy : 1.25.2
pytz : 2023.3
dateutil : 2.8.2
setuptools : 68.0.0
pip : 23.2.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 8.14.0
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 13.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.11.2
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

@flying-sheep flying-sheep added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 28, 2023
@simonjayhawkins simonjayhawkins added the Constructors Series/DataFrame/Index/pd.array Constructors label Feb 6, 2024
@flying-sheep
Copy link
Contributor Author

This is still an issue.

Who implemented that check? Can that person please explain what it’s for so we can fix it?

@mroeschke mroeschke removed the Needs Triage Issue that has not been reviewed by a pandas team member label Jul 17, 2024
@flying-sheep
Copy link
Contributor Author

I have a lovely ExtensionDType that I’d like to use, but it’s blocked on this issue for 11 months now.

Could someone please take a look?

https://gist.github.com/flying-sheep/99f2ceafdc494f97424222611b4f9474

@flying-sheep
Copy link
Contributor Author

Hello?

@flying-sheep
Copy link
Contributor Author

Anyone home?

@ilan-gold
Copy link

ilan-gold commented Feb 21, 2025

@shoyer Having a UUID extension array would be amazing for anndata, specifically the xarray integration.

Since we have to load coords in xarray, one way around that (that I'm pursuing) is loading the true index elsewhere and using an in-memory range index so that people have good first-load times. The issue, though, is that once you index a range indexer, you end up with an integer index after indexing into it, and we disallow this in AnnData to prevent confusion i.e., how iloc is its own method. So having a UUID index instead would be great - it would also help us avoid things like stacking two range indices.

I think either Phil or I can implement a fix, but the explanation would be helpful if it's solvable.

@ilan-gold
Copy link

I have also run into "distinguishing between void and structured" in zarr so understanding that difference and how to check for it (at least from you) would be amazing for my own knowledge.

@flying-sheep flying-sheep linked a pull request Jun 12, 2025 that will close this issue
5 tasks
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants