Skip to content

Commit 1da008a

Browse files
committed
BUG: show time values in repr of high precision DatetimeIndex
1 parent 36a71eb commit 1da008a

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

doc/source/whatsnew/v0.23.0.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,8 @@ Conversion
375375
- Bug in :class:`TimedeltaIndex` where division by a ``Series`` would return a ``TimedeltaIndex`` instead of a ``Series`` (issue:`19042`)
376376
- Bug in :class:`Series` with ``dtype='timedelta64[ns]`` where addition or subtraction of ``TimedeltaIndex`` could return a ``Series`` with an incorrect name (issue:`19043`)
377377
- Fixed bug where comparing :class:`DatetimeIndex` failed to raise ``TypeError`` when attempting to compare timezone-aware and timezone-naive datetimelike objects (:issue:`18162`)
378-
-
378+
- Bug in :class:`DatetimeIndex` where the repr was not showing the time values for the end of the day (:issue:`19030`)
379+
379380

380381
Indexing
381382
^^^^^^^^

pandas/io/formats/format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2188,7 +2188,7 @@ def _is_dates_only(values):
21882188
consider_values = values_int != iNaT
21892189
one_day_nanos = (86400 * 1e9)
21902190
even_days = np.logical_and(consider_values,
2191-
values_int % one_day_nanos != 0).sum() == 0
2191+
values_int % int(one_day_nanos) != 0).sum() == 0
21922192
if even_days:
21932193
return True
21942194
return False

pandas/tests/io/formats/test_format.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,20 @@ def test_datetimelike_frame(self):
883883
'[10 rows x 2 columns]')
884884
assert repr(df) == expected
885885

886+
def test_datetimeindex_highprecision(self):
887+
# GH19030
888+
# Check that time values for the end of day are included in repr
889+
df = DataFrame({'A': date_range(start='2017-01-01 23:59:59.999999999',
890+
freq='D', periods=5)})
891+
result = str(df)
892+
assert "23:59:59.999999999" in result
893+
894+
dti = date_range(start='2017-01-01 23:59:59.999999999',
895+
freq='D', periods=5)
896+
df = DataFrame({'A': range(5)}, index=dti)
897+
result = str(df.index)
898+
assert "23:59:59.999999999" in result
899+
886900
def test_nonunicode_nonascii_alignment(self):
887901
df = DataFrame([["aa\xc3\xa4\xc3\xa4", 1], ["bbbb", 2]])
888902
rep_str = df.to_string()
@@ -1914,6 +1928,20 @@ def test_datetimeindex(self):
19141928
result = str(s2.index)
19151929
assert 'NaT' in result
19161930

1931+
def test_datetimeindex_highprecision(self):
1932+
# GH19030
1933+
# Check that time values for the end of day are included in repr
1934+
s1 = Series(date_range(start='2017-01-01 23:59:59.999999999',
1935+
freq='D', periods=5))
1936+
result = str(s1)
1937+
assert "23:59:59.999999999" in result
1938+
1939+
dti = date_range(start='2017-01-01 23:59:59.999999999', freq='D',
1940+
periods=5)
1941+
s2 = Series(3, index=dti)
1942+
result = str(s2.index)
1943+
assert "23:59:59.999999999" in result
1944+
19171945
def test_timedelta64(self):
19181946

19191947
from datetime import datetime, timedelta

0 commit comments

Comments
 (0)