Skip to content

Commit f487995

Browse files
committed
Fix tests and whatnew notes
1 parent 0803fb1 commit f487995

File tree

5 files changed

+18
-21
lines changed

5 files changed

+18
-21
lines changed

doc/source/whatsnew/v0.21.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ The configuration option ``pd.options.mode.use_inf_as_null`` is deprecated, and
208208
UTC Localization with Series
209209
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
210210

211-
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`).
211+
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]`` dtype to be consistent with how list-like and `Index` data are handled. (:issue:`6415`).
212212

213213
Previous Behavior
214214

pandas/io/sql.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -821,13 +821,9 @@ def _harmonize_columns(self, parse_dates=None):
821821

822822
if (col_type is datetime or col_type is date or
823823
col_type is DatetimeTZDtype):
824-
if col_type is DatetimeTZDtype:
825-
# Convert tz-aware Datetime SQL columns to UTC
826-
self.frame[col_name] = _handle_date_column(df_col,
827-
utc=True)
828-
else:
829-
self.frame[col_name] = _handle_date_column(df_col)
830-
824+
# Convert tz-aware Datetime SQL columns to UTC
825+
utc = col_type is DatetimeTZDtype
826+
self.frame[col_name] = _handle_date_column(df_col, utc=utc)
831827
elif col_type is float:
832828
# floats support NA, can always convert!
833829
self.frame[col_name] = df_col.astype(col_type, copy=False)

pandas/tests/indexes/datetimes/test_tools.py

+14-11
Original file line numberDiff line numberDiff line change
@@ -292,17 +292,20 @@ def test_to_datetime_utc_true_with_series_single_value(self):
292292
expected = pd.Series([pd.Timestamp(ts, tz='utc')])
293293
tm.assert_series_equal(result, expected)
294294

295-
@pytest.mark.parametrize("data, dtype",
296-
[('2013-01-01 00:00:00-01:00', None),
297-
('2013-01-01 00:00:00-01:00', 'datetime64[ns]'),
298-
('2013-01-01 01:00:00', None),
299-
('2013-01-01 01:00:00', 'datetime64[ns]')])
300-
def test_to_datetime_utc_true_with_naive_dtype_series(self, data, dtype):
301-
test_dates = [data] * 10
302-
ser = pd.Series(test_dates, dtype=dtype)
303-
result = pd.to_datetime(ser, utc=True)
304-
expected_data = [pd.Timestamp('20130101 01:00:00', tz='utc')] * 10
305-
expected = pd.Series(expected_data)
295+
def test_to_datetime_utc_true_with_series_tzaware_string(self):
296+
ts = '2013-01-01 00:00:00-01:00'
297+
expected_ts = '2013-01-01 01:00:00'
298+
data = pd.Series([ts] * 3)
299+
result = pd.to_datetime(data, utc=True)
300+
expected = pd.Series([pd.Timestamp(expected_ts, tz='utc')] * 3)
301+
tm.assert_series_equal(result, expected)
302+
303+
@pytest.mark.parametrize('date, dtype',
304+
[('2013-01-01 01:00:00', 'datetime64[ns]'),
305+
('2013-01-01 01:00:00', 'datetime64[ns, UTC]')])
306+
def test_to_datetime_utc_true_with_series_datetime_ns(self, date, dtype):
307+
expected = pd.Series([pd.Timestamp('2013-01-01 01:00:00', tz='UTC')])
308+
result = pd.to_datetime(pd.Series([date], dtype=dtype), utc=True)
306309
tm.assert_series_equal(result, expected)
307310

308311
def test_to_datetime_tz_psycopg2(self):

pandas/tests/io/test_sql.py

-1
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,6 @@ def check(col):
13141314
expected = sql.read_sql_table("types_test_data", self.conn)
13151315
col = expected.DateColWithTz
13161316
assert is_datetime64tz_dtype(col.dtype)
1317-
# Removed ".astype('datetime64[ns, UTC]')"after GH 6415 was fixed
13181317
tm.assert_series_equal(df.DateColWithTz, expected.DateColWithTz)
13191318

13201319
# xref #7139

pandas/tests/test_multilevel.py

-1
Original file line numberDiff line numberDiff line change
@@ -2130,7 +2130,6 @@ def test_set_index_datetime(self):
21302130
'2011-07-19 08:00:00', '2011-07-19 09:00:00'],
21312131
'value': range(6)})
21322132
df.index = pd.to_datetime(df.pop('datetime'), utc=True)
2133-
# Removed 'tz_localize('utc') below after GH 6415 was fixed
21342133
df.index = df.index.tz_convert('US/Pacific')
21352134

21362135
expected = pd.DatetimeIndex(['2011-07-19 07:00:00',

0 commit comments

Comments
 (0)