Skip to content

Bug in date_range with semi-open interval and freq='B'? #6673

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
dhirschfeld opened this issue Mar 20, 2014 · 5 comments
Closed

Bug in date_range with semi-open interval and freq='B'? #6673

dhirschfeld opened this issue Mar 20, 2014 · 5 comments
Labels
API Design Datetime Datetime data dtype Frequency DateOffsets good first issue Testing pandas testing functions or related to the test suite
Milestone

Comments

@dhirschfeld
Copy link
Contributor

#5637 has some examples as well

When the end date in date_range is not a valid business day it appears that date_range first sets it to a valid date before deciding whether to return the last date depending on whether the interval is closed or open on the right. This results in the date range being incorrectly truncated when the interval is open-right - e.g.

In [22]: for d in pd.date_range('20-Mar-2014', '23-Mar-2014', freq='D'):
    ...:     print d.strftime('%a %d-%b-%Y')
    ...:     
Thu 20-Mar-2014
Fri 21-Mar-2014
Sat 22-Mar-2014
Sun 23-Mar-2014

In [23]: pd.date_range('20-Mar-2014', '23-Mar-2014', freq='B')
Out[23]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2014-03-20, 2014-03-21]
Length: 2, Freq: B, Timezone: None

In [24]: # should return all valid business days <= '23-Mar-2014'
    ...: pd.date_range('20-Mar-2014', '23-Mar-2014', freq='B', closed='left')
<class 'pandas.tseries.index.DatetimeIndex'>
[2014-03-20]
Length: 1, Freq: B, Timezone: None
@jreback
Copy link
Contributor

jreback commented Mar 20, 2014

related / dupe of #5637

See the comment here, I think this is somewhat arbitrary because it first needs to move to a valid business day.
https://github.com/pydata/pandas/blob/master/pandas/tseries/offsets.py#L69

I think this should be more deterministic. If you can come up with some 'rules' then I think could be straightforward.

@jreback jreback added this to the 0.14.0 milestone Mar 20, 2014
@jreback jreback changed the title Bug in date_range with semi-open interval and freq='B'? Bug in date_range with semi-open interval and freq='B'? Mar 20, 2014
@jreback jreback modified the milestones: 0.15.0, 0.14.0 Apr 6, 2014
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 3, 2015
@mroeschke
Copy link
Member

This looks fixed on master. Might need a test to confirm this behavior

@mroeschke mroeschke added Testing pandas testing functions or related to the test suite good first issue labels Jul 6, 2018
@mroeschke mroeschke modified the milestones: Contributions Welcome, 0.24.0 Jul 6, 2018
@louis-red
Copy link
Contributor

I am willing to add a test in a PR for my first issue !

@dhirschfeld
Copy link
Contributor Author

It's fair to say this one fell off my radar!

Confirmed that it works on master:
image

I'll let you add the test @JacquotLeHaricot - thanks! Just make sure to reference this issue from a comment in your PR so that they're linked

@jreback
Copy link
Contributor

jreback commented Jul 31, 2018

closed by #22095

@jreback jreback closed this as completed Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Datetime Datetime data dtype Frequency DateOffsets good first issue Testing pandas testing functions or related to the test suite
Projects
None yet
Development

No branches or pull requests

4 participants