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

bugfix: read fixed-length string arrays as bytes #982

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

gszep
Copy link

@gszep gszep commented Apr 15, 2023

There is a bug in pandas that prevents fixed-length string arrays np.dtype("S") from being read properly. For some reason the dataframe does the casting properly only if the array is set after dataframe creation.

x = np.array([b"123",b"e23423"], dtype="S")
df = pd.DataFrame({"a": x})
df.types # sees x as object
df = pd.DataFrame({})
df["a"] = x
df.dtypes # correct type

This PR is a workaround until the pandas bug is addressed

@gszep
Copy link
Author

gszep commented Apr 15, 2023

reported in pandas pandas-dev/pandas#51994

@gszep gszep changed the title 950 dataframe bugfix bugfix: read fixed-length string arrays as bytes Apr 15, 2023
@codecov
Copy link

codecov bot commented Apr 15, 2023

Codecov Report

Merging #982 (1794406) into main (dcee1e5) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #982      +/-   ##
==========================================
+ Coverage   84.15%   84.17%   +0.01%     
==========================================
  Files          34       34              
  Lines        4709     4713       +4     
==========================================
+ Hits         3963     3967       +4     
  Misses        746      746              
Impacted Files Coverage Δ
anndata/_io/specs/methods.py 87.90% <100.00%> (+0.12%) ⬆️

Copy link
Member

@ivirshup ivirshup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

If you use assert_equals in those failing tests, we'll probably get more useful error messages. I believe those tests predate that helper.

I would significantly prefer this being fixed upstream, and restricting usable versions of pandas, rather than having to do and then undo fixes + multiple releases here. Would you be up for tackling this upstream?

Also, is this issue new with pandas 2.0?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants