Skip to content

Commit 44d2e2b

Browse files
committed
TST/BUG: DataFrame truncated repr with DatetimeTz and NaT column
1 parent 7bbd031 commit 44d2e2b

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

pandas/tests/formats/test_format.py

+42
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,48 @@ def test_east_asian_unicode_frame(self):
665665
u"¡¡¡ ええええええ 4")
666666
self.assertEqual(_rep(df), expected)
667667

668+
def test_datetimelike_frame(self):
669+
# GH 12211
670+
dts = [pd.Timestamp('2011-01-01', tz='US/Eastern')] * 5 + [pd.NaT] * 5
671+
df = pd.DataFrame({"dt": dts,
672+
"x": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]})
673+
with option_context('display.max_rows', 5):
674+
expected = (' dt x\n'
675+
'0 2011-01-01 00:00:00-05:00 1\n'
676+
'1 2011-01-01 00:00:00-05:00 2\n'
677+
'.. ... ..\n'
678+
'8 NaT 9\n'
679+
'9 NaT 10\n\n'
680+
'[10 rows x 2 columns]')
681+
self.assertEqual(repr(df), expected)
682+
683+
dts = [pd.NaT] * 5 + [pd.Timestamp('2011-01-01', tz='US/Eastern')] * 5
684+
df = pd.DataFrame({"dt": dts,
685+
"x": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]})
686+
with option_context('display.max_rows', 5):
687+
expected = (' dt x\n'
688+
'0 NaT 1\n'
689+
'1 NaT 2\n'
690+
'.. ... ..\n'
691+
'8 2011-01-01 00:00:00-05:00 9\n'
692+
'9 2011-01-01 00:00:00-05:00 10\n\n'
693+
'[10 rows x 2 columns]')
694+
self.assertEqual(repr(df), expected)
695+
696+
dts = ([pd.Timestamp('2011-01-01', tz='Asia/Tokyo')] * 5 +
697+
[pd.Timestamp('2011-01-01', tz='US/Eastern')] * 5)
698+
df = pd.DataFrame({"dt": dts,
699+
"x": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]})
700+
with option_context('display.max_rows', 5):
701+
expected = (' dt x\n'
702+
'0 2011-01-01 00:00:00+09:00 1\n'
703+
'1 2011-01-01 00:00:00+09:00 2\n'
704+
'.. ... ..\n'
705+
'8 2011-01-01 00:00:00-05:00 9\n'
706+
'9 2011-01-01 00:00:00-05:00 10\n\n'
707+
'[10 rows x 2 columns]')
708+
self.assertEqual(repr(df), expected)
709+
668710
def test_to_string_buffer_all_unicode(self):
669711
buf = StringIO()
670712

0 commit comments

Comments
 (0)