Skip to content

Commit 9e9b89e

Browse files
committed
Whatsnew and tests fixups
1 parent 4d17722 commit 9e9b89e

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
lines changed

doc/source/whatsnew/v0.21.0.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ Previously, :func:`to_datetime` did not localize datetime ``Series`` data when `
311311

312312
s = Series(['20130101 00:00:00'] * 3)
313313

314-
.. code-block:: python
314+
.. code-block:: ipython
315315

316316
In [12]: pd.to_datetime(s, utc=True)
317317
Out[12]:
@@ -326,7 +326,7 @@ Previously, :func:`to_datetime` did not localize datetime ``Series`` data when `
326326

327327
pd.to_datetime(s, utc=True)
328328

329-
Additionally, DataFrames with datetime columns returned by :func:`read_sql` will also be localized to UTC only if the original SQL columns were timezone aware datetime columns.
329+
Additionally, DataFrames with datetime columns returned by :func:`read_sql_table` and :func:`read_sql_query` with the `parse_dates` argument specified will also be localized to UTC only if the original SQL columns were timezone aware datetime columns.
330330

331331
.. _whatsnew_0210.api:
332332

pandas/tests/indexes/datetimes/test_tools.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -260,16 +260,6 @@ def test_to_datetime_tz_pytz(self):
260260
dtype='datetime64[ns, UTC]', freq=None)
261261
tm.assert_index_equal(result, expected)
262262

263-
def test_to_datetime_utc_is_true(self):
264-
# See gh-11934
265-
start = pd.Timestamp('2014-01-01', tz='utc')
266-
end = pd.Timestamp('2014-01-03', tz='utc')
267-
date_range = pd.bdate_range(start, end)
268-
269-
result = pd.to_datetime(date_range, utc=True)
270-
expected = pd.DatetimeIndex(data=date_range)
271-
tm.assert_index_equal(result, expected)
272-
273263
@pytest.mark.parametrize("init_constructor, end_constructor, test_method",
274264
[(Index, DatetimeIndex, tm.assert_index_equal),
275265
(list, DatetimeIndex, tm.assert_index_equal),
@@ -279,7 +269,7 @@ def test_to_datetime_utc_true_with_constructors(self,
279269
init_constructor,
280270
end_constructor,
281271
test_method):
282-
# GH 6415: UTC=True with Series
272+
# See gh-11934 & gh-6415
283273
data = ['20100102 121314', '20100102 121315']
284274
expected_data = [pd.Timestamp('2010-01-02 12:13:14', tz='utc'),
285275
pd.Timestamp('2010-01-02 12:13:15', tz='utc')]
@@ -290,6 +280,11 @@ def test_to_datetime_utc_true_with_constructors(self,
290280
expected = end_constructor(expected_data)
291281
test_method(result, expected)
292282

283+
# Test scalar case as well
284+
for scalar, expected in zip(data, expected_data):
285+
result = pd.to_datetime(scalar, format='%Y%m%d %H%M%S', utc=True)
286+
assert result == expected
287+
293288
def test_to_datetime_utc_true_with_series_single_value(self):
294289
# GH 15760 UTC=True with Series
295290
ts = 1.5e18

pandas/tests/io/test_sql.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,13 +1271,8 @@ def check(col):
12711271

12721272
# "2000-01-01 00:00:00-08:00" should convert to
12731273
# "2000-01-01 08:00:00"
1274-
assert col[0] == Timestamp('2000-01-01 08:00:00', tz='UTC')
1275-
12761274
# "2000-06-01 00:00:00-07:00" should convert to
12771275
# "2000-06-01 07:00:00"
1278-
assert col[1] == Timestamp('2000-06-01 07:00:00', tz='UTC')
1279-
1280-
# Double check that the Series has been localized correctly
12811276
# GH 6415
12821277
expected_data = [Timestamp('2000-01-01 08:00:00', tz='UTC'),
12831278
Timestamp('2000-06-01 07:00:00', tz='UTC')]
@@ -1305,6 +1300,9 @@ def check(col):
13051300
self.conn, parse_dates=['DateColWithTz'])
13061301
if not hasattr(df, 'DateColWithTz'):
13071302
pytest.skip("no column with datetime with time zone")
1303+
col = df.DateColWithTz
1304+
assert is_datetime64tz_dtype(col.dtype)
1305+
assert str(col.dt.tz) == 'UTC'
13081306
check(df.DateColWithTz)
13091307

13101308
df = pd.concat(list(pd.read_sql_query("select * from types_test_data",
@@ -1314,9 +1312,8 @@ def check(col):
13141312
assert is_datetime64tz_dtype(col.dtype)
13151313
assert str(col.dt.tz) == 'UTC'
13161314
expected = sql.read_sql_table("types_test_data", self.conn)
1317-
tm.assert_series_equal(df.DateColWithTz,
1318-
expected.DateColWithTz
1319-
.astype('datetime64[ns, UTC]'))
1315+
# Removed ".astype('datetime64[ns, UTC]')"after GH 6415 was fixed
1316+
tm.assert_series_equal(df.DateColWithTz, expected.DateColWithTz)
13201317

13211318
# xref #7139
13221319
# this might or might not be converted depending on the postgres driver

0 commit comments

Comments
 (0)