title: How to build custom pandas.tseries.offsets class?
body: <p>I want to find a way to build a custom <code>pandas.tseries.offsets</code> class at 1 second frequency for trading hours. The main requirement here is that  the time offset object would be smart enough to know the next second of '2015-06-18 16:00:00' would be '2015-06-19 09:30:00 or 09:30:01', and the time delta computed from these two time stamps would be exactly 1s (custom offset 1s, similar to <code>BDay(1)</code> for business day frequency) instead of the duration of closing hours.</p>
  
  <p>The reason is that when plotting the pd.Series for intraday data across a few trading days, see the simulated example below, there are lots of 'step line' (linear interpolation) between close and next day open prices to represent the time duration of closing hours. Is there a way to get rid of this? I've look at the source codes of <code>pandas.tseries.offsets</code> and find <code>pd.tseries.offsets.BusinessHour</code> and <code>pd.tseries.offsets.BusinessMixin</code> may help but I don't know how to use those. </p>
  
  <pre><code>import pandas as pd
  import numpy as np
  from pandas.tseries.holiday import USFederalHolidayCalendar
  from pandas.tseries.offsets import CustomBusinessDay
  
  # set as 'constant' object shared by all codes in this script
  BDAY_US = CustomBusinessDay(calender=USFederalHolidayCalendar())
  sample_freq = '5min'
  dates = pd.date_range(start='2015-01-01', end='2015-01-31', freq=BDAY_US).date
  # exculde the 09:30:00 as it is included in the first time bucket
  times = pd.date_range(start='09:30:00', end='16:00:00', freq=sample_freq).time[1:]
  time_stamps = [dt.datetime.combine(date, time) for date in dates for time in times]
  s = pd.Series(np.random.randn(len(time_stamps)).cumsum() + 100, index=time_stamps)
  
  s.plot()
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/cqiww.png" alt="enter image description here"></p>
  
  <p>Another way I can think of to partially fix this problem is to first <code>reset_index()</code> to get the default consecutive integer index for each row, and then calculating the difference between consecutive integer index as time(in seconds) elapsed. Plotting integer index as x-axis and then relabel them to appropriate time labels. Could someone show me how to do it with <code>matplotlib</code> as well? </p>
  
  <p>Thanks for Jeff's comments. I just check the on-line docs for <code>BusinessHour()</code> and find it may useful in my case. Another follow-up question(s): the <code>BusinessHour</code> is in hour frequency, is there a way to make it at 1s frequency? also, how to combine it with <code>CustomBusinessDay</code> object? </p>
  
  <p>To use <code>BusinessHour()</code></p>
  
  <pre><code>from pandas.tseries.offsets import *
  bhour = BusinessHour(start='09:30', end='16:00')
  time = pd.Timestamp('2015-06-18 15:00:00')
  print(time)
  2015-06-18 15:00:00
  # hourly increment works nicely
  print(time + bhour * 1)
  2015-06-19 09:30:00
  # but not at minute or second frequency
  print(time + Minute(61))
  2015-06-18 16:01:00
  print(time + Second(60*60 + 1))
  2015-06-18 16:00:01
  </code></pre>
  
  <p>Many many thanks, and any help would be highly appreciated.</p>