BUG: TimedeltaIndex raising ValueError when slice indexing (#16637)
State: closed

Before accepting this Pull request is there any other kind of usage of loc that might fail using deltatimeindex that I am not aware of? I could take some time to fix it once and for all.

closes #16637

 - [ x ] closes #16637
 - [ x ] tests added / passed
 - [ x ] passes ``git diff upstream/master --name-only -- '*.py' | flake8 --diff``
 - [ x ] whatsnew entry


Labels:
name: Bug
name: Indexing
description: Related to indexing on series/frames, not to indexes themselves
name: Timedelta
description: Timedelta data type

Comments:
https://github.com/pandas-dev/pandas/issues?q=is%3Aopen+is%3Aissue+label%3ATimedelta+label%3AIndexing

are the only timedelta / indexing issues AFAICT (aside from new  one)
lgtm (just a comment to check location of test). ping on green.
do u have a repo for isnull or is_timeselta64_dtype raising?
Yeah... I am not sure about this change for the is_timedelta64_dtype. On one hand the behavior to me is bogus(Either a value is of a type or it's not). On the other hand, other projects may rely on this behavior(Why? I have no idea). I ran the test against the pandas suite and nothing broke.

I can make the change locally in get_loc, but I would rather fix the issue directly in the function. Let me know what you think.
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16638?src=pr&el=h1) Report
> Merging [#16638](https://codecov.io/gh/pandas-dev/pandas/pull/16638?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/15db50bbdbce91608c9c4c0bc1398c41a619a9be?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/16638/graphs/tree.svg?token=eZ4WkYLtcO&src=pr&height=150&width=650)](https://codecov.io/gh/pandas-dev/pandas/pull/16638?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #16638      +/-   ##
==========================================
+ Coverage   90.96%   90.96%   +<.01%     
==========================================
  Files         161      161              
  Lines       49274    49277       +3     
==========================================
+ Hits        44820    44824       +4     
+ Misses       4454     4453       -1
```

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

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/16638?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/dtypes/common.py](https://codecov.io/gh/pandas-dev/pandas/pull/16638?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2NvbW1vbi5weQ==) | `94.79% <100%> (+0.04%)` | :arrow_up: |
| [pandas/core/indexes/timedeltas.py](https://codecov.io/gh/pandas-dev/pandas/pull/16638?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy90aW1lZGVsdGFzLnB5) | `90.58% <100%> (+0.19%)` | :arrow_up: |

------

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

@jreback @jorisvandenbossche Both failures are unrelated to the code I changed. I think it's ready to be merged at this point.
lgtm. pls rebase and push again (had some ci failures unrelated).
http://pandas.pydata.org/pandas-docs/stable/contributing.html#using-pytest
Hi,

I have noticed another issue closely related to this.

```python
df.loc[[0, 3], 'x'] = 20
```

This will fail with the ValueError. Instead, it should do `KeyError: 'None of [[0, 3]] are in the [index]'`

I will take a second look a bit later and see if I can fix this.
you can address that other error in another PR (or here) up 2 u
I Will do it in a separate PR

On Jun 9, 2017 7:30 PM, "Jeff Reback" <notifications@github.com> wrote:

> you can address that other error in another PR (or here) up 2 u
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/16638#issuecomment-307523934>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AJfOkHsSqoNiRUy1nTRZw-_h-wRaAgUyks5sCdWhgaJpZM4N0GMz>
> .
>

@jdeschenes ok great. if you can create an issue would be great.

FYI travis is fixed, working on circle now. pytest-xdist new version broke some things.
@jdeschenes can you update? (some linting failures too I believe)
I have added the backticks to the what's new.

For the test, I have added an extra case. I can more if you want, if you have a better idea of what you want to see there, let me know.

I didn't see any linting issues running flake8. Let me know if you have a report or another tool that you are using to detect the failures you are mentionning.
@jdeschenes that's what failed this build: https://travis-ci.org/pandas-dev/pandas/jobs/249668871#L1779
can you rebase
Let me know if you need anything else!
thanks!