-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: DataFrame.from_records with empty rec array #20806
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: DataFrame.from_records with empty rec array #20806
Conversation
keep the dtypes Closes pandas-dev#20805
pandas/core/frame.py
Outdated
@@ -7387,7 +7387,10 @@ def _to_arrays(data, columns, coerce_float=False, dtype=None): | |||
if isinstance(data, np.ndarray): | |||
columns = data.dtype.names | |||
if columns is not None: | |||
return [[]] * len(columns), columns | |||
arrays = [np.array([], dtype=dtype) | |||
for _, dtype in data.dtype.descr] |
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.
What's the reasoning for using the descr
here instead of just the dtype? ref #20734 and the docs for dtype.descr
I think we may run into some obscure issues using the str representation of the type instead of the type directly
assert df.index.name == 'id' | ||
|
||
def test_from_records_empty_dtypes(self): |
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.
Think we should cover more dtypes? Perhaps a good use case for a shared fixture?
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.
can you add some more here?
@WillAyd comments, and a lint issue. otherwise lgtm. |
Codecov Report
@@ Coverage Diff @@
## master #20806 +/- ##
==========================================
+ Coverage 91.81% 91.83% +0.02%
==========================================
Files 153 153
Lines 49318 49319 +1
==========================================
+ Hits 45279 45294 +15
+ Misses 4039 4025 -14
Continue to review full report at Codecov.
|
Hmm I can't reproduce the failures locally with those versions of python / NumPy. May end up pushing this. The |
@@ -1092,6 +1092,7 @@ Numeric | |||
- Bug in :class:`Series` constructor with an int or float list where specifying ``dtype=str``, ``dtype='str'`` or ``dtype='U'`` failed to convert the data elements to strings (:issue:`16605`) | |||
- Bug in :class:`Index` multiplication and division methods where operating with a ``Series`` would return an ``Index`` object instead of a ``Series`` object (:issue:`19042`) | |||
- Bug in the :class:`DataFrame` constructor in which data containing very large positive or very large negative numbers was causing ``OverflowError`` (:issue:`18584`) | |||
- Bug in the :meth:`DataFrame.from_records` constructor losing the dtypes of a empty NumPy record array (:issue:`20805`) |
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.
move to 0.23.1
assert df.index.name == 'id' | ||
|
||
def test_from_records_empty_dtypes(self): |
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.
can you add some more here?
can you rebase |
closing as stale. if you'd like to continue, pls ping. |
keep the dtypes
Closes #20805