Skip to content

list of day-light savings days #26160

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

Closed
gmohandas opened this issue Apr 20, 2019 · 3 comments
Closed

list of day-light savings days #26160

gmohandas opened this issue Apr 20, 2019 · 3 comments
Labels
Datetime Datetime data dtype Enhancement

Comments

@gmohandas
Copy link

Would it be useful to add a feature that returns a list of days within a given time interval where the clock changes due to daylight savings? Personally, I've had occasion to find such days/dates as part of my work. I do not know of a one-shot way with which to do so in pandas at the moment. I'd be happy to contribute this functionality as an enhancement if there is some interest.

@gfyoung gfyoung added Enhancement Datetime Datetime data dtype labels Apr 20, 2019
@gfyoung
Copy link
Member

gfyoung commented Apr 20, 2019

cc @mroeschke

Not aware of a one-shot way either. As for your proposal, I'm uncertain of the degree of use that such functionality would get vs. the maintenance efforts involved.

If you do have an implementation, feel free to share it here though.

@gmohandas
Copy link
Author

@gfyoung I was wondering of possibly including a function like the one given below in pandas.core.indexes.datetimes. Not including all the necessary tests and accompaniments of course.

def get_dls_days(startdate, enddate):
   # array of all Sundays within the specified time interval.
    dran = pd.date_range(start=startdate, end=enddate, freq='W-SUN')

    # keep only the last Sunday falling in March and October
    dls_days = dran[(dran.month == 3) & (dran.day >= 25) |
                    (dran.month == 10) & (dran.day >= 25)]

    if not dls_days.size:
        print('No daylight saving days in the specified time interval.')
    else:
        return dls_days

To be honest, this was also my idea of making a first contribution to the pandas codebase (or to any major project for that matter). If it isn't worth the effort, never mind, but if it might be a nice extra feature, then I'd welcome any thoughts and suggestions.

@jreback
Copy link
Contributor

jreback commented Apr 20, 2019

see #22560; this method was rejected as not generally that useful for user facing operations as tz's are complicated. In any event it is pretty easy to generically do this (your method about is not very generic).

In [45]: idx = date_range('2018-01-01', '2018-12-31', freq='H', tz='US/Eastern')                                                                                                                                                                                 

In [46]: dst = idx.map(lambda x: x.dst())                                                                                                                                                                                                                      

In [47]: idx[1:][dst[1:]!=dst[:-1]]                                                                                                                                                                                                                            
Out[47]: DatetimeIndex(['2018-03-11 03:00:00-04:00', '2018-11-04 01:00:00-05:00'], dtype='datetime64[ns, US/Eastern]', freq=None)

@jreback jreback closed this as completed Apr 20, 2019
@jreback jreback added this to the No action milestone Apr 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Enhancement
Projects
None yet
Development

No branches or pull requests

3 participants