Repository: pandas-dev/pandas
Pull request: TST: add tests for using .at() with DateTime indexes
- [x] closes #29709 
- [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature
- [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit).
- [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions.
- [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.


added the tests described in issue #29709 but I feel like more around this subject could be written. let me know what you think! thank you for your time


Problem statement:
DataFrame.at indexing with date string promotes column type, while indexing with datetime casts value
#### Code Sample, a copy-pastable example if possible

```python
index = pd.date_range("2019-01-01", "2019-01-02", freq="D")
df = pd.DataFrame(index=index, columns=["A"]).fillna(1)

>>> df.at[pd.to_datetime('2019-01-01'), 'A'] = 0.98
>>> df
            A
2019-01-01  0  # cast to column dtype
2019-01-02  1
>>> df['A'].dtype
dtype('int64')

>>> df.at['2019-01-01', 'A'] = 0.98
>>> df
               A
2019-01-01  0.98  # column cast to value dtype
2019-01-02  1.00
>>> df['A'].dtype
dtype('float64')
```
#### Problem description
This issue arises when dealing with a Dataframe with a datetime index. When using `DataFrame.at[]` and indexing using a date string, the column dtype is promoted to the type of the provided value. However when using `DataFrame.at[]` and indexing using a datetime, the provided value is instead cast to the column's dtype. In the example, `0.98` is in this case indeed cast to 0.

#### Expected Output
That indexing `DataFrame.at[]` with either a date string or a datetime works the same.

#### Output of ``pd.show_versions()``
<details>

[paste the output of ``pd.show_versions()`` here below this line]
>>> pd.show_versions()
INSTALLED VERSIONS
------------------
commit           : None
python           : 3.6.8.final.0
python-bits      : 64
OS               : Darwin
OS-release       : 18.2.0
machine          : x86_64
processor        : i386
byteorder        : little
LC_ALL           : en_US.UTF-8
LANG             : en_US.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 0.25.3
numpy            : 1.16.1
pytz             : 2019.3
dateutil         : 2.8.0
pip              : 19.3.1
setuptools       : 41.6.0
Cython           : None
pytest           : 4.3.0
hypothesis       : 4.7.11
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : 2.7.7 (dt dec pq3 ext lo64)
jinja2           : 2.10.3
IPython          : None
pandas_datareader: None
bs4              : None
bottleneck       : None
fastparquet      : None
gcsfs            : None
lxml.etree       : None
matplotlib       : None
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pytables         : None
s3fs             : None
scipy            : 1.3.1
sqlalchemy       : None
tables           : None
xarray           : None
xlrd             : None
xlwt             : None
xlsxwriter       : None
</details>

Hints from issue discussion:
Hi, can I take on this issue?
This works on master, best guess is closed by #45121.  Will add a test for it.
@jbrockmendel were you able to add a test for this or is this issue still open?

not that i can recall
Which file would be ideal to write the test in? Is pandas/tests the correct folder?
hello @AryanAgarwal2000 are you still working on this? if so, i think you could add your code to `pandas/tests/indexing/test_at.py`. if not, i would like to work on this issue.

Commit message: fix styling error caught by github actions

Patch to review:
diff --git a/pandas/tests/indexing/test_at.py b/pandas/tests/indexing/test_at.py
index 96c73b007cef3..65ca8885a2f33 100644
--- a/pandas/tests/indexing/test_at.py
+++ b/pandas/tests/indexing/test_at.py
@@ -10,9 +10,11 @@
     CategoricalDtype,
     CategoricalIndex,
     DataFrame,
+    DatetimeIndex,
     MultiIndex,
     Series,
     Timestamp,
+    to_datetime,
 )
 import pandas._testing as tm
 
@@ -97,6 +99,18 @@ def test_at_setitem_categorical_missing(self):
 
         tm.assert_frame_equal(df, expected)
 
+    @pytest.mark.parametrize("row", (to_datetime("2019-01-01"), "2019-01-01"))
+    def test_at_datetime_index(self, row):
+        df = DataFrame(
+            data=[[1] * 2] * 2,
+            columns=["one", "two"],
+            index=DatetimeIndex(data=["2019-01-01", "2019-01-02"]),
+        )
+
+        df.at[row, "one"] = 0.5
+        assert df.at[row, "one"] == 0.5
+        assert df["one"].dtype == "float64"
+
     def test_at_setitem_multiindex(self):
         df = DataFrame(
             np.zeros((3, 2), dtype="int64"),


Code review comments:
diff_hunk: @@ -97,6 +99,18 @@ def test_at_setitem_categorical_missing(self):
 
         tm.assert_frame_equal(df, expected)
 
+    @pytest.mark.parametrize("row", (to_datetime("2019-01-01"), "2019-01-01"))
+    def test_at_datetime_index(self, row):
+        df = DataFrame(
+            data=[[1] * 2] * 2,
path: pandas/tests/indexing/test_at.py
text: @user1:
Passing data=1 should work here. The dimensions are defined by columns and index in this case

diff_hunk: @@ -97,6 +99,18 @@ def test_at_setitem_categorical_missing(self):
 
         tm.assert_frame_equal(df, expected)
 
+    @pytest.mark.parametrize("row", (to_datetime("2019-01-01"), "2019-01-01"))
path: pandas/tests/indexing/test_at.py
text: @user1:
Could you please check the whole DataFrame with tm.assert_frame_equal and use Timestamp() instead too?