diff --git a/doc/source/whatsnew/v0.23.0.txt b/doc/source/whatsnew/v0.23.0.txt index 4dde76dee46a5..3016b0490873b 100644 --- a/doc/source/whatsnew/v0.23.0.txt +++ b/doc/source/whatsnew/v0.23.0.txt @@ -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 ^^^^^^^ diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 847779b1747cf..7328cd336babf 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -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) + # 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 diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index b7d3a60ecf6e4..8b57e96e6fa06 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -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)