diff --git a/pandas/core/format.py b/pandas/core/format.py index 2773cc0c135c1..89973754a861c 100644 --- a/pandas/core/format.py +++ b/pandas/core/format.py @@ -2027,14 +2027,19 @@ def _format_datetime64_dateonly(x, nat_rep='NaT', date_format=None): def _is_dates_only(values): - for d in values: - if isinstance(d, np.datetime64): - d = Timestamp(d) - - if d is not None and not lib.checknull(d) and d._has_time_component(): - return False - return True + # return a boolean if we are only dates (and don't have a timezone) + from pandas import DatetimeIndex + values = DatetimeIndex(values) + if values.tz is not None: + return False + values_int = values.asi8 + consider_values = values_int != iNaT + one_day_nanos = (86400 * 1e9) + even_days = np.logical_and(consider_values, values_int % one_day_nanos != 0).sum() == 0 + if even_days: + return True + return False def _get_format_datetime64(is_dates_only, nat_rep='NaT', date_format=None): diff --git a/vb_suite/index_object.py b/vb_suite/index_object.py index de60a44e23a52..18e319f6ede55 100644 --- a/vb_suite/index_object.py +++ b/vb_suite/index_object.py @@ -108,7 +108,7 @@ # Constructing MultiIndex from cartesian product of iterables -# +# setup = common_setup + """ iterables = [tm.makeStringIndex(10000), xrange(20)] @@ -130,3 +130,14 @@ Benchmark("MultiIndex.from_product([level1, level2]).values", setup, name='multiindex_with_datetime_level', start_date=datetime(2014, 10, 11)) + +#---------------------------------------------------------------------- +# repr + +setup = common_setup + """ +dr = pd.date_range('20000101', freq='D', periods=100000) +""" + +datetime_index_repr = \ + Benchmark("dr._is_dates_only", setup, + start_date=datetime(2012, 1, 11))