Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make DateOffset.kwds a property #19403

Merged
merged 4 commits into from
Feb 2, 2018
Merged

Conversation

jbrockmendel
Copy link
Member

Returning to an older goal of making DateOffset immutable, this PR moves towards getting rid of DateOffset.kwds by making it a property instead of regular attribute. This uses the _get_attributes_dict pattern, albeit without actually using a _get_attributes_dict method.

I expect this to entail a small perf penalty since lookups are slower, but that's small potatoes next to the speedups we'll get from caching once these are immutable.

asv continuous -E virtualenv -f 1.1 master HEAD -b offset -b timeseries
[...]
    before     after       ratio
  [d3f7d2a6] [fe7a7187]
+   11.46μs    41.89μs      3.66  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<DateOffset: kwds={'months': 2, 'days': 2}>)
+    2.03ms     5.53ms      2.72  timeseries.ResampleSeries.time_resample('datetime', '5min', 'mean')
+    2.15ms     4.68ms      2.17  timeseries.ResampleSeries.time_resample('datetime', '1D', 'ohlc')
+   14.36μs    29.72μs      2.07  offset.OffestDatetimeArithmetic.time_add_10(<YearEnd: month=12>)
+    2.56ms     4.42ms      1.73  timeseries.ToDatetimeCache.time_dup_string_tzoffset_dates(True)
+   11.83μs    18.85μs      1.59  offset.OffestDatetimeArithmetic.time_add(<DateOffset: kwds={'months': 2, 'days': 2}>)
+    9.60μs    14.96μs      1.56  offset.OffestDatetimeArithmetic.time_apply(<DateOffset: kwds={'months': 2, 'days': 2}>)
+   28.55μs    42.49μs      1.49  offset.OffestDatetimeArithmetic.time_subtract(<DateOffset: kwds={'months': 2, 'days': 2}>)
+   12.76μs    18.56μs      1.45  offset.OffestDatetimeArithmetic.time_add(<BusinessYearEnd: month=12>)
+    7.69μs    10.75μs      1.40  timeseries.AsOf.time_asof_single_early('Series')
+    8.71ms    11.63ms      1.34  timeseries.ResampleSeries.time_resample('period', '5min', 'mean')
+   15.21μs    20.20μs      1.33  offset.OffestDatetimeArithmetic.time_add_10(<MonthEnd>)
+   14.20μs    18.47μs      1.30  offset.OffestDatetimeArithmetic.time_add_10(<BusinessQuarterEnd: startingMonth=3>)
+   17.44μs    21.72μs      1.25  offset.OffestDatetimeArithmetic.time_subtract_10(<SemiMonthBegin: day_of_month=15>)
+   11.22μs    13.54μs      1.21  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<YearEnd: month=12>)
+   13.63μs    16.37μs      1.20  offset.OffestDatetimeArithmetic.time_subtract(<BusinessMonthBegin>)
+   10.22μs    12.27μs      1.20  offset.OffestDatetimeArithmetic.time_apply(<BusinessDay>)
+   65.62μs    78.64μs      1.20  offset.OffestDatetimeArithmetic.time_add_10(<DateOffset: kwds={'months': 2, 'days': 2}>)
+   14.46μs    17.28μs      1.19  offset.OffestDatetimeArithmetic.time_subtract(<QuarterBegin: startingMonth=3>)
+   16.11μs    19.14μs      1.19  offset.OffestDatetimeArithmetic.time_subtract(<BusinessDay>)
+   16.31μs    19.07μs      1.17  offset.OffestDatetimeArithmetic.time_subtract_10(<BusinessYearBegin: month=1>)
+    2.35ms     2.73ms      1.16  timeseries.DatetimeIndex.time_unique('tz_naive')
+   15.43μs    17.89μs      1.16  offset.OffestDatetimeArithmetic.time_subtract_10(<BusinessMonthBegin>)
+   10.68μs    12.38μs      1.16  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<MonthEnd>)
+   10.57μs    12.24μs      1.16  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<BusinessMonthEnd>)
+   14.26μs    16.48μs      1.16  offset.OffestDatetimeArithmetic.time_add_10(<MonthBegin>)
+  121.98μs   140.64μs      1.15  offset.OffestDatetimeArithmetic.time_subtract_10(<DateOffset: kwds={'months': 2, 'days': 2}>)
+   16.60μs    19.11μs      1.15  offset.OffestDatetimeArithmetic.time_subtract_10(<BusinessYearEnd: month=12>)
+   15.66μs    18.00μs      1.15  offset.OffestDatetimeArithmetic.time_subtract(<YearEnd: month=12>)
+   16.78μs    19.25μs      1.15  offset.OffestDatetimeArithmetic.time_subtract(<SemiMonthEnd: day_of_month=15>)
+   13.87μs    15.89μs      1.15  offset.OffestDatetimeArithmetic.time_add_10(<BusinessYearEnd: month=12>)
+   14.96μs    17.13μs      1.14  offset.OffestDatetimeArithmetic.time_subtract(<BusinessQuarterBegin: startingMonth=3>)
+   15.27μs    17.43μs      1.14  offset.OffestDatetimeArithmetic.time_subtract_10(<BusinessMonthEnd>)
+   12.88μs    14.66μs      1.14  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<BusinessDay>)
+  251.65μs   285.47μs      1.13  offset.OffsetDatetimeIndexArithmetic.time_add_offset(<BusinessQuarterEnd: startingMonth=3>)
+   13.84μs    15.66μs      1.13  offset.OffestDatetimeArithmetic.time_add_10(<YearBegin: month=1>)
+   14.68ms    16.59ms      1.13  timeseries.DatetimeIndex.time_to_time('tz_naive')
+   16.66μs    18.79μs      1.13  offset.OffestDatetimeArithmetic.time_subtract_10(<YearEnd: month=12>)
+   10.00μs    11.19μs      1.12  offset.OffestDatetimeArithmetic.time_apply(<BusinessYearBegin: month=1>)
+   10.30μs    11.50μs      1.12  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<BusinessYearEnd: month=12>)
+   17.44μs    19.47μs      1.12  offset.OffestDatetimeArithmetic.time_subtract(<SemiMonthBegin: day_of_month=15>)
+   18.07μs    20.13μs      1.11  offset.OffestDatetimeArithmetic.time_add_10(<SemiMonthEnd: day_of_month=15>)
+   18.09μs    20.08μs      1.11  offset.OffestDatetimeArithmetic.time_add(<CustomBusinessDay>)
+   14.65μs    16.26μs      1.11  offset.OffestDatetimeArithmetic.time_add_10(<BusinessMonthEnd>)
+    5.32ms     5.91ms      1.11  offset.OffsetDatetimeIndexArithmetic.time_add_offset(<SemiMonthBegin: day_of_month=15>)
+   11.54μs    12.80μs      1.11  offset.OffestDatetimeArithmetic.time_add(<MonthBegin>)
+   12.23μs    13.55μs      1.11  offset.OffestDatetimeArithmetic.time_add(<BusinessQuarterEnd: startingMonth=3>)
+   15.25μs    16.87μs      1.11  offset.OffestDatetimeArithmetic.time_subtract_10(<MonthEnd>)
+   17.78μs    19.66μs      1.11  offset.OffestDatetimeArithmetic.time_subtract_10(<BusinessDay>)
+   18.13μs    20.05μs      1.11  offset.OffestDatetimeArithmetic.time_subtract_10(<BusinessQuarterEnd: startingMonth=3>)
+   21.89μs    24.19μs      1.10  offset.OffestDatetimeArithmetic.time_subtract_10(<Day>)
+    9.94μs    10.97μs      1.10  offset.OffestDatetimeArithmetic.time_apply(<SemiMonthEnd: day_of_month=15>)
+   10.74μs    11.85μs      1.10  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<BusinessYearBegin: month=1>)
+   18.51μs    20.39μs      1.10  offset.OffestDatetimeArithmetic.time_subtract_10(<SemiMonthEnd: day_of_month=15>)
+   39.52ms    43.52ms      1.10  timeseries.Factorize.time_factorize('Asia/Tokyo')
-   16.22μs    14.75μs      0.91  offset.OffestDatetimeArithmetic.time_add_10(<QuarterBegin: startingMonth=3>)
-   73.13ms    65.36ms      0.89  timeseries.ToDatetimeCache.time_dup_string_tzoffset_dates(False)
-   13.39μs    11.60μs      0.87  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<BusinessQuarterBegin: startingMonth=3>)
-   25.04μs    21.37μs      0.85  offset.OffestDatetimeArithmetic.time_add_10(<Day>)
-   14.25μs    11.66μs      0.82  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<QuarterEnd: startingMonth=3>)
-   44.47ms    34.93ms      0.79  timeseries.Factorize.time_factorize(None)
-    1.98ms     1.45ms      0.73  timeseries.ToDatetimeCache.time_dup_string_dates(False)
-    4.23ms     1.69ms      0.40  timeseries.ResampleSeries.time_resample('datetime', '1D', 'mean')

