Skip to content

Follow-Up: Unify apply and onOffset implementations #18329

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

Merged
merged 9 commits into from
Nov 19, 2017

Conversation

jbrockmendel
Copy link
Member

This follows up on #18280, #18278, and #18263.

get_day_of_month is extended to handle business_start and business_end in addition to start and end.

_day_opt attributes are added to YearFoo, QuarterFoo, and MonthFoo offsets. After some more algebraic simplification (done in a separate PR), their apply and onOffset methods will become identical and can be implemented in the base Year, Quarter, and Month classes.

I expect a small performance penalty from calling self._get_offset_day in cases where could hard-code 1, but the benefits of a unified+simplified implementation outweigh that.

@codecov
Copy link

codecov bot commented Nov 16, 2017

Codecov Report

Merging #18329 into master will decrease coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #18329      +/-   ##
==========================================
- Coverage   91.38%   91.36%   -0.02%     
==========================================
  Files         164      164              
  Lines       49780    49786       +6     
==========================================
- Hits        45491    45488       -3     
- Misses       4289     4298       +9
Flag Coverage Δ
#multiple 89.16% <100%> (ø) ⬆️
#single 39.52% <24.56%> (-0.04%) ⬇️
Impacted Files Coverage Δ
pandas/tseries/offsets.py 96.92% <100%> (+0.01%) ⬆️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.8% <0%> (-0.1%) ⬇️

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 a26b676...30991ba. Read the comment docs.

@codecov
Copy link

codecov bot commented Nov 16, 2017

Codecov Report

Merging #18329 into master will decrease coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #18329      +/-   ##
==========================================
- Coverage   91.38%   91.34%   -0.05%     
==========================================
  Files         164      164              
  Lines       49790    49796       +6     
==========================================
- Hits        45501    45486      -15     
- Misses       4289     4310      +21
Flag Coverage Δ
#multiple 89.14% <100%> (-0.03%) ⬇️
#single 39.55% <27.11%> (-0.04%) ⬇️
Impacted Files Coverage Δ
pandas/tseries/offsets.py 96.92% <100%> (+0.01%) ⬆️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/plotting/_converter.py 63.44% <0%> (-1.82%) ⬇️
pandas/core/frame.py 97.8% <0%> (-0.1%) ⬇️

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 f724066...1f3c76e. Read the comment docs.

@@ -394,6 +394,10 @@ class _BaseOffset(object):
out = '<%s' % n_str + className + plural + self._repr_attrs() + '>'
return out

def _get_offset_day(self, datetime other):
# subclass must implement `_day_opt`
Copy link
Contributor

Choose a reason for hiding this comment

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

so in the Base class add a NotImplementedError for this

@jreback jreback added the Frequency DateOffsets label Nov 17, 2017
else:
# Note: unlike `shift_month`, get_day_of_month does not
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 add a test with a sub-class of BaseOffset (e.g. a dummy class) that checks this

@jbrockmendel
Copy link
Member Author

Appveyor error looks like floating point error in an unrelated test. Will push dummy commit in a bit.

@jreback
Copy link
Contributor

jreback commented Nov 19, 2017

can you rebase

@jreback
Copy link
Contributor

jreback commented Nov 19, 2017

looks fine. can you run the offset asvs & report

I expect a small performance penalty

is?

@jreback jreback added the Clean label Nov 19, 2017
@jbrockmendel
Copy link
Member Author

Pretty tame by local standards:

taskset 7 asv continuous -f 1.1 -E virtualenv master HEAD -b timeseries -b period
[...]
     [6405919e]       [1f3c76e9]
