Skip to content

BUG: BDay() offsetting not behaving as expected #38046

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
mhorsley30896 opened this issue Nov 24, 2020 · 6 comments · Fixed by #38324
Closed

BUG: BDay() offsetting not behaving as expected #38046

mhorsley30896 opened this issue Nov 24, 2020 · 6 comments · Fixed by #38324
Assignees
Labels
Frequency DateOffsets Needs Tests Unit test(s) needed to prevent regressions
Milestone

Comments

@mhorsley30896
Copy link

mhorsley30896 commented Nov 24, 2020

import pandas as pd
from pandas.tseries.offsets import CDay, BDay

idx = pd.bdate_range("2010/02/01","2010/02/15", freq='6H')

t1 = idx + BDay(offset=pd.Timedelta(3, unit='H'))

t2 = idx + CDay(offset=pd.Timedelta(3, unit='H'))

t1.equals(t2)

False

Problem description

BDay does not seem to be offsetting when a timedelta is supplied.

Expected Output

True

Output of pd.show_versions()

INSTALLED VERSIONS

commit : db08276
python : 3.6.12.final.0
python-bits : 64
OS : Linux
OS-release : 3.10.0-514.6.1.el7.x86_64
Version : #1 SMP Wed Jan 18 13:06:36 UTC 2017
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C
LOCALE : None.None

pandas : 1.1.3
numpy : 1.19.2
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.4
setuptools : 50.3.1.post20201107
Cython : 0.29.21
pytest : 6.1.1
hypothesis : None
sphinx : 3.2.1
blosc : None
feather : None
xlsxwriter : 1.3.7
lxml.etree : 4.6.1
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.16.1
pandas_datareader: 0.9.0
bs4 : 4.9.3
bottleneck : 1.3.2
fsspec : 0.8.3
fastparquet : None
gcsfs : None
matplotlib : 3.3.2
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.5
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.2
sqlalchemy : 1.3.20
tables : 3.6.1
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : 1.3.0
numba : 0.51.2

@mhorsley30896 mhorsley30896 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 24, 2020
@mhorsley30896 mhorsley30896 changed the title BUG: BUG: BDay() offsetting not behaving as expected Nov 24, 2020
@phofl
Copy link
Member

phofl commented Nov 24, 2020

Hi,

thanks for your report. This returns True on master

/home/developer/PycharmProjects/pandas/pandas/core/arrays/datetimes.py:700: PerformanceWarning: Non-vectorized DateOffset being applied to Series or DatetimeIndex
  warnings.warn(
True

Would you like to contribute a test for this to avoid regression?

@rhshadrach rhshadrach added Frequency DateOffsets Needs Tests Unit test(s) needed to prevent regressions and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 24, 2020
@rhshadrach rhshadrach added this to the Contributions Welcome milestone Nov 24, 2020
@rhshadrach rhshadrach removed the Bug label Nov 24, 2020
@mhorsley30896
Copy link
Author

mhorsley30896 commented Nov 25, 2020

Something like?

def test_bday_ignores_timedeltas():
    idx = pd.bdate_range("2010/02/01","2010/02/15", freq='6H')
    t1 = idx + BDay(offset=pd.Timedelta(3, unit='H'))
    t2 = idx + CDay(offset=pd.Timedelta(3, unit='H'))
    assert t1.equals(t2), 't1 should always equal t2 as behaviour of CDay and BDay equivalent with no calendar'
    pass

@phofl
Copy link
Member

phofl commented Nov 25, 2020

Yes essentially, it would be a bit better if you could define expected (t2) without calling a function

@theoniko
Copy link
Contributor

theoniko commented Dec 5, 2020

I tried the code snippet from mhorsley30896 with latest master (1.2.0.dev0+1469.g122ae441d) and it returned True. I have not worked in python but i will try to add the test above.

@theoniko
Copy link
Contributor

theoniko commented Dec 5, 2020

take

@theoniko
Copy link
Contributor

theoniko commented Dec 9, 2020

Hello @phofl
Could you please review pr #38324?

@jreback jreback modified the milestones: Contributions Welcome, 1.3 Dec 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Frequency DateOffsets Needs Tests Unit test(s) needed to prevent regressions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants