Open Queilow opened 4 months ago
Yes, I like it and imo good idea to bring with/before 1.0!
Date logic is a very common use case and as you said current design is a bit confusing
year
-> calendar year ✅ iso_year
-> iso year ✅ week
-> iso week 🤔iso_week
-> missing 😞
Description
Checks
Description
Currently
Series.dt.week()
returns the ISO 8601 definition of a week. Although this is a very consistent definition of a week, it could potentially lead users to accidentally pair it withdt.year()
instead ofdt.iso_year()
which can cause difficult to catch mistakes. For example:We can see both dates have the same (Gregorian year, isoweek) tuple despite being 12 months apart. I believe a
week
method compatible with Gregorian year is practical enough to be an explicit MethodProposal
dt.week()
to correspond with the%W
format from chrono'sstrftime
. This format is identical to ISO Week except all week 52/53 in January are turned to 0.dt.iso_week()
method to keep access to the current functionalityDiscussion
Pros:
(year, week)
, rather than(year, iso_year, iso_week)
currently (or create the column via string casting)(year, week)
or(iso_year, iso_week)
, and any situations where users are mix-matching the two formats are done consciously.%W
format is aligned with the currentdt.weekday()
method as well, as opposed to other week definition such as the one fromlubridate
in RCons:
dt.week()
DATEPART(date, 'week')
in SQLContext, currently both 'week' and 'isoweek' return isoweek format