Skip to content

TST: added addtl datetimes test in construction (ref GH #2809/#2810) #2834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -7998,6 +7998,26 @@ def test_constructor_with_datetimes(self):
expected = Series({'int64': 1, 'float64' : 1, 'datetime64[ns]': 1, 'object' : 1})
assert_series_equal(result, expected)

# GH 2809
from pandas import date_range
ind = date_range(start="2000-01-01", freq="D", periods=10)
datetimes = [ts.to_pydatetime() for ts in ind]
datetime_s = Series(datetimes)
self.assert_(datetime_s.dtype == 'M8[ns]')
df = DataFrame({'datetime_s':datetime_s})
result = df.get_dtype_counts()
expected = Series({ 'datetime64[ns]' : 1 })
assert_series_equal(result, expected)

# GH 2810
ind = date_range(start="2000-01-01", freq="D", periods=10)
datetimes = [ts.to_pydatetime() for ts in ind]
dates = [ts.date() for ts in ind]
df = DataFrame({'datetimes': datetimes, 'dates':dates})
result = df.get_dtype_counts()
expected = Series({ 'datetime64[ns]' : 1, 'object' : 1 })
assert_series_equal(result, expected)

def test_constructor_frame_copy(self):
cop = DataFrame(self.frame, copy=True)
cop['A'] = 5
Expand Down
9 changes: 9 additions & 0 deletions pandas/tseries/tests/test_timezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,11 +491,20 @@ def test_to_datetime_tzlocal(self):
self.assert_(result.tz is pytz.utc)

def test_frame_no_datetime64_dtype(self):

dr = date_range('2011/1/1', '2012/1/1', freq='W-FRI')
dr_tz = dr.tz_localize('US/Eastern')
e = DataFrame({'A': 'foo', 'B': dr_tz}, index=dr)
self.assert_(e['B'].dtype == 'M8[ns]')

# GH 2810 (with timezones)
datetimes_naive = [ ts.to_pydatetime() for ts in dr ]
datetimes_with_tz = [ ts.to_pydatetime() for ts in dr_tz ]
df = DataFrame({'dr' : dr, 'dr_tz' : dr_tz, 'datetimes_naive': datetimes_naive, 'datetimes_with_tz' : datetimes_with_tz })
result = df.get_dtype_counts()
expected = Series({ 'datetime64[ns]' : 3, 'object' : 1 })
assert_series_equal(result, expected)

def test_hongkong_tz_convert(self):
# #1673
dr = date_range(
Expand Down