asv continuous -E virtualenv -f 1.1 master HEAD -b offset -b timeseries
[...]
+   17.01μs    35.30μs      2.08  offset.OffestDatetimeArithmetic.time_subtract_10(<BusinessQuarterBegin: startingMonth=3>)
+    3.02ms     4.90ms      1.62  timeseries.AsOf.time_asof_nan_single('DataFrame')
+   77.45ms   124.97ms      1.61  timeseries.Factorize.time_factorize('Asia/Tokyo')
+   12.33μs    19.34μs      1.57  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<DateOffset: days=2, months=2>)
+    9.65μs    14.70μs      1.52  offset.OffestDatetimeArithmetic.time_apply(<DateOffset: days=2, months=2>)
+   11.65μs    17.30μs      1.48  offset.OffestDatetimeArithmetic.time_add(<DateOffset: days=2, months=2>)
+   27.81μs    40.60μs      1.46  offset.OffestDatetimeArithmetic.time_subtract(<DateOffset: days=2, months=2>)
+   71.60μs    91.28μs      1.27  offset.OffestDatetimeArithmetic.time_add(<CustomBusinessMonthEnd>)
+   92.47μs   113.39μs      1.23  offset.OffestDatetimeArithmetic.time_subtract(<CustomBusinessMonthBegin>)
+   18.89μs    23.02μs      1.22  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<Day>)
+   10.49μs    12.66μs      1.21  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<BusinessMonthBegin>)
+   16.88μs    20.14μs      1.19  offset.OffestDatetimeArithmetic.time_subtract(<SemiMonthEnd: day_of_month=15>)
+   15.45μs    18.27μs      1.18  offset.OffestDatetimeArithmetic.time_add_10(<QuarterEnd: startingMonth=3>)
+    8.37μs     9.90μs      1.18  offset.OffestDatetimeArithmetic.time_apply(<MonthBegin>)
+   62.24μs    73.22μs      1.18  offset.OffestDatetimeArithmetic.time_add_10(<DateOffset: days=2, months=2>)
+   21.38μs    24.98μs      1.17  offset.OffestDatetimeArithmetic.time_add_10(<Day>)
+   16.28μs    18.91μs      1.16  offset.OffestDatetimeArithmetic.time_subtract_10(<QuarterBegin: startingMonth=3>)
+   12.20μs    14.11μs      1.16  offset.OffestDatetimeArithmetic.time_add(<BusinessQuarterEnd: startingMonth=3>)
+   11.51μs    13.30μs      1.16  offset.OffestDatetimeArithmetic.time_add(<BusinessYearBegin: month=1>)
+   12.89μs    14.83μs      1.15  offset.OffestDatetimeArithmetic.time_add(<SemiMonthBegin: day_of_month=15>)
+   14.39μs    16.51μs      1.15  offset.OffestDatetimeArithmetic.time_add_10(<QuarterBegin: startingMonth=3>)
+   10.50μs    12.03μs      1.15  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<YearEnd: month=12>)
+    2.32ms     2.66ms      1.14  timeseries.DatetimeIndex.time_unique('tz_naive')
+   15.92μs    18.08μs      1.14  offset.OffestDatetimeArithmetic.time_subtract_10(<BusinessMonthEnd>)
+  123.41μs   140.13μs      1.14  offset.OffestDatetimeArithmetic.time_subtract_10(<DateOffset: days=2, months=2>)
+   71.20ms    80.52ms      1.13  offset.OffsetSeriesArithmetic.time_add_offset(<CustomBusinessMonthEnd>)
+   17.68μs    19.89μs      1.13  offset.OffestDatetimeArithmetic.time_subtract_10(<BusinessYearBegin: month=1>)
+   15.36μs    17.23μs      1.12  offset.OffestDatetimeArithmetic.time_subtract_10(<MonthBegin>)
+   15.98μs    17.82μs      1.12  offset.OffestDatetimeArithmetic.time_add_10(<SemiMonthBegin: day_of_month=15>)
+   14.64μs    16.31μs      1.11  offset.OffestDatetimeArithmetic.time_add_10(<BusinessMonthEnd>)
+    8.96μs     9.94μs      1.11  offset.OffestDatetimeArithmetic.time_apply(<BusinessYearEnd: month=12>)
+   17.27μs    19.16μs      1.11  offset.OffestDatetimeArithmetic.time_subtract_10(<YearEnd: month=12>)
+   14.44μs    16.01μs      1.11  offset.OffestDatetimeArithmetic.time_subtract(<BusinessYearBegin: month=1>)
+   15.26μs    16.90μs      1.11  offset.OffestDatetimeArithmetic.time_add_10(<BusinessDay>)
+   14.19μs    15.70μs      1.11  offset.OffestDatetimeArithmetic.time_subtract(<MonthBegin>)
+   13.72μs    15.16μs      1.11  offset.OffestDatetimeArithmetic.time_add_10(<MonthEnd>)
+  127.38μs   140.62μs      1.10  offset.OffestDatetimeArithmetic.time_add_10(<CustomBusinessMonthBegin>)
+   13.77μs    15.20μs      1.10  offset.OffestDatetimeArithmetic.time_subtract(<BusinessMonthEnd>)
-   17.66μs    15.89μs      0.90  offset.OffestDatetimeArithmetic.time_subtract_10(<MonthEnd>)
-    4.07ms     3.66ms      0.90  timeseries.ToDatetimeISO8601.time_iso8601_nosep
-   25.01μs    22.41μs      0.90  offset.OffestDatetimeArithmetic.time_subtract_10(<Day>)
-   11.44μs    10.22μs      0.89  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<MonthEnd>)
-   18.64μs    16.19μs      0.87  timeseries.AsOf.time_asof_single('Series')
-   92.96ms    77.71ms      0.84  timeseries.Factorize.time_factorize(None)
-   23.06μs    19.02μs      0.83  offset.OffestDatetimeArithmetic.time_subtract_10(<BusinessYearEnd: month=12>)
-   13.05μs    10.37μs      0.79  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<YearBegin: month=1>)
-   23.95μs    14.14μs      0.59  offset.OffestDatetimeArithmetic.time_add(<MonthBegin>)
-  444.49μs   260.00μs      0.58  offset.OffsetDatetimeIndexArithmetic.time_add_offset(<BusinessYearEnd: month=12>)
-    4.31ms     2.46ms      0.57  timeseries.ToDatetimeCache.time_unique_seconds_and_unit(False)
-   21.43μs    11.69μs      0.55  offset.OffestDatetimeArithmetic.time_apply(<BusinessDay>)

