Skip to content

Commit 68dbccb

Browse files
removed more catch_warnings
1 parent 7802715 commit 68dbccb

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

pandas/core/apply.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import abc
22
import inspect
33
from typing import TYPE_CHECKING, Any, Dict, Iterator, Optional, Type, Union
4-
import warnings
54

65
import numpy as np
76

@@ -351,9 +350,13 @@ def wrap_results(
351350
return self.wrap_results_for_axis(results, res_index)
352351

353352
# dict of scalars
354-
with warnings.catch_warnings():
355-
warnings.simplefilter(action="ignore", category=FutureWarning)
356-
result = self.obj._constructor_sliced(results)
353+
# TODO: Remove if/else block when default dtype of Series is changed to object
354+
constructor_sliced = self.obj._constructor_sliced
355+
is_empty = isinstance(results, (list, tuple, dict)) and not results
356+
if constructor_sliced is Series and is_empty:
357+
result = constructor_sliced(results, dtype=object)
358+
else:
359+
result = constructor_sliced(results)
357360
result.index = res_index
358361

359362
return result

pandas/tests/indexing/common.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
""" common utilities """
22
import itertools
3-
import warnings
43
from warnings import catch_warnings, filterwarnings
54

65
import numpy as np
@@ -98,9 +97,7 @@ def setup_method(self, method):
9897
self.frame_ts_rev = DataFrame(np.random.randn(4, 4), index=dates_rev)
9998

10099
self.frame_empty = DataFrame()
101-
with warnings.catch_warnings():
102-
warnings.simplefilter(action="ignore", category=FutureWarning)
103-
self.series_empty = Series()
100+
self.series_empty = Series(dtype=object)
104101

105102
# form agglomerates
106103
for kind in self._kinds:

pandas/tests/io/json/test_pandas.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from io import StringIO
44
import json
55
import os
6-
import warnings
76

87
import numpy as np
98
import pytest
@@ -671,9 +670,7 @@ def test_series_roundtrip_object(self, orient, numpy, dtype):
671670
@pytest.mark.parametrize("numpy", [True, False])
672671
def test_series_roundtrip_empty(self, orient, numpy):
673672
data = self.empty_series.to_json(orient=orient)
674-
with warnings.catch_warnings():
675-
warnings.simplefilter(action="ignore", category=FutureWarning)
676-
result = pd.read_json(data, typ="series", orient=orient, numpy=numpy)
673+
result = pd.read_json(data, typ="series", orient=orient, numpy=numpy)
677674
expected = self.empty_series.copy()
678675

679676
# TODO: see what causes inconsistency

0 commit comments

Comments
 (0)