Skip to content

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

Merged
merged 1 commit into from
Jan 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.23.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ Timezones
- :func:`Timestamp.replace` will now handle Daylight Savings transitions gracefully (:issue:`18319`)
- Bug in tz-aware :class:`DatetimeIndex` where addition/subtraction with a :class:`TimedeltaIndex` or array with ``dtype='timedelta64[ns]'`` was incorrect (:issue:`17558`)
- Bug in :func:`DatetimeIndex.insert` where inserting ``NaT`` into a timezone-aware index incorrectly raised (:issue:`16357`)
- Bug in the :class:`DataFrame` constructor, where tz-aware Datetimeindex and a given column name will result in an empty ``DataFrame`` (:issue:`19157`)

Offsets
^^^^^^^
Expand Down
6 changes: 5 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,11 @@ 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)
Copy link
Contributor

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

# GH19157
if columns is None:
columns = [0]
return _arrays_to_mgr([values], columns, index, columns,
dtype=dtype)

# by definition an array here
# the dtypes will be coerced to a single dtype
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2092,3 +2092,14 @@ def test_frame_timeseries_to_records(self):
result['index'].dtype == 'M8[ns]'

result = df.to_records(index=False)

def test_frame_timeseries_column(self):
# GH19157
dr = date_range(start='20130101T10:00:00', periods=3, freq='T',
tz='US/Eastern')
result = DataFrame(dr, columns=['timestamps'])
expected = DataFrame({'timestamps': [
Timestamp('20130101T10:00:00', tz='US/Eastern'),
Timestamp('20130101T10:01:00', tz='US/Eastern'),
Timestamp('20130101T10:02:00', tz='US/Eastern')]})
tm.assert_frame_equal(result, expected)