asv continuous -E virtualenv -f 1.1 master HEAD -b offset -b timeseries
[...]
    before     after       ratio
  [d3f7d2a6] [fe7a7187]
+   16.58μs    26.15μs      1.58  offset.OffestDatetimeArithmetic.time_subtract(<BusinessQuarterEnd: startingMonth=3>)
+    9.75μs    14.73μs      1.51  offset.OffestDatetimeArithmetic.time_apply(<DateOffset: days=2, months=2>)
+   12.16μs    18.11μs      1.49  offset.OffestDatetimeArithmetic.time_add(<DateOffset: days=2, months=2>)
+   12.21μs    17.69μs      1.45  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<DateOffset: days=2, months=2>)
+   28.97μs    40.89μs      1.41  offset.OffestDatetimeArithmetic.time_subtract(<DateOffset: days=2, months=2>)
+    1.63ms     2.25ms      1.38  timeseries.ResampleSeries.time_resample('datetime', '1D', 'mean')
+   14.71μs    20.02μs      1.36  offset.OffestDatetimeArithmetic.time_subtract(<BusinessYearBegin: month=1>)
+   14.63μs    19.70μs      1.35  offset.OffestDatetimeArithmetic.time_subtract(<BusinessMonthBegin>)
+   19.52μs    26.26μs      1.35  offset.OffestDatetimeArithmetic.time_add(<CustomBusinessDay>)
+   22.16ms    29.79ms      1.34  offset.OffsetSeriesArithmetic.time_add_offset(<CustomBusinessDay>)
+   20.69ms    26.91ms      1.30  timeseries.IrregularOps.time_add
+   16.77μs    20.77μs      1.24  offset.OffestDatetimeArithmetic.time_subtract(<SemiMonthEnd: day_of_month=15>)
+   15.76μs    19.40μs      1.23  offset.OffestDatetimeArithmetic.time_subtract_10(<MonthBegin>)
+   17.31μs    21.15μs      1.22  offset.OffestDatetimeArithmetic.time_subtract_10(<QuarterBegin: startingMonth=3>)
+   15.31μs    18.65μs      1.22  offset.OffestDatetimeArithmetic.time_subtract(<BusinessQuarterBegin: startingMonth=3>)
+   14.71μs    17.75μs      1.21  offset.OffestDatetimeArithmetic.time_add_10(<YearBegin: month=1>)
+   15.88μs    19.10μs      1.20  offset.OffestDatetimeArithmetic.time_subtract(<BusinessDay>)
+    6.38ms     7.55ms      1.18  timeseries.AsOf.time_asof('DataFrame')
+   16.25μs    18.97μs      1.17  offset.OffestDatetimeArithmetic.time_subtract_10(<BusinessQuarterEnd: startingMonth=3>)
+   66.50μs    76.79μs      1.15  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<CustomBusinessMonthEnd>)
+   19.02μs    21.70μs      1.14  offset.OffestDatetimeArithmetic.time_add(<Day>)
+   13.95μs    15.83μs      1.13  offset.OffestDatetimeArithmetic.time_subtract(<MonthEnd>)
+   18.43μs    20.88μs      1.13  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<Day>)
+   64.88μs    72.92μs      1.12  offset.OffestDatetimeArithmetic.time_add_10(<DateOffset: days=2, months=2>)
+   12.91μs    14.43μs      1.12  offset.OffestDatetimeArithmetic.time_add(<QuarterEnd: startingMonth=3>)
+   15.23μs    16.99μs      1.12  offset.OffestDatetimeArithmetic.time_add_10(<BusinessDay>)
+   13.70μs    15.24μs      1.11  offset.OffestDatetimeArithmetic.time_add_10(<YearEnd: month=12>)
+  131.58μs   145.99μs      1.11  offset.OffestDatetimeArithmetic.time_subtract_10(<DateOffset: days=2, months=2>)
+   11.07μs    12.26μs      1.11  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<BusinessQuarterBegin: startingMonth=3>)
+   11.14μs    12.34μs      1.11  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<MonthBegin>)
+   11.60μs    12.84μs      1.11  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<BusinessMonthEnd>)
+    2.44ms     2.70ms      1.11  timeseries.DatetimeIndex.time_unique('tz_naive')
+   15.79μs    17.46μs      1.11  offset.OffestDatetimeArithmetic.time_subtract_10(<BusinessMonthEnd>)
+   21.47μs    23.70μs      1.10  offset.OffestDatetimeArithmetic.time_subtract(<Day>)
+   10.57μs    11.64μs      1.10  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<BusinessMonthBegin>)
+    2.98μs     3.28μs      1.10  timeseries.DatetimeIndex.time_get('repeated')
-   10.04μs     9.07μs      0.90  offset.OffestDatetimeArithmetic.time_apply(<BusinessMonthBegin>)
-   12.54μs    11.29μs      0.90  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<YearEnd: month=12>)
-   10.30μs     9.25μs      0.90  offset.OffestDatetimeArithmetic.time_apply(<QuarterBegin: startingMonth=3>)
-   16.50μs    14.67μs      0.89  offset.OffestDatetimeArithmetic.time_add_10(<QuarterEnd: startingMonth=3>)
-    8.11ms     6.98ms      0.86  timeseries.Factorize.time_factorize(None)
-    7.85ms     6.72ms      0.86  timeseries.Factorize.time_factorize('Asia/Tokyo')
-   20.75μs    13.16μs      0.63  offset.OffestDatetimeArithmetic.time_add(<MonthEnd>)
-    2.00ms     1.21ms      0.60  timeseries.ResampleDataFrame.time_method('mean')
-    3.99ms     2.34ms      0.59  timeseries.ToDatetimeCache.time_dup_string_dates(True)
-   19.81μs    11.38μs      0.57  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<BusinessYearBegin: month=1>)
-   30.71μs    12.91μs      0.42  offset.OffestDatetimeArithmetic.time_add(<BusinessQuarterEnd: startingMonth=3>)

asv continuous -E virtualenv -f 1.1 master HEAD -b offset -b timeseries
[...]
    before     after       ratio
  [d3f7d2a6] [fe7a7187]
+   13.89μs    26.44μs      1.90  offset.OffestDatetimeArithmetic.time_add(<BusinessMonthEnd>)
+    9.67μs    15.55μs      1.61  offset.OffestDatetimeArithmetic.time_apply(<DateOffset: days=2, months=2>)
+   11.64μs    17.55μs      1.51  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<DateOffset: days=2, months=2>)
+   12.28μs    17.62μs      1.43  offset.OffestDatetimeArithmetic.time_add(<DateOffset: days=2, months=2>)
+   30.04μs    40.47μs      1.35  offset.OffestDatetimeArithmetic.time_subtract(<DateOffset: days=2, months=2>)
+   14.31μs    17.84μs      1.25  offset.OffestDatetimeArithmetic.time_subtract(<YearBegin: month=1>)
+   14.24μs    17.55μs      1.23  offset.OffestDatetimeArithmetic.time_add_10(<QuarterBegin: startingMonth=3>)
+   16.80μs    20.62μs      1.23  offset.OffestDatetimeArithmetic.time_add_10(<SemiMonthEnd: day_of_month=15>)
+   15.42μs    18.40μs      1.19  offset.OffestDatetimeArithmetic.time_subtract_10(<MonthBegin>)
+   61.16μs    72.26μs      1.18  offset.OffestDatetimeArithmetic.time_add_10(<DateOffset: days=2, months=2>)
+   14.30μs    16.82μs      1.18  offset.OffestDatetimeArithmetic.time_add_10(<BusinessQuarterEnd: startingMonth=3>)
+   14.67μs    17.24μs      1.18  offset.OffestDatetimeArithmetic.time_add_10(<QuarterEnd: startingMonth=3>)
+    9.54μs    11.21μs      1.17  offset.OffestDatetimeArithmetic.time_apply(<QuarterEnd: startingMonth=3>)
+   17.11μs    20.00μs      1.17  offset.OffestDatetimeArithmetic.time_subtract_10(<QuarterBegin: startingMonth=3>)
+   15.54μs    18.01μs      1.16  offset.OffestDatetimeArithmetic.time_apply(<CustomBusinessDay>)
+   10.34μs    11.95μs      1.16  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<MonthEnd>)
+  123.20μs   141.04μs      1.14  offset.OffestDatetimeArithmetic.time_subtract_10(<DateOffset: days=2, months=2>)
+   13.93μs    15.85μs      1.14  offset.OffestDatetimeArithmetic.time_add_10(<YearBegin: month=1>)
+   11.39μs    12.85μs      1.13  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<YearEnd: month=12>)
+   16.79μs    18.84μs      1.12  offset.OffestDatetimeArithmetic.time_subtract_10(<QuarterEnd: startingMonth=3>)
+    2.35ms     2.64ms      1.12  timeseries.DatetimeIndex.time_unique('tz_naive')
+    4.16μs     4.67μs      1.12  timeseries.DatetimeIndex.time_get('dst')
+    6.03μs     6.73μs      1.12  timeseries.DatetimeIndex.time_get('tz_aware')
+   16.77μs    18.74μs      1.12  offset.OffestDatetimeArithmetic.time_add_10(<BusinessDay>)
+   10.47μs    11.69μs      1.12  offset.OffestDatetimeArithmetic.time_apply(<BusinessDay>)
+   12.36μs    13.67μs      1.11  offset.OffestDatetimeArithmetic.time_add(<YearBegin: month=1>)
+    9.49μs    10.49μs      1.11  offset.OffestDatetimeArithmetic.time_apply(<BusinessQuarterEnd: startingMonth=3>)
+  105.28μs   116.31μs      1.10  offset.OffestDatetimeArithmetic.time_apply(<CustomBusinessMonthBegin>)
+   18.86μs    20.84μs      1.10  offset.OffestDatetimeArithmetic.time_subtract_10(<SemiMonthEnd: day_of_month=15>)
+   14.58μs    16.07μs      1.10  offset.OffestDatetimeArithmetic.time_subtract(<MonthBegin>)
-    4.33ms     3.93ms      0.91  offset.OnOffset.time_on_offset(<CustomBusinessMonthBegin>)
-    2.30ms     2.05ms      0.89  timeseries.ResampleSeries.time_resample('datetime', '1D', 'ohlc')
-  148.28ms   131.47ms      0.89  timeseries.DatetimeIndex.time_to_pydatetime('tz_aware')
-   10.14μs     8.93μs      0.88  offset.OffestDatetimeArithmetic.time_apply(<MonthEnd>)
-   13.64μs    11.91μs      0.87  offset.OffestDatetimeArithmetic.time_apply_np_dt64(<SemiMonthBegin: day_of_month=15>)
-   32.12μs    27.72μs      0.86  offset.OffestDatetimeArithmetic.time_add_10(<CustomBusinessDay>)
-   16.82μs    13.94μs      0.83  offset.OffestDatetimeArithmetic.time_add_10(<MonthEnd>)
-    3.27μs     2.59μs      0.79  timeseries.DatetimeIndex.time_get('repeated')
-  313.89μs   235.57μs      0.75  offset.OffsetDatetimeIndexArithmetic.time_add_offset(<QuarterEnd: startingMonth=3>)
-   23.48μs    15.20μs      0.65  offset.OffestDatetimeArithmetic.time_add(<BusinessYearEnd: month=12>)
-    3.96ms     2.55ms      0.64  timeseries.ResampleSeries.time_resample('period', '5min', 'ohlc')
-   23.80μs    13.81μs      0.58  offset.OffestDatetimeArithmetic.time_add(<BusinessDay>)
-    3.13ms     1.45ms      0.46  timeseries.ToDatetimeCache.time_dup_string_dates(False)

