Skip to content

Commit db35ff4

Browse files
sinhrksjreback
authored andcommitted
TST/BUG: DataFrame truncated repr with DatetimeTz and NaT column
closes #12211 Author: sinhrks <[email protected]> Closes #13039 from sinhrks/format_tz and squashes the following commits: 44d2e2b [sinhrks] TST/BUG: DataFrame truncated repr with DatetimeTz and NaT column
1 parent 35e3933 commit db35ff4

File tree

2 files changed

+55
-13
lines changed

2 files changed

+55
-13
lines changed

doc/source/whatsnew/v0.18.1.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -494,13 +494,13 @@ Bug Fixes
494494
- Bug in printing data which contains ``Period`` with different ``freq`` raises ``ValueError`` (:issue:`12615`)
495495
- Bug in numpy compatibility of ``np.round()`` on a ``Series`` (:issue:`12600`)
496496
- Bug in ``Series`` construction with ``Categorical`` and ``dtype='category'`` is specified (:issue:`12574`)
497-
- Bugs in concatenation with a coercable dtype was too aggressive. (:issue:`12411`, :issue:`12045`, :issue:`11594`, :issue:`10571`)
497+
- Bugs in concatenation with a coercable dtype was too aggressive. (:issue:`12411`, :issue:`12045`, :issue:`11594`, :issue:`10571`, :issue:`12211`)
498498
- Bug in ``float_format`` option with option not being validated as a callable. (:issue:`12706`)
499499
- Bug in ``GroupBy.filter`` when ``dropna=False`` and no groups fulfilled the criteria (:issue:`12768`)
500500
- Bug in ``__name__`` of ``.cum*`` functions (:issue:`12021`)
501501
- Bug in ``.astype()`` of a ``Float64Inde/Int64Index`` to an ``Int64Index`` (:issue:`12881`)
502502
- Bug in roundtripping an integer based index in ``.to_json()/.read_json()`` when ``orient='index'`` (the default) (:issue:`12866`)
503-
503+
- Bug in plotting ``Categorical`` dtypes cause error when attempting stacked bar plot (:issue:`13019`)
504504
- Compat with >= numpy 1.11 for NaT comparions (:issue:`12969`)
505505
- Bug in ``.drop()`` with a non-unique ``MultiIndex``. (:issue:`12701`)
506506
- Bug in ``.concat`` of datetime tz-aware and naive DataFrames (:issue:`12467`)

pandas/tests/formats/test_format.py

+53-11
Original file line numberDiff line numberDiff line change
@@ -732,19 +732,9 @@ def test_to_string_truncate_multilevel(self):
732732

733733
def test_truncate_with_different_dtypes(self):
734734

735-
# 11594, 12045, 12211
735+
# 11594, 12045
736736
# when truncated the dtypes of the splits can differ
737737

738-
# 12211
739-
df = DataFrame({'date' : [pd.Timestamp('20130101').tz_localize('UTC')] + [pd.NaT]*5})
740-
741-
with option_context("display.max_rows", 5):
742-
result = str(df)
743-
self.assertTrue('2013-01-01 00:00:00+00:00' in result)
744-
self.assertTrue('NaT' in result)
745-
self.assertTrue('...' in result)
746-
self.assertTrue('[6 rows x 1 columns]' in result)
747-
748738
# 11594
749739
import datetime
750740
s = Series([datetime.datetime(2012, 1, 1)]*10 + [datetime.datetime(1012,1,2)] + [datetime.datetime(2012, 1, 3)]*10)
@@ -761,6 +751,58 @@ def test_truncate_with_different_dtypes(self):
761751
self.assertTrue('None' in result)
762752
self.assertFalse('NaN' in result)
763753

754+
def test_datetimelike_frame(self):
755+
756+
# GH 12211
757+
df = DataFrame({'date' : [pd.Timestamp('20130101').tz_localize('UTC')] + [pd.NaT]*5})
758+
759+
with option_context("display.max_rows", 5):
760+
result = str(df)
761+
self.assertTrue('2013-01-01 00:00:00+00:00' in result)
762+
self.assertTrue('NaT' in result)
763+
self.assertTrue('...' in result)
764+
self.assertTrue('[6 rows x 1 columns]' in result)
765+
766+
dts = [pd.Timestamp('2011-01-01', tz='US/Eastern')] * 5 + [pd.NaT] * 5
767+
df = pd.DataFrame({"dt": dts,
768+
"x": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]})
769+
with option_context('display.max_rows', 5):
770+
expected = (' dt x\n'
771+
'0 2011-01-01 00:00:00-05:00 1\n'
772+
'1 2011-01-01 00:00:00-05:00 2\n'
773+
'.. ... ..\n'
774+
'8 NaT 9\n'
775+
'9 NaT 10\n\n'
776+
'[10 rows x 2 columns]')
777+
self.assertEqual(repr(df), expected)
778+
779+
dts = [pd.NaT] * 5 + [pd.Timestamp('2011-01-01', tz='US/Eastern')] * 5
780+
df = pd.DataFrame({"dt": dts,
781+
"x": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]})
782+
with option_context('display.max_rows', 5):
783+
expected = (' dt x\n'
784+
'0 NaT 1\n'
785+
'1 NaT 2\n'
786+
'.. ... ..\n'
787+
'8 2011-01-01 00:00:00-05:00 9\n'
788+
'9 2011-01-01 00:00:00-05:00 10\n\n'
789+
'[10 rows x 2 columns]')
790+
self.assertEqual(repr(df), expected)
791+
792+
dts = ([pd.Timestamp('2011-01-01', tz='Asia/Tokyo')] * 5 +
793+
[pd.Timestamp('2011-01-01', tz='US/Eastern')] * 5)
794+
df = pd.DataFrame({"dt": dts,
795+
"x": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]})
796+
with option_context('display.max_rows', 5):
797+
expected = (' dt x\n'
798+
'0 2011-01-01 00:00:00+09:00 1\n'
799+
'1 2011-01-01 00:00:00+09:00 2\n'
800+
'.. ... ..\n'
801+
'8 2011-01-01 00:00:00-05:00 9\n'
802+
'9 2011-01-01 00:00:00-05:00 10\n\n'
803+
'[10 rows x 2 columns]')
804+
self.assertEqual(repr(df), expected)
805+
764806
def test_to_html_with_col_space(self):
765807
def check_with_width(df, col_space):
766808
import re

0 commit comments

Comments
 (0)