+        1.67±0ms      1.95±0.09ms     1.17  timeseries.DatetimeIndex.time_add_offset_delta
+      70.4±0.4μs         80.2±2μs     1.14  period.Properties.time_start_time
+     14.9±0.04ms       16.9±0.2ms     1.14  timeseries.Iteration.time_iter_periodindex_preexit
+       128±0.5μs        141±0.4μs     1.10  timeseries.Offsets.time_custom_bmonthbegin_incr_n
-         817±1ns          737±4ns     0.90  period.Properties.time_year
-      27.9±0.2μs       25.0±0.3μs     0.90  timeseries.Offsets.time_custom_bday_cal_incr
-     1.59±0.09ms      1.40±0.04ms     0.88  timeseries.ToDatetime.time_cache_false_with_dup_string_dates_and_format
-      21.9±0.3μs      19.0±0.04μs     0.87  timeseries.Offsets.time_timeseries_day_incr
-      21.8±0.1μs      18.5±0.08μs     0.85  timeseries.Offsets.time_custom_bday_incr
-        876±20ns        733±0.7ns     0.84  period.Properties.time_hour
-           16.6s            13.9s     0.83  gil.nogil_datetime_fields.time_datetime_to_period
-      14.5±0.4μs      12.0±0.04μs     0.83  timeseries.SemiMonthOffset.time_begin_apply

taskset 7 asv continuous -f 1.1 -E virtualenv master HEAD -b timeseries -b period
[...]
       before           after         ratio
     [6405919e]       [1f3c76e9]
+        6.79±0μs      7.79±0.01μs     1.15  timeseries.DatetimeIndex.time_timestamp_tzinfo_cons
+      6.51±0.1ms       7.34±0.1ms     1.13  timeseries.DatetimeIndex.time_dti_factorize
-     20.9±0.08μs      18.8±0.09μs     0.90  timeseries.Offsets.time_custom_bday_incr
-        844±10ns          752±5ns     0.89  period.Properties.time_week
-        79.6±2ms       70.8±0.2ms     0.89  timeseries.ToDatetime.time_cache_false_with_dup_string_tzoffset_dates
-        858±20ns          735±3ns     0.86  period.Properties.time_day
-      33.2±0.7μs      27.3±0.07μs     0.82  timeseries.Offsets.time_custom_bday_decr
-           46.6s            37.7s     0.81  gil.nogil_datetime_fields.time_period_to_datetime

@jbrockmendel
Copy link
Member Author

One more:

     before           after         ratio
     [6405919e]       [1f3c76e9]
+        748±10ns          870±3ns     1.16  period.PeriodProperties.time_month
+      7.26±0.2ms       8.36±0.2ms     1.15  timeseries.DatetimeIndex.time_dti_tz_factorize
-         824±5ns          738±6ns     0.90  period.Properties.time_month
-         117±3μs        104±0.1μs     0.89  timeseries.Offsets.time_custom_bmonthend_decr_n
-        18.2±1μs      16.2±0.04μs     0.89  timeseries.SemiMonthOffset.time_end_incr
-     7.76±0.05μs      6.86±0.02μs     0.88  timeseries.DatetimeIndex.time_timestamp_tzinfo_cons
-         156±4ms          138±2ms     0.88  timeseries.ToDatetime.time_iso8601_tz_spaceformat
-      20.9±0.4μs       18.1±0.1μs     0.86  timeseries.Offsets.time_custom_bday_incr
-      33.2±0.6μs       27.8±0.2μs     0.84  timeseries.Offsets.time_custom_bday_decr

@jreback jreback added this to the 0.22.0 milestone Nov 19, 2017
@jreback jreback merged commit c868423 into pandas-dev:master Nov 19, 2017
@jreback
Copy link
Contributor

jreback commented Nov 19, 2017

thanks!

@@ -357,6 +357,7 @@ class _BaseOffset(object):
_typ = "dateoffset"
_normalize_cache = True
Copy link
Contributor

Choose a reason for hiding this comment

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

in a followup (TODO), can you add a description of these attributes in the doc-string of this class. (e.g. what the options are, what they do, etc).

@jbrockmendel jbrockmendel deleted the tslibs-offsets-followup branch December 8, 2017 19:38
@jbrockmendel jbrockmendel mentioned this pull request Dec 19, 2017
39 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants