BUG: fix mutation of DTI backing Series/DataFrame
State: closed

Fixes (at least some) verify_integrity bugs discussed in #24074.

- [x] closes #21907
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry


Labels:
name: Datetime
description: Datetime data dtype

Comments:
Hello @jbrockmendel! Thanks for submitting the PR.

 - There are no PEP8 issues in the file [`pandas/core/internals/blocks.py`](https://github.com/jbrockmendel/pandas/blob/03f4eb4e14111cdf1ee541a92bea0d65ef9659bc/pandas/core/internals/blocks.py) !

 - There are no PEP8 issues in the file [`pandas/tests/frame/test_block_internals.py`](https://github.com/jbrockmendel/pandas/blob/03f4eb4e14111cdf1ee541a92bea0d65ef9659bc/pandas/tests/frame/test_block_internals.py) !


Does this fix #6326 as well?
> Does this fix #6326 as well?

It looks like it does not.  This also breaks another copy/view-based test, which I'll need to look into.
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24096?src=pr&el=h1) Report
> Merging [#24096](https://codecov.io/gh/pandas-dev/pandas/pull/24096?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/1d3ed917638b9890e0410fa996a447c4a780429e?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/24096/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/24096?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #24096      +/-   ##
==========================================
+ Coverage   42.52%   42.52%   +<.01%     
==========================================
  Files         161      161              
  Lines       51697    51699       +2     
==========================================
+ Hits        21982    21986       +4     
+ Misses      29715    29713       -2
```

| Flag | Coverage Δ | |
|---|---|---|
| #single | `42.52% <100%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24096?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/internals/blocks.py](https://codecov.io/gh/pandas-dev/pandas/pull/24096/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW50ZXJuYWxzL2Jsb2Nrcy5weQ==) | `52.93% <100%> (+0.19%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24096?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24096?src=pr&el=footer). Last update [1d3ed91...841c4a5](https://codecov.io/gh/pandas-dev/pandas/pull/24096?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24096?src=pr&el=h1) Report
> Merging [#24096](https://codecov.io/gh/pandas-dev/pandas/pull/24096?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/9f2c7164ec581a484ee167c04478bf9e4f81426b?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/24096/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/24096?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #24096      +/-   ##
==========================================
- Coverage    92.2%    92.2%   -0.01%     
==========================================
  Files         162      162              
  Lines       51714    51719       +5     
==========================================
+ Hits        47682    47686       +4     
- Misses       4032     4033       +1
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.6% <100%> (ø)` | :arrow_up: |
| #single | `43.02% <100%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24096?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/internals/blocks.py](https://codecov.io/gh/pandas-dev/pandas/pull/24096/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW50ZXJuYWxzL2Jsb2Nrcy5weQ==) | `93.72% <100%> (ø)` | :arrow_up: |
| [pandas/core/series.py](https://codecov.io/gh/pandas-dev/pandas/pull/24096/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc2VyaWVzLnB5) | `93.7% <100%> (+0.01%)` | :arrow_up: |
| [pandas/core/internals/construction.py](https://codecov.io/gh/pandas-dev/pandas/pull/24096/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW50ZXJuYWxzL2NvbnN0cnVjdGlvbi5weQ==) | `96.64% <100%> (+0.02%)` | :arrow_up: |
| [pandas/io/json/json.py](https://codecov.io/gh/pandas-dev/pandas/pull/24096/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2pzb24vanNvbi5weQ==) | `92.61% <0%> (-0.48%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/24096/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `87.51% <0%> (+0.09%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24096?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24096?src=pr&el=footer). Last update [9f2c716...4851ffa](https://codecov.io/gh/pandas-dev/pandas/pull/24096?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

> i don't see any tests for the OP issue here (just the freq change), which AFIACT is orthogonal

Each of the tests has an assertion near the end `assert dti[1] == ts` or `assert dti[0] == ts` that is a check for non-mutation.
lgtm. ping on green.
Ping
thanks!