Skip to content

Commit c142975

Browse files
committed
Address comments and confirm timezone tests
1 parent 808a810 commit c142975

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

doc/source/whatsnew/v0.21.0.txt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,13 @@ length 2+ levels, so a :class:`MultiIndex` is always returned from all of the
303303
UTC Localization with Series
304304
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
305305

306-
Previously, :func:`to_datetime` did not localize datetime ``Series`` data as when ``utc=True`` was passed. Now, :func:`to_datetime` will correctly localize `Series` with a `datetime64[ns, UTC]` data type. (:issue:`6415`).
306+
Previously, :func:`to_datetime` did not localize datetime ``Series`` data when ``utc=True`` was passed. Now, :func:`to_datetime` will correctly localize `Series` with a `datetime64[ns, UTC]` data type to be consistent with how list-like and Index data are handled. (:issue:`6415`).
307307

308308
Previous Behavior
309309

310310
.. ipython:: python
311311

312-
s = Series(['20130101 00:00:00'] * 10)
312+
s = Series(['20130101 00:00:00'] * 3)
313313

314314
.. code-block:: python
315315

@@ -318,13 +318,6 @@ Previously, :func:`to_datetime` did not localize datetime ``Series`` data as whe
318318
0 2013-01-01
319319
1 2013-01-01
320320
2 2013-01-01
321-
3 2013-01-01
322-
4 2013-01-01
323-
5 2013-01-01
324-
6 2013-01-01
325-
7 2013-01-01
326-
8 2013-01-01
327-
9 2013-01-01
328321
dtype: datetime64[ns]
329322

330323
New Behavior

pandas/core/tools/datetimes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ def _convert_listlike(arg, box, format, name=None, tz=tz):
516516
result = arg
517517
elif isinstance(arg, ABCSeries):
518518
from pandas import Series
519-
values = _convert_listlike(arg, True, format)
519+
values = _convert_listlike(arg._values, True, format)
520520
result = Series(values, index=arg.index, name=arg.name)
521521
elif isinstance(arg, (ABCDataFrame, MutableMapping)):
522522
result = _assemble_from_unit_mappings(arg, errors=errors)

pandas/io/sql.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,7 @@ def _harmonize_columns(self, parse_dates=None):
818818
df_col = self.frame[col_name]
819819
# the type the dataframe column should have
820820
col_type = self._get_dtype(sql_col.type)
821+
821822
if (col_type is datetime or col_type is date or
822823
col_type is DatetimeTZDtype):
823824
if col_type is DatetimeTZDtype:

pandas/tests/indexes/datetimes/test_tools.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,13 @@ def test_to_datetime_utc_is_true(self):
272272

273273
@pytest.mark.parametrize("init_constructor, end_constructor, test_method",
274274
[(Index, DatetimeIndex, tm.assert_index_equal),
275+
(list, DatetimeIndex, tm.assert_index_equal),
276+
(np.array, DatetimeIndex, tm.assert_index_equal),
275277
(Series, Series, tm.assert_series_equal)])
276-
def test_to_datetime_utc_true_with_series(self,
277-
init_constructor,
278-
end_constructor,
279-
test_method):
278+
def test_to_datetime_utc_true_with_constructors(self,
279+
init_constructor,
280+
end_constructor,
281+
test_method):
280282
# GH 6415: UTC=True with Series
281283
data = ['20100102 121314', '20100102 121315']
282284
expected_data = [pd.Timestamp('2010-01-02 12:13:14', tz='utc'),

pandas/tests/io/test_sql.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,13 @@ def check(col):
12771277
# "2000-06-01 07:00:00"
12781278
assert col[1] == Timestamp('2000-06-01 07:00:00', tz='UTC')
12791279

1280+
# Double check that the Series has been localized correctly
1281+
# GH 6415
1282+
expected_data = [Timestamp('2000-01-01 08:00:00', tz='UTC'),
1283+
Timestamp('2000-06-01 07:00:00', tz='UTC')]
1284+
expected = Series(expected_data)
1285+
tm.assert_series_equal(col, expected)
1286+
12801287
else:
12811288
raise AssertionError("DateCol loaded with incorrect type "
12821289
"-> {0}".format(col.dtype))
@@ -1388,8 +1395,8 @@ def test_datetime_date(self):
13881395
df = DataFrame([date(2014, 1, 1), date(2014, 1, 2)], columns=["a"])
13891396
df.to_sql('test_date', self.conn, index=False)
13901397
res = read_sql_table('test_date', self.conn)
1391-
expected = res['a']
1392-
result = to_datetime(df['a'])
1398+
result = res['a']
1399+
expected = to_datetime(df['a'])
13931400
# comes back as datetime64
13941401
tm.assert_series_equal(result, expected)
13951402

0 commit comments

Comments
 (0)