I was looking at the scipy cookbook implementation of the Savitzky-Golay algorithm:
#!python
def savitzky_golay(y, window_size, order, deriv=0, rate=1):
r\"\
Indeed, this logic isn't right, which can be best seen by considering the case of y[0] and y[-1] being 0. I believe the intent was to achieve odd reflection, so that the first derivative would be continuous at the reflection point. The correct form for that is
firstvals = 2*y[0] - y[1:half_window+1][::-1]
lastvals = 2*y[-1] - y[-half_window-1:-1][::-1]
or, combining reversing and slicing in one step,
firstvals = 2*y[0] - y[half_window:0:-1]
lastvals = 2*y[-1] - y[-2:-half_window-2:-1]
I should emphasize this is just some code contributed by a user. The actual Scipy implementation of Savitzky-Golay filter is entirely different.