Skip to content

Commit 0f8a053

Browse files
removed more catch_warnings
1 parent 3510ba8 commit 0f8a053

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

pandas/core/apply.py

Lines changed: 7 additions & 4 deletions
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

@@ -357,9 +356,13 @@ def wrap_results(self, results: ResType) -> Union["Series", "DataFrame"]:
357356
return self.wrap_results_for_axis(results)
358357

359358
# dict of scalars
360-
with warnings.catch_warnings():
361-
warnings.simplefilter(action="ignore", category=FutureWarning)
362-
result = self.obj._constructor_sliced(results)
359+
# TODO: Remove if/else block when default dtype of Series is changed to object
360+
constructor_sliced = self.obj._constructor_sliced
361+
is_empty = isinstance(results, (list, tuple, dict)) and not results
362+
if constructor_sliced is Series and is_empty:
363+
result = constructor_sliced(results, dtype=object)
364+
else:
365+
result = constructor_sliced(results)
363366
result.index = self.res_index
364367

365368
return result

pandas/tests/indexing/common.py

Lines changed: 1 addition & 4 deletions
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

Lines changed: 1 addition & 4 deletions
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)