Skip to content

Commit 66951dc

Browse files
reworked some test changes - instead of asserting the warning, the dtype is specified explicitely mostly
1 parent 967c772 commit 66951dc

24 files changed

+61
-110
lines changed

pandas/core/generic.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6281,6 +6281,8 @@ def fillna(
62816281
2 NaN 1.0 NaN 5
62826282
3 NaN 3.0 NaN 4
62836283
"""
6284+
from pandas import Series
6285+
62846286
inplace = validate_bool_kwarg(inplace, "inplace")
62856287
value, method = validate_fillna_kwargs(value, method)
62866288

@@ -6317,8 +6319,10 @@ def fillna(
63176319
return self
63186320

63196321
if self.ndim == 1:
6320-
if isinstance(value, (dict, ABCSeries)):
6321-
from pandas import Series
6322+
if isinstance(value, dict):
6323+
dtype = object if not value else None
6324+
value = Series(value, dtype=dtype)
6325+
elif isinstance(value, ABCSeries):
63226326

63236327
value = Series(value)
63246328
elif not is_list_like(value):

pandas/io/html.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,8 @@ def _parse_tfoot_tr(self, table):
767767

768768

769769
def _expand_elements(body):
770-
lens = Series([len(elem) for elem in body])
770+
dtype = None if body else object
771+
lens = Series([len(elem) for elem in body], dtype=dtype)
771772
lens_max = lens.max()
772773
not_max = lens[lens != lens_max]
773774

pandas/tests/io/json/test_pandas.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ def setup(self, datapath):
5353
self.objSeries = tm.makeObjectSeries()
5454
self.objSeries.name = "objects"
5555

56-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
57-
self.empty_series = Series([], index=[])
56+
self.empty_series = Series([], index=[], dtype=np.float64)
5857
self.empty_frame = DataFrame()
5958

6059
self.frame = _frame.copy()

pandas/tests/io/test_html.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,7 @@ def test_empty_tables(self):
415415
</tbody>
416416
</table>
417417
"""
418-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
419-
result = self.read_html(html)
420-
418+
result = self.read_html(html)
421419
assert len(result) == 1
422420

423421
def test_multiple_tbody(self):

pandas/tests/resample/test_base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ def test_resample_empty_dataframe(empty_frame, freq, resample_method):
123123
expected = df.copy()
124124
else:
125125
# GH14962
126-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
127-
expected = Series([])
126+
expected = Series([], dtype=object)
128127

129128
if isinstance(df.index, PeriodIndex):
130129
expected.index = df.index.asfreq(freq=freq)

pandas/tests/reshape/test_concat.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,11 +2227,8 @@ def test_concat_empty_series_timelike(self, tz, values):
22272227
# GH 18447
22282228

22292229
first = Series([], dtype="M8[ns]").dt.tz_localize(tz)
2230-
if values:
2231-
second = Series(values)
2232-
else:
2233-
with tm.assert_produces_warning(FutureWarning):
2234-
second = Series(values)
2230+
dtype = None if values else np.float64
2231+
second = Series(values, dtype=dtype)
22352232

22362233
expected = DataFrame(
22372234
{
@@ -2592,11 +2589,7 @@ def test_concat_odered_dict(self):
25922589
@pytest.mark.parametrize("dt", np.sctypes["float"])
25932590
def test_concat_no_unnecessary_upcast(dt, pdt):
25942591
# GH 13247
2595-
if pdt is Series:
2596-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
2597-
dims = pdt().ndim
2598-
else:
2599-
dims = pdt().ndim
2592+
dims = pdt(dtype=object).ndim
26002593

26012594
dfs = [
26022595
pdt(np.array([1], dtype=dt, ndmin=dims)),
@@ -2633,8 +2626,7 @@ def test_concat_empty_and_non_empty_frame_regression():
26332626
def test_concat_empty_and_non_empty_series_regression():
26342627
# GH 18187 regression test
26352628
s1 = pd.Series([1])
2636-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
2637-
s2 = pd.Series([])
2629+
s2 = pd.Series([], dtype=object)
26382630

26392631
expected = s1
26402632
result = pd.concat([s1, s2])

pandas/tests/series/indexing/test_alter_index.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ def test_reindex_with_datetimes():
230230

231231
def test_reindex_corner(datetime_series):
232232
# (don't forget to fix this) I think it's fixed
233-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
234-
empty = Series()
233+
empty = Series(dtype=object)
235234
empty.reindex(datetime_series.index, method="pad") # it works
236235

237236
# corner case: pad empty series
@@ -540,9 +539,8 @@ def test_drop_with_ignore_errors():
540539
def test_drop_empty_list(index, drop_labels):
541540
# GH 21494
542541
expected_index = [i for i in index if i not in drop_labels]
543-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
544-
series = pd.Series(index=index).drop(drop_labels)
545-
expected = pd.Series(index=expected_index)
542+
series = pd.Series(index=index, dtype=object).drop(drop_labels)
543+
expected = pd.Series(index=expected_index, dtype=object)
546544
tm.assert_series_equal(series, expected)
547545

548546

@@ -557,8 +555,5 @@ def test_drop_empty_list(index, drop_labels):
557555
def test_drop_non_empty_list(data, index, drop_labels):
558556
# GH 21494 and GH 16877
559557
with pytest.raises(KeyError, match="not found in axis"):
560-
if data is None:
561-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
562-
pd.Series(data=data, index=index).drop(drop_labels)
563-
else:
564-
pd.Series(data=data, index=index).drop(drop_labels)
558+
dtype = object if data is None else None
559+
pd.Series(data=data, index=index, dtype=dtype).drop(drop_labels)

pandas/tests/series/indexing/test_datetime.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ def test_series_set_value():
105105
dates = [datetime(2001, 1, 1), datetime(2001, 1, 2)]
106106
index = DatetimeIndex(dates)
107107

108-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
109-
s = Series()._set_value(dates[0], 1.0)
108+
s = Series(dtype=object)._set_value(dates[0], 1.0)
110109
s2 = s._set_value(dates[1], np.nan)
111110

112111
expected = Series([1.0, np.nan], index=index)

pandas/tests/series/indexing/test_indexing.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,8 @@ def test_getitem_get(datetime_series, string_series, object_series):
109109

110110
# None
111111
# GH 5652
112-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
113-
s1 = Series()
114-
s2 = Series(index=list("abc"))
112+
s1 = Series(dtype=object)
113+
s2 = Series(dtype=object, index=list("abc"))
115114
for s in [s1, s2]:
116115
result = s.get(None)
117116
assert result is None
@@ -137,8 +136,7 @@ def test_getitem_generator(string_series):
137136

138137
def test_type_promotion():
139138
# GH12599
140-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
141-
s = pd.Series()
139+
s = pd.Series(dtype=object)
142140
s["a"] = pd.Timestamp("2016-01-01")
143141
s["b"] = 3.0
144142
s["c"] = "foo"
@@ -176,8 +174,7 @@ def test_getitem_out_of_bounds(datetime_series):
176174
datetime_series[len(datetime_series)]
177175

178176
# GH #917
179-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
180-
s = Series([])
177+
s = Series([], dtype=object)
181178
with pytest.raises(IndexError, match=msg):
182179
s[-1]
183180

@@ -334,14 +331,12 @@ def test_setitem(datetime_series, string_series):
334331

335332
# Test for issue #10193
336333
key = pd.Timestamp("2012-01-01")
337-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
338-
series = pd.Series()
334+
series = pd.Series(dtype=object)
339335
series[key] = 47
340336
expected = pd.Series(47, [key])
341337
tm.assert_series_equal(series, expected)
342338

343-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
344-
series = pd.Series([], pd.DatetimeIndex([], freq="D"))
339+
series = pd.Series([], pd.DatetimeIndex([], freq="D"), dtype=object)
345340
series[key] = 47
346341
expected = pd.Series(47, pd.DatetimeIndex([key], freq="D"))
347342
tm.assert_series_equal(series, expected)
@@ -649,8 +644,7 @@ def test_setitem_na():
649644

650645
def test_timedelta_assignment():
651646
# GH 8209
652-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
653-
s = Series([])
647+
s = Series([], dtype=object)
654648
s.loc["B"] = timedelta(1)
655649
tm.assert_series_equal(s, Series(Timedelta("1 days"), index=["B"]))
656650

pandas/tests/series/indexing/test_numeric.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ def test_delitem():
153153
tm.assert_series_equal(s, expected)
154154

155155
# empty
156-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
157-
s = Series()
156+
s = Series(dtype=object)
158157

159158
with pytest.raises(KeyError, match=r"^0$"):
160159
del s[0]

0 commit comments

Comments
 (0)