-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
ENH: Enable pytables to round-trip with StringDtype #60663
base: main
Are you sure you want to change the base?
Conversation
if dtype == "str[python]": | ||
dtype = StringDtype("python", np.nan) | ||
elif dtype == "string[python]": | ||
dtype = StringDtype("python", NA) | ||
elif dtype == "str[pyarrow]": | ||
dtype = StringDtype("pyarrow", np.nan) | ||
else: | ||
assert dtype == "string[pyarrow]" | ||
dtype = StringDtype("pyarrow", NA) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if there is a better approach here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StringDtype.construct_from_string
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wouldn't allow round-tripping if you e.g. write out a Python-backed string with NaN-semantics, and read it in an environment with PyArrow installed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool thanks for getting this started. I guess this should be added as an enhancement to 2.3?
vlarr = self._handle.create_vlarray(self.group, key, _tables().ObjectAtom()) | ||
vlarr.append(value.to_numpy()) | ||
node = getattr(self.group, key) | ||
if value.dtype == StringDtype("python", np.nan): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need all the branches here or can you just do str(values.dtype)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as #60663 (comment)
if using_string_dtype() and is_string_array(values, skipna=True): | ||
if ( | ||
using_string_dtype() | ||
and isinstance(values, np.ndarray) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming read_array
can return a non-ndarray type here? Does this prevent against pyarrow arrays?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming
read_array
can return a non-ndarray type here?
Correct - datetime and string currently.
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.Replaces #60625
Writing out with object dtype still infers
str
wheninfer_string=True
.