@property
def kwds(self):
# for backwards-compatibility
kwds = {name: getattr(self, name, None) for name in self._attributes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In particular DateOffset has a lot of _attributes that may not get set unless specifically passed.

@@ -218,7 +218,7 @@ def test_offset_freqstr(self, offset_types):

freqstr = offset.freqstr
if freqstr not in ('<Easter>',
"<DateOffset: kwds={'days': 1}>",
"<DateOffset: days=1>",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need a whatsnew note, explainig that the repr changed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did the repr change break anything? can you add some tests for this (doesn't have to be comprehensive, but some basic ones is ok)


self._offset, self._use_relativedelta = _determine_offset(kwds)
for name in kwds:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can do
self.__dict__.update(kwds)

@@ -284,7 +288,7 @@ def isAnchored(self):
return (self.n == 1)

def _params(self):
all_paras = dict(list(vars(self).items()) + list(self.kwds.items()))
all_paras = vars(self)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use self.__dict__ (as we do below) rather than vars

if 'offset' in state:
# Older versions have offset attribute instead of _offset
if '_offset' in state: # pragma: no cover
raise ValueError('Unexpected key `_offset`')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this an assert

def __setstate__(self, state):
"""Reconstruct an instance from a pickled state"""
if 'offset' in state:
# Older versions have offset attribute instead of _offset
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you put a version note here (so late we can fix this)

offset = state['_offset']
odict = offset.__dict__
kwds = {key: odict[key] for key in odict if odict[key]}
state.update(kwds)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just state.update(odict)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we don't want to pull in all of the unused relativedelta attributes.

@jreback jreback added the Frequency DateOffsets label Jan 26, 2018
@codecov
Copy link

codecov bot commented Jan 27, 2018

Codecov Report

Merging #19403 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #19403      +/-   ##
==========================================
- Coverage   91.67%   91.67%   -0.01%     
==========================================
  Files         148      148              
  Lines       48553    48554       +1     
==========================================
  Hits        44513    44513              
- Misses       4040     4041       +1
Flag Coverage Δ
#multiple 90.04% <100%> (-0.01%) ⬇️
#single 41.71% <70%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/tseries/offsets.py 97% <100%> (-0.09%) ⬇️
pandas/core/indexes/datetimes.py 95.25% <100%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 35812ea...53c251f. Read the comment docs.

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. just the question on repr tests.

@@ -218,7 +218,7 @@ def test_offset_freqstr(self, offset_types):

freqstr = offset.freqstr
if freqstr not in ('<Easter>',
"<DateOffset: kwds={'days': 1}>",
"<DateOffset: days=1>",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did the repr change break anything? can you add some tests for this (doesn't have to be comprehensive, but some basic ones is ok)

@jbrockmendel
Copy link
Member Author

did the repr change break anything? can you add some tests for this (doesn't have to be comprehensive, but some basic ones is ok)

Well it broke that one test. Did you have something else in mind?

@jreback jreback added this to the 0.23.0 milestone Feb 1, 2018
@jreback
Copy link
Contributor

jreback commented Feb 1, 2018

looks fine. can you rebase and ping on green (just to make sure)

@jbrockmendel
Copy link
Member Author

ping

@jreback jreback merged commit 601b8c9 into pandas-dev:master Feb 2, 2018
@jreback
Copy link
Contributor

jreback commented Feb 2, 2018

thanks!

@jbrockmendel jbrockmendel deleted the attr_dict branch February 4, 2018 16:42
harisbal pushed a commit to harisbal/pandas that referenced this pull request Feb 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Frequency DateOffsets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants