Skip to content

Commit 59c719c

Browse files
committed
Address comments
1 parent 6cb20a7 commit 59c719c

File tree

4 files changed

+60
-17
lines changed

4 files changed

+60
-17
lines changed

asv_bench/benchmarks/timeseries.py

+25-10
Original file line numberDiff line numberDiff line change
@@ -386,20 +386,35 @@ def time_format_exact(self):
386386
def time_format_no_exact(self):
387387
to_datetime(self.s, format='%d%b%y', exact=False)
388388

389-
def time_cache_with_unique_seconds_and_unit(self):
390-
to_datetime(self.unique_numeric_seconds, unit='s')
389+
def time_cache_true_with_unique_seconds_and_unit(self):
390+
to_datetime(self.unique_numeric_seconds, unit='s', cache=True)
391391

392-
def time_cache_with_dup_seconds_and_unit(self):
393-
to_datetime(self.dup_numeric_seconds, unit='s')
392+
def time_cache_false_with_unique_seconds_and_unit(self):
393+
to_datetime(self.unique_numeric_seconds, unit='s', cache=False)
394394

395-
def time_cache_with_dup_string_dates(self):
396-
to_datetime(self.dup_string_dates)
395+
def time_cache_true_with_dup_seconds_and_unit(self):
396+
to_datetime(self.dup_numeric_seconds, unit='s', cache=True)
397397

398-
def time_cache_with_dup_string_dates_and_format(self):
399-
to_datetime(self.dup_string_dates, format='%Y-%m-%d')
398+
def time_cache_false_with_dup_seconds_and_unit(self):
399+
to_datetime(self.dup_numeric_seconds, unit='s', cache=False)
400400

401-
def time_cache_with_dup_string_tzoffset_dates(self):
402-
to_datetime(self.dup_string_with_tz)
401+
def time_cache_true_with_dup_string_dates(self):
402+
to_datetime(self.dup_string_dates, cache=True)
403+
404+
def time_cache_false_with_dup_string_dates(self):
405+
to_datetime(self.dup_string_dates, cache=False)
406+
407+
def time_cache_true_with_dup_string_dates_and_format(self):
408+
to_datetime(self.dup_string_dates, format='%Y-%m-%d', cache=True)
409+
410+
def time_cache_false_with_dup_string_dates_and_format(self):
411+
to_datetime(self.dup_string_dates, format='%Y-%m-%d', cache=False)
412+
413+
def time_cache_true_with_dup_string_tzoffset_dates(self):
414+
to_datetime(self.dup_string_with_tz, cache=True)
415+
416+
def time_cache_false_with_dup_string_tzoffset_dates(self):
417+
to_datetime(self.dup_string_with_tz, cache=False)
403418

404419

405420
class Offsets(object):

doc/source/whatsnew/v0.22.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Performance Improvements
7070
~~~~~~~~~~~~~~~~~~~~~~~~
7171

7272
- Indexers on Series or DataFrame no longer create a reference cycle (:issue:`17956`)
73-
- Added a keyword argument, ``cache``, to :func:`to_datetime` that improved the performance of converting duplicate datetime arguments (:issue:`11665`)
73+
- Added a keyword argument, ``cache``, to :func:`to_datetime` that improved the performance of converting duplicate datetime arguments. The ``cache`` keyword is set to ``False`` by default. (:issue:`11665`)
7474
-
7575

7676
.. _whatsnew_0220.docs:

pandas/core/tools/datetimes.py

+31-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,21 @@ def _guess_datetime_format_for_array(arr, **kwargs):
3737

3838

3939
def _maybe_cache(arg, format, cache, tz, _convert_listlike):
40-
"""Create a cache of unique dates from an array of dates"""
40+
"""
41+
Create a cache of unique dates from an array of dates
42+
43+
Parameters
44+
----------
45+
arg : integer, float, string, datetime, list, tuple, 1-d array of dates
46+
format : string, strftime to parse time
47+
cache: boolean, whether to convert with cache
48+
tz: string, timezone of the dates
49+
_convert_listlike: function, conversion function to apply on dates
50+
51+
Returns
52+
-------
53+
cache_array: Series, cache of converted, unique dates, can be empty
54+
"""
4155
from pandas import Series
4256
cache_array = Series()
4357
if cache:
@@ -52,7 +66,22 @@ def _maybe_cache(arg, format, cache, tz, _convert_listlike):
5266

5367

5468
def _convert_and_box_cache(arg, cache_array, box, errors, tz, name=None):
55-
"""Convert array of dates with a cache and box the result"""
69+
"""
70+
Convert array of dates with a cache and box the result
71+
72+
Parameters
73+
----------
74+
arg : integer, float, string, datetime, list, tuple, 1-d array of dates
75+
cache_array: Series, cache of converted, unique dates
76+
box: boolean, True boxes result as an Index-like
77+
errors: string, 'ignore' plus box=True will convert result to Index
78+
tz: string, timezone of the dates
79+
name: string, default None. name for a DatetimeIndex
80+
81+
Returns
82+
-------
83+
result: Index-like if box=True else array-like of converted dates
84+
"""
5685
from pandas import Series, DatetimeIndex, Index
5786
result = Series(arg).map(cache_array)
5887
if box:

pandas/tests/indexes/datetimes/test_tools.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,9 @@ def test_to_datetime_tz_psycopg2(self, cache):
372372
dtype='datetime64[ns, UTC]')
373373
tm.assert_index_equal(result, expected)
374374

375-
bool_skip = pytest.mark.skipif(True, reason="GH 18111")
376-
377-
@pytest.mark.parametrize('cache', [pytest.param(True, marks=bool_skip),
378-
False])
375+
@pytest.mark.parametrize('cache',
376+
[pytest.param(True, marks=pytest.mark.skipif(True, reason="GH 18111")),
377+
False])
379378
def test_datetime_bool(self, cache):
380379
# GH13176
381380
with pytest.raises(TypeError):

0 commit comments

Comments
 (0)