Skip to content

Added test test_datetimeField_after_setitem for issue #6942 #28790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
28 changes: 28 additions & 0 deletions pandas/tests/generic/test_frame.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from copy import deepcopy
from datetime import datetime
from distutils.version import LooseVersion
from operator import methodcaller

Expand Down Expand Up @@ -287,3 +288,30 @@ def test_deepcopy_empty(self):
empty_frame_copy = deepcopy(empty_frame)

self._compare(empty_frame_copy, empty_frame)

def test_datetimeField_after_setitem_with_at(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: test_datetime_field_after_setitem_with_at

# This test covers the unexpected behaviour of datetimeField when using
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

datetimeField -> datetime64 column ?

# setitem on another column as reported in issue #6942

start = pd.to_datetime("20140401")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you use pd.Timestamp here


result = pd.DataFrame(
index=pd.date_range(start, periods=1), columns=["timenow", "Live"]
)

result.at[start, "timenow"] = datetime.today() # initial datetime.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove this comment.


new_datetime = datetime.today()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it matter that this datetime.today() is called separately from the one two lines up? if not, pls use just one datetime object


result.Live = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the test rely on this being result.Live instead of result["Live"]? if not, pls use the latter


# Changing the value in "timenow" column after setting the "Live" column to True.
result.at[start, "timenow"] = new_datetime

expected = pd.DataFrame(
[[new_datetime, True]],
index=pd.date_range(start, periods=1),
columns=["timenow", "Live"],
)

assert_frame_equal(result, expected, check_dtype=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check_dtype=True should be set here.