-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: DatetimeIndex(tz) & single column name, return empty df (GH19157) #19330
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
Conversation
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.
needs tests from the original issue. add tests first locally, then make sure they fail! then add a fix to see if it passes.
add a whatsnew note
@@ -518,7 +518,17 @@ def _get_axes(N, K, index=index, columns=columns): | |||
return _arrays_to_mgr([values], columns, index, columns, | |||
dtype=dtype) | |||
elif is_datetimetz(values): | |||
return self._init_dict({0: values}, index, columns, dtype=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.
I think we we can just call _arrays_to_mgr
here instead, w/o all of this additional code
you can add tests for #13407 as well (if this fixes it). |
Codecov Report
@@ Coverage Diff @@
## master #19330 +/- ##
==========================================
- Coverage 91.65% 91.63% -0.03%
==========================================
Files 150 150
Lines 48724 48726 +2
==========================================
- Hits 44658 44648 -10
- Misses 4066 4078 +12
Continue to review full report at Codecov.
|
git diff upstream/master -u -- "*.py" | flake8 --diff
This issue is due to self._init_dict({0: values}, index, columns, dtype=dtype) will call for the filtering if columns passed (
data = {k: v for k, v in compat.iteritems(data) if k in columns}
), see function_init_dict
of frame.pySo
self._init_dict({0: values}, index, columns, dtype=dtype)
expects the column name of values as '0', but since we pass a column with a different name, upon filtering it will result in an empty DataFrame.My solution assumes that the conversion of a series of DatetimeIndex with tz_info. Hence, we will initialize a DataFrame according to the given column name. If no column name specified, index '0' is chosen. I introduced an assertion to warn the users if multiple column names are passed.
Update 27-01-2018: The updated PR includes a test, and update on whatsnew entry. The revised solution uses
_arrays_to_mgr
instead, such that a default column name 0 is specified ifcolumns
not specified.