-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Can't use dt.ceil, dt.floor, dt.round with coarser target frequencies #15303
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
Comments
Here is an alternative and probably more correct.
The issue is rounding is pretty tricky and I would argue unexpected for Months. You can easily have round up on the 15th for some months and down for others. You could argue that If you want to implement something reasonable would be fine. (you could prob just do the |
Taking a look at this: if the date is While I wrote this issue for My patch currently affects the
There is a very similar |
This is how you work with dti/Series; its very similar.
|
(got motivated to come back to this issue as I hit it again...) Thanks @jreback - I am very close now. Only issue is that adding the offset isn't idempotent/doesn't handle the exact boundary properly. That is, in the single
|
If you just want to roll forward then |
I'm interested in this still, I can't find a reasonable way to snap a datetime to a week beginning the best I can do is:
.floor used to work for 'W-SUN' |
This worked for me :)
|
It is so surprising that this ticket has been opened in 2017 and has not been fixed in 4 years. It is very obvious that this is due to incompetent programming nature when it comes to grouping dates into different buckets. As I mentioned in #43093, the internal logic inconsistency of Pandas will only make these kinds of defects harder to rectify. If grouping by years or months cannot be done easily, I have no objection. This is because one year has ~365.2425 days, as a result, the number of days in a year and thus in a month cannot be determined in a straight-forward manner, you need to determine where are the leap years and leap months (especially every 4 years, except for years that are divisable by 100 and not divisable by 400 we got a leap year). However, the number of days in a week is always 7, this is not affected by leap year. Thus, this is something that can be easily calculated just using a simple MOD operation on the raw timestamp. Not sure why pd.Timestamp.floor('W') or W-SUN/W-MON/etc. still does not work until today. |
statements like this
will get you banned, pls follow the code-of-conduct. constructive criticisim and patches are welcome. |
@xuancong84 it's not the first time you make such comments:
So, please take the above as a final warning - thanks |
I do apologize that maybe my comments are a bit harsh for you guys. But why do I only make harsh kind of comments only in your repo, but not everyone else's repo? I hope you can focus more of your energy in solving those bugs rather than solving the people who complain about your bug. I will make no further harsh comments on Pandas repo in the future but on this issue, may I know which part of the source code needs to be changed in order to solve the bug? |
Code Sample
This works fine:
But this doesn't:
Problem description
I haven't done an exhaustive test, but it seems that one can't use coarser frequencies like 'M', 'Q', 'A' in the dt.ceil/floor/round set of methods.
Expected Output
It would seem reasonable to be able to take a series of scattered dates and be able to "coarsen" them into month-ends, quarter-ends, year-ends, etc.
Output of
pd.show_versions()
pandas: 0.19.0+300.g74e20a0.dirty
nose: 1.3.7
pip: 7.1.2
setuptools: 19.1.1
Cython: 0.23.4
numpy: 1.10.2
scipy: 0.16.1
statsmodels: None
xarray: None
IPython: 4.0.1
sphinx: 1.3.1
patsy: 0.4.0
dateutil: 2.4.2
pytz: 2016.4
blosc: None
bottleneck: 1.0.0
tables: 3.2.2
numexpr: 2.4.6
feather: None
matplotlib: 1.5.1
openpyxl: 2.3.2
xlrd: 0.9.4
xlwt: 1.0.0
xlsxwriter: 0.8.2
lxml: 3.5.0
bs4: None
html5lib: 0.999
httplib2: None
apiclient: None
sqlalchemy: 1.0.11
pymysql: 0.6.7.None
psycopg2: None
jinja2: 2.8
s3fs: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: