Skip to content

Commit 5c85a80

Browse files
committed
TST: added addtl datetimes test in construction (ref GH pandas-dev#2809/2810)
1 parent ccaa428 commit 5c85a80

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

pandas/tests/test_frame.py

+20
Original file line numberDiff line numberDiff line change
@@ -7998,6 +7998,26 @@ def test_constructor_with_datetimes(self):
79987998
expected = Series({'int64': 1, 'float64' : 1, 'datetime64[ns]': 1, 'object' : 1})
79997999
assert_series_equal(result, expected)
80008000

8001+
# GH 2809
8002+
from pandas import date_range
8003+
ind = date_range(start="2000-01-01", freq="D", periods=10)
8004+
datetimes = [ts.to_pydatetime() for ts in ind]
8005+
datetime_s = Series(datetimes)
8006+
self.assert_(datetime_s.dtype == 'M8[ns]')
8007+
df = DataFrame({'datetime_s':datetime_s})
8008+
result = df.get_dtype_counts()
8009+
expected = Series({ 'datetime64[ns]' : 1 })
8010+
assert_series_equal(result, expected)
8011+
8012+
# GH 2810
8013+
ind = date_range(start="2000-01-01", freq="D", periods=10)
8014+
datetimes = [ts.to_pydatetime() for ts in ind]
8015+
dates = [ts.date() for ts in ind]
8016+
df = DataFrame({'datetimes': datetimes, 'dates':dates})
8017+
result = df.get_dtype_counts()
8018+
expected = Series({ 'datetime64[ns]' : 1, 'object' : 1 })
8019+
assert_series_equal(result, expected)
8020+
80018021
def test_constructor_frame_copy(self):
80028022
cop = DataFrame(self.frame, copy=True)
80038023
cop['A'] = 5

pandas/tseries/tests/test_timezones.py

+9
Original file line numberDiff line numberDiff line change
@@ -491,11 +491,20 @@ def test_to_datetime_tzlocal(self):
491491
self.assert_(result.tz is pytz.utc)
492492

493493
def test_frame_no_datetime64_dtype(self):
494+
494495
dr = date_range('2011/1/1', '2012/1/1', freq='W-FRI')
495496
dr_tz = dr.tz_localize('US/Eastern')
496497
e = DataFrame({'A': 'foo', 'B': dr_tz}, index=dr)
497498
self.assert_(e['B'].dtype == 'M8[ns]')
498499

500+
# GH 2810 (with timezones)
501+
datetimes_naive = [ ts.to_pydatetime() for ts in dr ]
502+
datetimes_with_tz = [ ts.to_pydatetime() for ts in dr_tz ]
503+
df = DataFrame({'dr' : dr, 'dr_tz' : dr_tz, 'datetimes_naive': datetimes_naive, 'datetimes_with_tz' : datetimes_with_tz })
504+
result = df.get_dtype_counts()
505+
expected = Series({ 'datetime64[ns]' : 3, 'object' : 1 })
506+
assert_series_equal(result, expected)
507+
499508
def test_hongkong_tz_convert(self):
500509
# #1673
501510
dr = date_range(

0 commit comments

Comments
 (0)