BUG: astype with timedelta and datetime string (#22100)
State: closed

- [X] closes #22100
- [ ] tests added / passed
- [ ] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry
Not sure about test. Should I test `DataFrame` method `astype` instead? If so, where to put test?

Labels:
name: Bug
name: Datetime
description: Datetime data dtype

Comments:
Hello @fjdiod! Thanks for updating the PR.





Cheers ! There are no PEP8 issues in this Pull Request. :beers: 

##### Comment last updated on July 31, 2018 at 10:45 Hours UTC
Why do we need this?
https://github.com/pandas-dev/pandas/blob/0b7a08b70444056f964bb636a74ac41ca0058d37/pandas/core/dtypes/cast.py#L688-L699
With that we have:
```python
>>> s = pd.Series([None])
>>> s.astype('m8')
0   NaT
dtype: timedelta64[ns]
>>> s.astype('m8').astype('m8')
0   NaN
dtype: float64
```
which looks strange.
Also, I've noticed:
```python
>>> s = pd.Series([None, 1, 2])
>>> s.astype('timedelta64[ns]')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sergey/projects/pandas/pandas/util/_decorators.py", line 177, in wrapper
    return func(*args, **kwargs)
  File "/home/sergey/projects/pandas/pandas/core/generic.py", line 5182, in astype
    **kwargs)
  File "/home/sergey/projects/pandas/pandas/core/internals/managers.py", line 554, in astype
    return self.apply('astype', dtype=dtype, **kwargs)
  File "/home/sergey/projects/pandas/pandas/core/internals/managers.py", line 421, in apply
    applied = getattr(b, f)(**kwargs)
  File "/home/sergey/projects/pandas/pandas/core/internals/blocks.py", line 564, in astype
    **kwargs)
  File "/home/sergey/projects/pandas/pandas/core/internals/blocks.py", line 655, in _astype
    values = astype_nansafe(values.ravel(), dtype, copy=True)
  File "/home/sergey/projects/pandas/pandas/core/dtypes/cast.py", line 709, in astype_nansafe
    raise ValueError('Cannot convert non-finite values (NA or inf) to '
ValueError: Cannot convert non-finite values (NA or inf) to integer
```
Is it expected?
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22107?src=pr&el=h1) Report
> Merging [#22107](https://codecov.io/gh/pandas-dev/pandas/pull/22107?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/26b3e7de56fdebaf1842b01d747a1a30a126c54a?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #22107      +/-   ##
==========================================
- Coverage   92.07%   92.06%   -0.02%     
==========================================
  Files         170      170              
  Lines       50688    50706      +18     
==========================================
+ Hits        46671    46682      +11     
- Misses       4017     4024       +7
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.47% <100%> (-0.02%)` | :arrow_down: |
| #single | `42.3% <51.56%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/22107?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/json/json.py](https://codecov.io/gh/pandas-dev/pandas/pull/22107/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2pzb24vanNvbi5weQ==) | `92.47% <ø> (ø)` | :arrow_up: |
| [pandas/core/arrays/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/22107/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2NhdGVnb3JpY2FsLnB5) | `95.95% <ø> (ø)` | :arrow_up: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/22107/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.26% <ø> (ø)` | :arrow_up: |
| [pandas/core/series.py](https://codecov.io/gh/pandas-dev/pandas/pull/22107/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc2VyaWVzLnB5) | `94.11% <ø> (ø)` | :arrow_up: |
| [pandas/io/html.py](https://codecov.io/gh/pandas-dev/pandas/pull/22107/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2h0bWwucHk=) | `89.17% <ø> (ø)` | :arrow_up: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/22107/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `85.69% <ø> (-0.21%)` | :arrow_down: |
| [pandas/core/generic.py](https://codecov.io/gh/pandas-dev/pandas/pull/22107/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ2VuZXJpYy5weQ==) | `96.47% <ø> (ø)` | :arrow_up: |
| [pandas/core/arrays/interval.py](https://codecov.io/gh/pandas-dev/pandas/pull/22107/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2ludGVydmFsLnB5) | `92.55% <ø> (-0.05%)` | :arrow_down: |
| [pandas/core/internals/blocks.py](https://codecov.io/gh/pandas-dev/pandas/pull/22107/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW50ZXJuYWxzL2Jsb2Nrcy5weQ==) | `94.45% <100%> (ø)` | :arrow_up: |
| [pandas/core/arrays/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/22107/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2RhdGV0aW1lcy5weQ==) | `95.5% <100%> (+0.04%)` | :arrow_up: |
| ... and [13 more](https://codecov.io/gh/pandas-dev/pandas/pull/22107/diff?src=pr&el=tree-more) | |

------

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

Hello, @jbrockmendel, @WillAyd 
Are there any other changes I should make?
closing as stale. if you'd like to continue pls ping.