Skip to content

Commit b329806

Browse files
authored
CLN More float warnings (#50605)
1 parent c29736a commit b329806

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

pandas/tests/series/methods/test_asof.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ def test_scalar(self):
6363

6464
N = 30
6565
rng = date_range("1/1/1990", periods=N, freq="53s")
66-
ts = Series(np.arange(N), index=rng)
66+
# Explicit cast to float avoid implicit cast when setting nan
67+
ts = Series(np.arange(N), index=rng, dtype="float")
6768
ts.iloc[5:10] = np.NaN
6869
ts.iloc[15:20] = np.NaN
6970

pandas/tests/series/methods/test_interpolate.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,8 @@ def test_spline_smooth(self):
703703

704704
@td.skip_if_no_scipy
705705
def test_spline_interpolation(self):
706-
s = Series(np.arange(10) ** 2)
706+
# Explicit cast to float to avoid implicit cast when setting np.nan
707+
s = Series(np.arange(10) ** 2, dtype="float")
707708
s[np.random.randint(0, 9, 3)] = np.nan
708709
result1 = s.interpolate(method="spline", order=1)
709710
expected1 = s.interpolate(method="spline", order=1)

pandas/tests/series/methods/test_rank.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ def test_rank(self, datetime_series):
9292
iranks = iseries.rank(pct=True)
9393
tm.assert_series_equal(iranks, exp)
9494

95+
# Explicit cast to float to avoid implicit cast when setting nan
96+
iseries = iseries.astype("float")
9597
iseries[1] = np.nan
9698
exp = Series(np.repeat(50.0 / 99.0, 100))
9799
exp[1] = np.nan
@@ -109,14 +111,16 @@ def test_rank(self, datetime_series):
109111
iranks = iseries.rank(pct=True)
110112
tm.assert_series_equal(iranks, exp)
111113

112-
iseries = Series(np.arange(5)) + 1
114+
# Explicit cast to float to avoid implicit cast when setting nan
115+
iseries = Series(np.arange(5), dtype="float") + 1
113116
iseries[4] = np.nan
114117
exp = iseries / 4.0
115118
iranks = iseries.rank(pct=True)
116119
tm.assert_series_equal(iranks, exp)
117120

118121
rng = date_range("1/1/1990", periods=5)
119-
iseries = Series(np.arange(5), rng) + 1
122+
# Explicit cast to float to avoid implicit cast when setting nan
123+
iseries = Series(np.arange(5), rng, dtype="float") + 1
120124
iseries.iloc[4] = np.nan
121125
exp = iseries / 4.0
122126
iranks = iseries.rank(pct=True)

pandas/tests/tools/test_to_datetime.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ def test_to_datetime_format_YYYYMMDD(self, cache):
117117
tm.assert_series_equal(result, expected)
118118

119119
def test_to_datetime_format_YYYYMMDD_with_nat(self, cache):
120-
ser = Series([19801222, 19801222] + [19810105] * 5)
120+
# Explicit cast to float to explicit cast when setting np.nan
121+
ser = Series([19801222, 19801222] + [19810105] * 5, dtype="float")
121122
# with NaT
122123
expected = Series(
123124
[Timestamp("19801222"), Timestamp("19801222")] + [Timestamp("19810105")] * 5
@@ -139,7 +140,8 @@ def test_to_datetime_format_YYYYMMDD_with_nat(self, cache):
139140

140141
def test_to_datetime_format_YYYYMM_with_nat(self, cache):
141142
# https://github.com/pandas-dev/pandas/issues/50237
142-
ser = Series([198012, 198012] + [198101] * 5)
143+
# Explicit cast to float to explicit cast when setting np.nan
144+
ser = Series([198012, 198012] + [198101] * 5, dtype="float")
143145
expected = Series(
144146
[Timestamp("19801201"), Timestamp("19801201")] + [Timestamp("19810101")] * 5
145147
)

0 commit comments

Comments
 (0)