BUG GH23451 Allow setting date in string index for Series
State: closed

- [X] closes #23451 
- [X] tests added / passed
- [X] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry

Prevents string indices from turning into lists of characters when setting a date.


Labels:
name: Datetime
description: Datetime data dtype
name: Indexing
description: Related to indexing on series/frames, not to indexes themselves

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

 - There are no PEP8 issues in the file [`pandas/core/series.py`](https://github.com/JustinZhengBC/pandas/blob/9d03b801e0a9ad938c9b2ab0b0945a0aeb960f6a/pandas/core/series.py) !

 - There are no PEP8 issues in the file [`pandas/tests/series/test_datetime_values.py`](https://github.com/JustinZhengBC/pandas/blob/9d03b801e0a9ad938c9b2ab0b0945a0aeb960f6a/pandas/tests/series/test_datetime_values.py) !


# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/23495?src=pr&el=h1) Report
> Merging [#23495](https://codecov.io/gh/pandas-dev/pandas/pull/23495?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/54982c24ed23b29d87a18bb9a28ee268463ad0bb?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/23495/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/23495?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #23495      +/-   ##
==========================================
- Coverage   92.25%   92.25%   -0.01%     
==========================================
  Files         161      161              
  Lines       51176    51178       +2     
==========================================
  Hits        47214    47214              
- Misses       3962     3964       +2
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.63% <100%> (-0.01%)` | :arrow_down: |
| #single | `42.28% <0%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/23495?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/series.py](https://codecov.io/gh/pandas-dev/pandas/pull/23495/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc2VyaWVzLnB5) | `93.7% <100%> (-0.18%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/23495?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/23495?src=pr&el=footer). Last update [54982c2...12d2f8a](https://codecov.io/gh/pandas-dev/pandas/pull/23495?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Can you see if this fixes https://github.com/pandas-dev/pandas/issues/12862 as well?
@mroeschke it fixes the issue of strings being split into lists, but that bug still persists because for tz-aware timestamps, the data is stored in a `DateTimeIndex`, whereas almost every other data format is stored in an `ndarray`, and setting an item directly requires an `ndarray` to be passed to the [backend function](https://github.com/pandas-dev/pandas/blob/24ab22f75aae1c9b9491c26e6f753814b7d6fd8e/pandas/_libs/index.pyx#L95). After this, I can do a quick PR to make the [] operator work just like using `.loc`, but it would still lose the timezone data after adding a new item. @jreback is that okay or should the problem be fixed closer to the root cause?
lgtm. ping on green.
@jreback green now
thanks!