Skip to content

Commit 878263c

Browse files
committed
TST: Parse dates with empty space (#6428)
1 parent 0c82abe commit 878263c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

pandas/io/tests/test_date_converters.py

+13
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,19 @@ def date_parser(date, time):
138138
names=['datetime', 'prn']))
139139
assert_frame_equal(df, df_correct)
140140

141+
def test_parse_date_column_with_empty_string(self):
142+
# GH 6428
143+
data = """case,opdate
144+
7,10/18/2006
145+
7,10/18/2008
146+
621, """
147+
result = read_csv(StringIO(data), parse_dates=['opdate'])
148+
expected_data = [[7, '10/18/2006'],
149+
[7, '10/18/2008'],
150+
[621, ' ']]
151+
expected = DataFrame(expected_data, columns=['case', 'opdate'])
152+
assert_frame_equal(result, expected)
153+
141154
if __name__ == '__main__':
142155
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
143156
exit=False)

pandas/tseries/tests/test_timeseries.py

+12
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,18 @@ def test_to_datetime_on_datetime64_series(self):
947947
result = to_datetime(s)
948948
self.assertEqual(result[0], s[0])
949949

950+
def test_to_datetime_with_space_in_series(self):
951+
# GH 6428
952+
s = Series(['10/18/2006', '10/18/2008', ' '])
953+
tm.assertRaises(ValueError, lambda: to_datetime(s, errors='raise'))
954+
result_coerce = to_datetime(s, errors='coerce')
955+
expected_coerce = Series([datetime(2006, 10, 18),
956+
datetime(2008, 10, 18),
957+
pd.NaT])
958+
tm.assert_series_equal(result_coerce, expected_coerce)
959+
result_ignore = to_datetime(s, errors='ignore')
960+
tm.assert_series_equal(result_ignore, s)
961+
950962
def test_to_datetime_with_apply(self):
951963
# this is only locale tested with US/None locales
952964
_skip_if_has_locale()

0 commit comments

Comments
 (0)