BUG: record warnings related to DatetimeIndex
State: closed

- [ ] closes #xxxx
- [ ] tests added / passed
- [ ] passes `black pandas`
- [ ] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry

This PR handles warnings emitted when running tests in ``pandas/tests/plotting/test_datetimelike.py``.
Warnings looked like this:

```
pandas/tests/plotting/test_datetimelike.py::TestTSPlot::test_irreg_dtypes
  /workspaces/pandas/pandas/core/frame.py:3216: FutureWarning: Automatically casting object-dtype Index of datetimes to DatetimeIndex is deprecated and will be removed in a future version.  Explicitly cast to DatetimeIndex instead.
    return klass(values, index=self.index, name=name, fastpath=True)
```

Presumably it started after implementing this: https://github.com/pandas-dev/pandas/pull/36697/

The reason for not using ``tm.assert_produces_warning`` is that when I use it,
then I get an error that the warning is raised with the incorrect stacklevel.

Labels:
name: Datetime
description: Datetime data dtype
name: Visualization
description: plotting

Comments:
thanks @ivanovmg 
I am not fully sure this is the correct way to deal with those warnings. 

So the warnings can be reproduced with this snippet:

```
idx = pd.date_range("2012-6-22 21:59:51", freq="S", periods=100)
df = pd.DataFrame(np.random.randn(len(idx), 2), index=idx)
df.index = df.index.astype(object)

df.plot(ax=ax)
```

In this case, the user is not doing any conversion of the index themselves, so at best the warning is quite confusing. 

Further, the question is if the behaviour will actually change once we enforce the deprecation. Because if not, then the warning is also useless (it's not warning about something that will change). 
Based on a quick check (running the snippet above with master vs with the the code in `_set_axis` related to the warning commented out), I don't think there is actually any change in behaviour.
> I am not fully sure this is the correct way to deal with those warnings. 
> 
> 
> 
> So the warnings can be reproduced with this snippet:
> 
> 
> 
> ```
> 
> idx = pd.date_range("2012-6-22 21:59:51", freq="S", periods=100)
> 
> df = pd.DataFrame(np.random.randn(len(idx), 2), index=idx)
> 
> df.index = df.index.astype(object)
> 
> 
> 
> df.plot(ax=ax)
> 
> ```
> 
> 
> 
> In this case, the user is not doing any conversion of the index themselves, so at best the warning is quite confusing. 
> 
> 
> 
> Further, the question is if the behaviour will actually change once we enforce the deprecation. Because if not, then the warning is also useless (it's not warning about something that will change). 
> 
> Based on a quick check (running the snippet above with master vs with the the code in `_set_axis` related to the warning commented out), I don't think there is actually any change in behaviour.

there is an explicit astype here
so this is just testing that the user is getting the warning which AFACTA is correct
> there is an explicit astype here

The warning is not coming from there, but from the plot() call.

So yes it is plotting a dataframe with an object-dtype index. But 1) the warning is not clear about that and 2) we actually support plotting object dtype values, so there shouldn't necessarily be a warning at all.
ok i guess - why don't u open a new issue

this was just testing that we get a warning