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
Timestamp.to_period() is off-by-one for weekly frequencies #20818
Comments
Hmm interesting. I think the issue is somewhere in the Period constructor (which to_period essentially uses) In [28]: from pandas import Period
In [29]: Period(pd.to_datetime('1/2/2018'), freq='W-MON')
Out[29]: Period('2018-01-02/2018-01-08', 'W-MON')
In [30]: Period(pd.to_datetime('1/2/2018'), freq='W-SUN')
Out[30]: Period('2018-01-01/2018-01-07', 'W-SUN') I didn't see a ton of test coverage for this frequency so it's possible something slipped through. cc @jorisvandenbossche for any input |
In case it helps, here's another example of
Edit: This will make the above behave as expected:
I figured this out by looking at the source for |
I believe we hit this same bug:
Result:
Expected:
|
Yesterday I was a happy man, because I learned about BUT: it seems that this is indeed expetected behaviour: see this snippet: pandas/pandas/_libs/tslibs/dtypes.pyx Lines 100 to 106 in dafa5dd
W-MON is "Weekly - Monday end of week", so this is not a bug but a documentation problem.
To have monday start of week one has to specify "W-SUN", i.e weekly sunday end of week, i.e. "W"
|
Code Sample
Problem description
I expect
W-MON
to produce aPeriod
that starts on Monday. But in my example, the beginning of thePeriod
is2018-01-02
, which is a Tuesday.Note that
pandas.date_range()
does produce the expected output:Expected Output
Period('2018-01-01/2018-01-07', 'W-MON')
Output of
pd.show_versions()
pandas: 0.22.0
pytest: None
pip: 9.0.1
setuptools: 39.0.1
Cython: 0.26
numpy: 1.14.2
scipy: 0.19.1
pyarrow: None
xarray: None
IPython: 5.5.0
sphinx: None
patsy: 0.4.1
dateutil: 2.7.2
pytz: 2018.4
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.1.1
openpyxl: None
xlrd: None
xlwt: 1.3.0
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.9999999
sqlalchemy: 1.2.0
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: