Added test test_datetimeField_after_setitem for issue #6942
State: closed

Added test `test_datetimeField_after_setitem` in `tests/generic/test_frame.py`.

- [x] closes #6942 
- [x] test added
- [x] passes `black pandas`
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`


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

Comments:
Hello @anirudnits! Thanks for updating this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:



There are currently no PEP 8 issues detected in this Pull Request. Cheers! :beers: 

##### Comment last updated at 2020-01-04 04:19:00 UTC
@anirudnits is this still active? Can you merge master and repush?
@WillAyd sure will do that.
@anirudnits looks like this is failing - can you get CI green?
@WillAyd sorry for the late reply, I am little caught up with some things and will work on the same as soon as possible. Thanks
@anirudnits is this still active?
I guess the reason that CI is failing is because that the dtypes of the DataFrames are not equal (I don't know if that is by design or an error). I can make the `check_dytpe = False` in the `assert_frame_equal` function and I believe that will pass the CI and sorry to keep this issue idle for so long. Appreciate your patience. 
Yea I don't think the original issue is fixed then - are you interested in trying to debug further? 
@WillAyd yeah sure. I will work on it. 
@WillAyd I will also mention the issue in the original thread #6942.
I guess this behavior with **at** is causing the issue:

With `loc`
```
f1 = pd.DataFrame(columns=["A"])
f1.loc[1] = [dt.now()]
f1.dtypes
A    datetime64[ns]
dtype: object
```
With the `constructor`
```
f1 = pd.DataFrame([[dt.now()]], columns=["A"])
f1.dtypes
A    datetime64[ns]
dtype: object
```

The same thing with `at`:

```
f1 = pd.DataFrame(columns=["A"])
f1.at[1, "A"] = dt.now()
f1.dtypes
A    object
dtype: object
```
@anirudnits do you have time to merge in master and address the review comments?
@mroeschke but wouldn't the CI still fail?
Are you interested in solving the original issue still?
@mroeschke sure, I'll look over the code and get back to you by this weekend. That's okay?
I found another peculiar behavior with __dtypes__ and  believe it to be unintended
`df = pd.DataFrame(columns=["a", "b"])`
`df.loc[0, "a"] = 1`
`df.dtypes:`
`a:  **object**`
`b:  object`
`dtype: object`
but
`df = pd.DataFrame(columns=["a"])`
`df.loc[0, "a"] = 1`
`df.dtypes:`
`a: **int64**`
`dtype: object`

shouldn't in the first snippet the __dtype__ of column "a" be __int64__ just like in the second snippet? 
Correct. I think both should be int64
@mroeschke  Sorry for the delay in responding I had been stuck with my school work. So, along with the dtype issues mentioned in this thread, some other dtype issues especially with **.loc** have been mentioned in issues #11617, #14205, #14337 and #14361, some of these issues are closed without proper solution of the said problem. To add to these issues I found something interesting:

`df = pd.DataFrame(columns=['A'])`
`df.loc[0, "A"] = 7`
`df.dtypes`
`A    int64`
`dtype: object`

But

`df = pd.DataFrame(columns=['A'])`
`df.loc[0] = 7`
`df.dtypes`
`A    object`
`dtype: object`

So, I believe it has something to do with how **loc** sets an entire row versus a single column in a row(even though the row may have only one column). Using **at** in the above scenario gives the expected dtype of int64 both times. I tried to find the section in https://github.com/pandas-dev/pandas/blob/6258397047b9debc11bd77b3dd0cd60aa49762fd/pandas/core/indexing.py#L900, where I could find that difference in the behavior of **loc** in handling the two different cases. But the deeper the went I still couldn't find the exact code what I was looking for. So that's what I am stuck with now and would be thankful if you could point to the file(s) where I would find the desired code sections. 

is this still active? this was supposed to be a simple test, but has morphed; let's keep the scope down here.
@jreback I got stuck with the whole indexer thing and couldn't find any real solutions to the `dtype` problem :( I can get the CI to pass by adding `check_dtype=False` when I check the equality of frames. 
@anirudnits can you merge master and fix conflicts?
@anirudnits thanks for the PR. Going to close as stale but please let us know if you would like to pick up this issue again.