Skip to content

Commit b2fa8c3

Browse files
committed
Add tests with time zones, and clean up DataFrame test
1 parent 369d5ea commit b2fa8c3

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

pandas/tests/test_frame.py

+11-14
Original file line numberDiff line numberDiff line change
@@ -4194,27 +4194,24 @@ def test_astype_cast_nan_int(self):
41944194

41954195
def test_astype_str(self):
41964196
# GH9757
4197-
dts = Series(date_range('2010-01-04', periods=5))
4198-
tds = Series([Timedelta(x, unit='d') for x in range(5)])
4199-
ns = Series(range(5))
4200-
fs = Series([0.0, 0.2, 0.4, 0.6, 0.8])
4197+
a = Series(date_range('2010-01-04', periods=5))
4198+
b = Series(date_range('3/6/2012 00:00', periods=5, tz='US/Eastern'))
4199+
c = Series([Timedelta(x, unit='d') for x in range(5)])
4200+
d = Series(range(5))
4201+
e = Series([0.0, 0.2, 0.4, 0.6, 0.8])
42014202

4202-
df = DataFrame({
4203-
'dts' : dts.values,
4204-
'tds' : tds.values,
4205-
'ns' : ns.values,
4206-
'fs' : fs.values,
4207-
})
4203+
df = DataFrame({'a' : a, 'b' : b, 'c' : c, 'd' : d, 'e' : e})
42084204

42094205
# Test str and unicode on python 2.x and just str on python 3.x
42104206
for tt in set([str, compat.text_type]):
42114207
result = df.astype(tt)
42124208

42134209
expected = DataFrame({
4214-
'dts' : list(map(tt, dts.values)),
4215-
'tds' : list(map(tt, tds.values)),
4216-
'ns' : list(map(tt, ns.values)),
4217-
'fs' : list(map(tt, fs.values)),
4210+
'a' : list(map(tt, a.values)),
4211+
'b' : list(map(tt, b.values)),
4212+
'c' : list(map(tt, c.values)),
4213+
'd' : list(map(tt, d.values)),
4214+
'e' : list(map(tt, e.values)),
42184215
})
42194216

42204217
assert_frame_equal(result, expected)

pandas/tests/test_series.py

+5
Original file line numberDiff line numberDiff line change
@@ -5519,6 +5519,11 @@ def test_astype_str(self):
55195519
expected = Series([tt(ts.values[0])])
55205520
assert_series_equal(s, expected)
55215521

5522+
ts = Series([Timestamp('2010-01-04 00:00:00', tz='US/Eastern')])
5523+
s = ts.astype(tt)
5524+
expected = Series([tt(ts.values[0])])
5525+
assert_series_equal(s, expected)
5526+
55225527
td = Series([Timedelta(1, unit='d')])
55235528
s = td.astype(tt)
55245529
expected = Series([tt(td.values[0])])

0 commit comments

Comments
 (0)