diff --git a/asv_bench/benchmarks/io/csv.py b/asv_bench/benchmarks/io/csv.py index d48f37cc45e99..88c2a6f997a5e 100644 --- a/asv_bench/benchmarks/io/csv.py +++ b/asv_bench/benchmarks/io/csv.py @@ -50,6 +50,24 @@ def time_frame_date_formatting(self): self.data.to_csv(self.fname, date_format='%Y%m%d') +class ToCSVDatetimeBig(BaseIO): + + fname = '__test__.csv' + timeout = 1500 + params = [1000, 10000, 100000] + param_names = ['obs'] + + def setup(self, obs): + d = '2018-11-29' + dt = '2018-11-26 11:18:27.0' + self.data = DataFrame({'dt': [np.datetime64(dt)] * obs, + 'd': [np.datetime64(d)] * obs, + 'r': [np.random.uniform()] * obs}) + + def time_frame(self, obs): + self.data.to_csv(self.fname) + + class StringIORewind: def data(self, stringio_object): diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 20d4f46348be6..f1bec18da30e7 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -249,6 +249,7 @@ Performance Improvements - Improved performance of :meth:`pandas.core.groupby.GroupBy.quantile` (:issue:`20405`) - Improved performance of :meth:`read_csv` by faster tokenizing and faster parsing of small float numbers (:issue:`25784`) - Improved performance of :meth:`read_csv` by faster parsing of N/A and boolean values (:issue:`25804`) +- Improved performance of :meth:DataFrame.`to_csv` when write datetime dtype data (:issue:`25708`) .. _whatsnew_0250.bug_fixes: diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 97d16de6ad088..662fe6e3ecb37 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -2178,6 +2178,7 @@ def to_native_types(self, slicer=None, na_rep=None, date_format=None, i8values = self.values.view('i8') if slicer is not None: + values = values[..., slicer] i8values = i8values[..., slicer] from pandas.io.formats.format import _get_format_datetime64_from_values