Skip to content

CLN: avoid upcasting in tests where unnecessary (PDEP-6 precursor) #53075

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

Merged
merged 1 commit into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pandas/tests/indexing/test_at.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ def test_at_setitem_multiindex(self):

@pytest.mark.parametrize("row", (Timestamp("2019-01-01"), "2019-01-01"))
def test_at_datetime_index(self, row):
# Set float64 dtype to avoid upcast when setting .5
df = DataFrame(
data=[[1] * 2], index=DatetimeIndex(data=["2019-01-01", "2019-01-02"])
)
).astype({0: "float64"})
expected = DataFrame(
data=[[0.5, 1], [1.0, 1]],
index=DatetimeIndex(data=["2019-01-01", "2019-01-02"]),
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/indexing/test_iloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,8 @@ def test_iloc_setitem_with_scalar_index(self, indexer, value):
# assigning like "df.iloc[0, [0]] = ['Z']" should be evaluated
# elementwisely, not using "setter('A', ['Z'])".

df = DataFrame([[1, 2], [3, 4]], columns=["A", "B"])
# Set object type to avoid upcast when setting "Z"
df = DataFrame([[1, 2], [3, 4]], columns=["A", "B"]).astype({"A": object})
df.iloc[0, indexer] = value
result = df.iloc[0, 0]

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexing/test_scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def test_mixed_index_at_iat_loc_iloc_dataframe(self):

def test_iat_setter_incompatible_assignment(self):
# GH 23236
result = DataFrame({"a": [0, 1], "b": [4, 5]})
result = DataFrame({"a": [0.0, 1.0], "b": [4, 5]})
result.iat[0, 0] = None
expected = DataFrame({"a": [None, 1], "b": [4, 5]})
tm.assert_frame_equal(result, expected)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/interchange/test_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def test_dataframe(data):
def test_missing_from_masked():
df = pd.DataFrame(
{
"x": np.array([1, 2, 3, 4, 0]),
"x": np.array([1.0, 2.0, 3.0, 4.0, 0.0]),
"y": np.array([1.5, 2.5, 3.5, 4.5, 0]),
"z": np.array([True, False, True, True, True]),
}
Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/reshape/test_from_dummies.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ def test_error_with_prefix_default_category_dict_not_complete(


def test_error_with_prefix_contains_nan(dummies_basic):
# Set float64 dtype to avoid upcast when setting np.nan
dummies_basic["col2_c"] = dummies_basic["col2_c"].astype("float64")
dummies_basic.loc[2, "col2_c"] = np.nan
with pytest.raises(
ValueError, match=r"Dummy DataFrame contains NA value in column: 'col2_c'"
Expand All @@ -171,6 +173,8 @@ def test_error_with_prefix_contains_nan(dummies_basic):


def test_error_with_prefix_contains_non_dummies(dummies_basic):
# Set object dtype to avoid upcast when setting "str"
dummies_basic["col2_c"] = dummies_basic["col2_c"].astype(object)
dummies_basic.loc[2, "col2_c"] = "str"
with pytest.raises(TypeError, match=r"Passed DataFrame contains non-dummy data"):
from_dummies(dummies_basic, sep="_")
Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/series/methods/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def test_update(self, using_copy_on_write):
# GH 3217
df = DataFrame([{"a": 1}, {"a": 3, "b": 2}])
df["c"] = np.nan
# Cast to object to avoid upcast when setting "foo"
df["c"] = df["c"].astype(object)
df_orig = df.copy()

df["c"].update(Series(["foo"], index=[0]))
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/series/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def test_valid(self, datetime_series):

def test_hasnans_uncached_for_series():
# GH#19700
idx = Index([0, 1])
# set float64 dtype to avoid upcast when setting nan
idx = Index([0, 1], dtype="float64")
assert idx.hasnans is False
assert "hasnans" in idx._cache
ser = idx.to_series()
Expand Down