DEPR: Deprecate week, weekofyear in Series.dt,DatetimeIndex
State: closed

Closes https://github.com/pandas-dev/pandas/issues/33503

This PR is a followup to #33220 and implements what was discussed there.

A few comments:

- `DatetimeIndex.isocalendar` does not set the index on the returned dataframe,
  leading to some cumbersome syntax.  This may be worth changing, please let me
  know what you think.
- Should we also deprecate `Timestamp.week/weekofyear`?

- [ ] closes #xxxx
- [ ] tests added / passed
- [ ] passes `black pandas`
- [ ] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry

Labels:
name: Datetime
description: Datetime data dtype
name: Deprecate
description: Functionality to remove in pandas

Comments:
> DatetimeIndex.isocalendar does not set the index on the returned dataframe,
leading to some cumbersome syntax. This may be worth changing, please let me
know what you think.

hmm you mean the index of the original dataframe? I *think* we do this on the accessors, so we *should* do this.
> DatetimeIndex.isocalendar does not set the index on the returned dataframe,
leading to some cumbersome syntax

agreed
> hmm you mean the index of the original dataframe? I think we do this on the accessors, so we should do this.

Yes, I mean that the DataFrame returned by DatetimeIndex.isocalendar() should probably have its index set to the DatetimeIndex.  This is done e.g. in Series.dt.isocalendar(): the returned DataFrame has it's index set to that of the Series.

For Index classes, the [current behavior](https://github.com/pandas-dev/pandas/blob/3a5ae505bcec7541a282114a89533c01a49044c0/pandas/core/indexes/extension.py#L60) of `inherit_names` when wrapping is to *convert* the result of the delegated call to the same *type* if possible (i.e. DatetimeIndex => DatetimeIndex) and to fall back to a generic Index if not.


> > DatetimeIndex.isocalendar does not set the index on the returned dataframe,
> > leading to some cumbersome syntax
> > 
> 
> agreed

Ok, the question would then be where to do this:

- It can be done in `inherit_names`, but the code [there](https://github.com/pandas-dev/pandas/blob/3a5ae505bcec7541a282114a89533c01a49044c0/pandas/core/indexes/extension.py#L60) would need to be adapted to handle a DataFrame (or something more generic?) and this is currently the only case for that.  
- Or the delegation can be done "manually" in an explicitly defined`DatetimeIndex.isocalendar` method.

Build failing due to numba version.  Will wait for #33686 or patch from @mroeschke 
@jbrockmendel @jreback 
Sorry for the delay, I believe all open comments have been addressed.  Tests green.

Regarding the setting of the index, I would like to do that in a separate PR if there are no objections.




@mroeschke @jreback @jbrockmendel Just checking in here to see if anything else needs to be done re discussion/PR?  Thanks!
@mroeschke @jreback I would like to ping one more time, to try to keep this from getting too stale.  If more discussion needs to be add about this, I'm totally fine with that, but I would like to also address the two issues that came up in the PR here.  If this needs more time to merge, then I would go ahead and address those already.
Sorry for the delay @mgmarino. I think everything looked good to me a while back. Looks like there's a merge conflict, but once that's resolved I think this should be good
 
yeah this is ok, ping on green. @jorisvandenbossche unless any objections here.
Build failure due to a version bump of flake in the CI (now 3.8.1, last succeeded with 3.7.9), see #34150.  
@jreback back to green
this lgtm. we can merge on green.
Thanks for sticking with this @mgmarino. Great PR as always!