Skip to content

Commit d4ecbc8

Browse files
author
MarcoGorelli
committed
add comments
1 parent 96e4dc9 commit d4ecbc8

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

pandas/tests/frame/test_query_eval.py

+2
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ def test_date_index_query(self):
448448
def test_date_index_query_with_NaT(self):
449449
engine, parser = self.engine, self.parser
450450
n = 10
451+
# Cast to object to avoid implicit cast when setting entry to pd.NaT below
451452
df = DataFrame(np.random.randn(n, 3)).astype({0: object})
452453
df["dates1"] = date_range("1/1/2012", periods=n)
453454
df["dates3"] = date_range("1/1/2014", periods=n)
@@ -808,6 +809,7 @@ def test_date_index_query(self):
808809
def test_date_index_query_with_NaT(self):
809810
engine, parser = self.engine, self.parser
810811
n = 10
812+
# Cast to object to avoid implicit cast when setting entry to pd.NaT below
811813
df = DataFrame(np.random.randn(n, 3)).astype({0: object})
812814
df["dates1"] = date_range("1/1/2012", periods=n)
813815
df["dates3"] = date_range("1/1/2014", periods=n)

pandas/tests/frame/test_reductions.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -448,15 +448,15 @@ def test_var_std(self, datetime_frame):
448448
@pytest.mark.parametrize("meth", ["sem", "var", "std"])
449449
def test_numeric_only_flag(self, meth):
450450
# GH 9201
451-
df1 = DataFrame(np.random.randn(5, 3), columns=["foo", "bar", "baz"]).astype(
452-
{"foo": object}
453-
)
451+
df1 = DataFrame(np.random.randn(5, 3), columns=["foo", "bar", "baz"])
452+
# Cast to object to avoid implicit cast when setting entry to "100" below
453+
df1 = df1.astype({"foo": object})
454454
# set one entry to a number in str format
455455
df1.loc[0, "foo"] = "100"
456456

457-
df2 = DataFrame(np.random.randn(5, 3), columns=["foo", "bar", "baz"]).astype(
458-
{"foo": object}
459-
)
457+
df2 = DataFrame(np.random.randn(5, 3), columns=["foo", "bar", "baz"])
458+
# Cast to object to avoid implicit cast when setting entry to "a" below
459+
df2 = df2.astype({"foo": object})
460460
# set one entry to a non-number str
461461
df2.loc[0, "foo"] = "a"
462462

pandas/tests/groupby/test_timegrouper.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ def test_groupby_with_timegrouper(self):
102102
index=date_range(
103103
"20130901", "20131205", freq="5D", name="Date", inclusive="left"
104104
),
105-
).astype({"Buyer": object})
105+
)
106+
# Cast to object to avoid implicit cast when setting entry to "CarlCarlCarl"
107+
expected = expected.astype({"Buyer": object})
106108
expected.iloc[0, 0] = "CarlCarlCarl"
107109
expected.iloc[6, 0] = "CarlCarl"
108110
expected.iloc[18, 0] = "Joe"

pandas/tests/series/methods/test_replace.py

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def test_replace_explicit_none(self):
1616
expected = pd.Series([0, 0, None], dtype=object)
1717
tm.assert_series_equal(result, expected)
1818

19+
# Cast column 2 to object to avoid implicit cast when setting entry to ""
1920
df = pd.DataFrame(np.zeros((3, 3))).astype({2: object})
2021
df.iloc[2, 2] = ""
2122
result = df.replace("", None)

0 commit comments

Comments
 (0)