#14854: DatetimeIndex compiled together in test_datetime.py
State: closed

### Partially completes #14854 

Grouped all the ```DatetimeIndex``` related tests under one file - ```pandas/tests/indexes/test_datetime.py```.

### Tests reorganized

There were some tests in other classes which could be shifted to the as well. From **```pandas/pandas/tseries/tests/test_timeseries.py```**

- [test_pass_datetimeindex_to_index](https://github.com/pandas-dev/pandas/blob/master/pandas/tseries/tests/test_timeseries.py#L326) from class ```TestTimeSeries```
- [test_datetimeindex_accessors](https://github.com/pandas-dev/pandas/blob/master/pandas/tseries/tests/test_timeseries.py#L3972) from class ```TestDatetime64```
- [test_datetimeindex_diff](https://github.com/pandas-dev/pandas/blob/master/pandas/tseries/tests/test_timeseries.py#L4111) from class ```TestDatetime64```
- [test_nanosecond_field](https://github.com/pandas-dev/pandas/blob/master/pandas/tseries/tests/test_timeseries.py#L4105) from class ```TestDatetime64```
- [test_datetimeindex_constructor](https://github.com/pandas-dev/pandas/blob/master/pandas/tseries/tests/test_timeseries.py#L4146) from class ```TestDatetime64```

1. Should these also be included in the ```test_datetime.py``` in their respective classes or let them be?

2. In **```pandas/tests/indexes/test_datetimelike.py```** there were some tests which were using the ```DatetimeLike``` class defined there. I could import that class in the ```test_datetime.py``` and transfer the whole ```TestDatetimeIndex``` but should it be done?


### Mostly passes ``git diff upstream/master | flake8 --diff``

```
./pandas/tests/indexes/test_datetime.py:1121:5: F811 redefinition of unused 'test_intersection' from line 572
./pandas/tests/indexes/test_datetime.py:1751:5: F811 redefinition of unused 'test_union' from line 589
```
3. Should I merge the two ```test_intersection``` and ```test_union``` functions?


## Further TODOs from the following discussion and the #14854 under datetime

- [x] Split ```datetimes/test_datetime.py``` into smaller chunks

- [x] In ```datetimes/test_misc.py``` lines from 167-202 should go under timestamp related tests (?)

- [x] Transfer of function (```test_datetimeindex_accessors```) from class ```TestDatetime64``` in ```datetimes/test_misc.py``` to class ```TestDatetimeIndexOps``` of ```datetime/test_ops.py``` (?)

- [x] Function ```test_round``` from ```datetimes/test_datetime.py``` to ```pandas/tests/scalars/test_timestamp.py```. (and test_timedelta.py). So anything specifically Timestamp related will go there.


Labels:
name: Testing
description: pandas testing functions or related to the test suite

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/15266?src=pr&el=h1) Report
> Merging [#15266](https://codecov.io/gh/pandas-dev/pandas/pull/15266?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/845208055845b0db58d2bfee7ba39f6862ce141c?src=pr&el=desc) will **not impact** coverage.


```diff
@@           Coverage Diff           @@
##           master   #15266   +/-   ##
=======================================
  Coverage   86.33%   86.33%           
=======================================
  Files         139      139           
  Lines       51149    51149           
=======================================
  Hits        44157    44157           
  Misses       6992     6992
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/15266?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/15266?src=pr&el=footer). Last update [8452080...6ee2bd9](https://codecov.io/gh/pandas-dev/pandas/compare/845208055845b0db58d2bfee7ba39f6862ce141c...6ee2bd99f0ab9595975e6bc8ca486530ae8adf02?el=footer&src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
ok, so the resulting test file is just too big and unweildy.

let's split it out to a sub-dir, IOW

``pandas/tests/indexes/datetime``

then split into a number of files (you can start by splitting each class to a separate named file for instance)
nice start!

name things like

``test_ops.py`` (not ``test_datetimeops`` (except for the main 'test_datetime.py')
Thanks. 

Though, ```test_datetime.py``` still looks big.

What about the questions I raised or is this PR ready?
> In pandas/tests/indexes/test_datetimelike.py there were some tests which were using the DatetimeLike class defined there. I could import that class in the test_datetime.py and transfer the whole TestDatetimeIndex but should it be done?

no ``DatetimeLike`` needs to be defined where it is as PeriodIndex tests use it (though it *could* be factorted to another file if need be)


> There were some tests in other classes which could be shifted to the as well. From pandas/pandas/tseries/tests/test_timeseries.py
test_pass_datetimeindex_to_index from class TestTimeSeries
test_datetimeindex_accessors from class TestDatetime64
test_datetimeindex_diff from class TestDatetime64
test_nanosecond_field from class TestDatetime64
test_datetimeindex_constructor from class TestDatetime64
Should these also be included in the test_datetime.py in their respective classes or let them be?

essentially yes these should be moved.

certainly would like to split up test_datetime.py Ideally split along class lines (though maybe not much there, it might already be a big class).

So can come back and do that later.
also need to add an entry in ``setup.py`` (right after ``pandas.tests.indexes``
Now only remaining thing, it seems, is the merging of those 2 different function definitions by same name (```test_intersection``` and ```test_union```) in the ```pandas/tests/indexes/datetime/test_datetime.py```. I didn't do that because you said not to change individual tests.
@TrigonaMinima sure, let's get this passing. Then pls make a list of what changes you think could / should be made. We want to move and then in other commits, fix/change etc.
@jreback I am sorry, I didn't understand you. Changes like? Merging those two functions and what else? Also, other commits under this PR only, right?
Okay so here's the list I came up with

- [x] In ```datetime/test_misc.py``` lines from 167-202 should go under timestamp related tests (?)

- [x] Transfer of function (```test_datetimeindex_accessors```) from class ```TestDatetime64``` in ```datetime/test_misc.py``` to class ```TestDatetimeIndexOps``` of ```datetime/test_ops.py``` (?)

- [x] Split ```datetime/test_datetime.py``` into smaller chunks
@TrigonaMinima if you can get this passing (iow fix the flake errors) would be great. 
@jreback the build in Python2.7 is giving errors in all the tests in ```pandas/tests/indexes``` due to import errors for ```datetime``` module. I am guessing it is trying to import the new ```datetime``` directory we have just made. It runs fine for Python3.5. 

Any suggestions? Changing the name of the directory is the easiest fix I can think of.
@TrigonaMinima change the directory name to datetimes I think will work
FYI you can do

``git diff master | flake8 --diff`` to see flake errors ahead of time
Yeah. I read the full contributing guide yesterday.

Though, this module name problem wasn't showing up in the output of the command. Which is the right behavior given this isn't exactly a pep8 issue.
@TrigonaMinima yeah, for some reason travis catches slightly different things that local flake8, not really sure why (its only this particular pep, missing a whole module import)
thanks @TrigonaMinima !

ok I am going to push a scalar directory now that is empty, but please continue on moving things!