Skip to content

Commit e8fca9e

Browse files
authored
CLN: collected cleanups, warning suppression in tests (#37021)
1 parent 2c30222 commit e8fca9e

File tree

12 files changed

+55
-43
lines changed

12 files changed

+55
-43
lines changed

pandas/core/indexes/base.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -5404,9 +5404,7 @@ def _cmp_method(self, other, op):
54045404
with np.errstate(all="ignore"):
54055405
result = ops.comparison_op(self._values, np.asarray(other), op)
54065406

5407-
if is_bool_dtype(result):
5408-
return result
5409-
return ops.invalid_comparison(self, other, op)
5407+
return result
54105408

54115409
@classmethod
54125410
def _add_numeric_methods_binary(cls):

pandas/core/internals/blocks.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,7 @@ def _maybe_downcast(self, blocks: List["Block"], downcast=None) -> List["Block"]
501501

502502
# no need to downcast our float
503503
# unless indicated
504-
if downcast is None and (
505-
self.is_float or self.is_timedelta or self.is_datetime
506-
):
504+
if downcast is None and (self.is_float or self.is_datelike):
507505
return blocks
508506

509507
return extend_blocks([b.downcast(downcast) for b in blocks])
@@ -638,7 +636,7 @@ def astype(self, dtype, copy: bool = False, errors: str = "raise"):
638636
if isinstance(values, np.ndarray):
639637
values = values.reshape(self.shape)
640638

641-
newb = make_block(values, placement=self.mgr_locs, ndim=self.ndim)
639+
newb = self.make_block(values)
642640

643641
if newb.is_numeric and self.is_numeric:
644642
if newb.shape != self.shape:
@@ -2484,7 +2482,7 @@ def f(mask, val, idx):
24842482
blocks = self.split_and_operate(None, f, False)
24852483
else:
24862484
values = f(None, self.values.ravel(), None)
2487-
blocks = [make_block(values, ndim=self.ndim, placement=self.mgr_locs)]
2485+
blocks = [self.make_block(values)]
24882486

24892487
return blocks
24902488

pandas/core/internals/concat.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def __repr__(self) -> str:
187187
return f"{type(self).__name__}({repr(self.block)}, {self.indexers})"
188188

189189
@cache_readonly
190-
def needs_filling(self):
190+
def needs_filling(self) -> bool:
191191
for indexer in self.indexers.values():
192192
# FIXME: cache results of indexer == -1 checks.
193193
if (indexer == -1).any():
@@ -206,7 +206,7 @@ def dtype(self):
206206
return get_dtype(maybe_promote(self.block.dtype, self.block.fill_value)[0])
207207

208208
@cache_readonly
209-
def is_na(self):
209+
def is_na(self) -> bool:
210210
if self.block is None:
211211
return True
212212

pandas/io/pytables.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -4728,8 +4728,13 @@ def _set_tz(
47284728
assert values.tz is None or values.tz == tz
47294729

47304730
if tz is not None:
4731-
name = getattr(values, "name", None)
4732-
values = values.ravel()
4731+
if isinstance(values, DatetimeIndex):
4732+
name = values.name
4733+
values = values.asi8
4734+
else:
4735+
name = None
4736+
values = values.ravel()
4737+
47334738
tz = _ensure_decoded(tz)
47344739
values = DatetimeIndex(values, name=name)
47354740
values = values.tz_localize("UTC").tz_convert(tz)

pandas/tests/extension/test_external_block.py

-9
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,6 @@ class CustomBlock(ExtensionBlock):
1111
_holder = np.ndarray
1212
_can_hold_na = False
1313

14-
def concat_same_type(self, to_concat, placement=None):
15-
"""
16-
Always concatenate disregarding self.ndim as the values are
17-
always 1D in this custom Block
18-
"""
19-
values = np.concatenate([blk.values for blk in to_concat])
20-
placement = self.mgr_locs if self.ndim == 2 else slice(len(values))
21-
return self.make_block_same_class(values, placement=placement)
22-
2314

2415
@pytest.fixture
2516
def df():

pandas/tests/frame/apply/test_frame_transform.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,18 @@ def test_transform_bad_dtype(op):
168168
if op in ("backfill", "shift", "pad", "bfill", "ffill"):
169169
pytest.xfail("Transform function works on any datatype")
170170
msg = "Transform function failed"
171-
with pytest.raises(ValueError, match=msg):
172-
df.transform(op)
173-
with pytest.raises(ValueError, match=msg):
174-
df.transform([op])
175-
with pytest.raises(ValueError, match=msg):
176-
df.transform({"A": op})
177-
with pytest.raises(ValueError, match=msg):
178-
df.transform({"A": [op]})
171+
172+
# tshift is deprecated
173+
warn = None if op != "tshift" else FutureWarning
174+
with tm.assert_produces_warning(warn, check_stacklevel=False):
175+
with pytest.raises(ValueError, match=msg):
176+
df.transform(op)
177+
with pytest.raises(ValueError, match=msg):
178+
df.transform([op])
179+
with pytest.raises(ValueError, match=msg):
180+
df.transform({"A": op})
181+
with pytest.raises(ValueError, match=msg):
182+
df.transform({"A": [op]})
179183

180184

181185
@pytest.mark.parametrize("op", transformation_kernels)

pandas/tests/frame/test_api.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,9 @@ def test_constructor_expanddim_lookup(self):
605605
# raise NotImplementedError
606606
df = DataFrame()
607607

608-
inspect.getmembers(df)
608+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
609+
# _AXIS_NUMBERS, _AXIS_NAMES lookups
610+
inspect.getmembers(df)
609611

610612
with pytest.raises(NotImplementedError, match="Not supported for DataFrames!"):
611613
df._constructor_expanddim(np.arange(27).reshape(3, 3, 3))

pandas/tests/indexes/common.py

-2
Original file line numberDiff line numberDiff line change
@@ -613,8 +613,6 @@ def test_equals(self, index):
613613
def test_equals_op(self):
614614
# GH9947, GH10637
615615
index_a = self.create_index()
616-
if isinstance(index_a, PeriodIndex):
617-
pytest.skip("Skip check for PeriodIndex")
618616

619617
n = len(index_a)
620618
index_b = index_a[0:-1]

pandas/tests/io/__init__.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import pytest
2+
3+
pytestmark = [
4+
# fastparquet
5+
pytest.mark.filterwarnings(
6+
"ignore:PY_SSIZE_T_CLEAN will be required.*:DeprecationWarning"
7+
),
8+
# xlrd
9+
pytest.mark.filterwarnings(
10+
"ignore:This method will be removed in future versions:DeprecationWarning"
11+
),
12+
pytest.mark.filterwarnings(
13+
"ignore:This method will be removed in future versions. "
14+
r"Use 'tree.iter\(\)' or 'list\(tree.iter\(\)\)' instead."
15+
":PendingDeprecationWarning"
16+
),
17+
]

pandas/tests/io/excel/__init__.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import pytest
22

3-
pytestmark = pytest.mark.filterwarnings(
4-
# Looks like tree.getiterator is deprecated in favor of tree.iter
5-
"ignore:This method will be removed in future versions:PendingDeprecationWarning"
6-
)
3+
pytestmark = [
4+
pytest.mark.filterwarnings(
5+
# Looks like tree.getiterator is deprecated in favor of tree.iter
6+
"ignore:This method will be removed in future versions:"
7+
"PendingDeprecationWarning"
8+
),
9+
pytest.mark.filterwarnings(
10+
"ignore:This method will be removed in future versions:DeprecationWarning"
11+
),
12+
]

pandas/tests/io/excel/test_readers.py

-2
Original file line numberDiff line numberDiff line change
@@ -635,8 +635,6 @@ def test_read_from_s3_url(self, read_ext, s3_resource, s3so):
635635
tm.assert_frame_equal(url_table, local_table)
636636

637637
@pytest.mark.slow
638-
# ignore warning from old xlrd
639-
@pytest.mark.filterwarnings("ignore:This metho:PendingDeprecationWarning")
640638
def test_read_from_file_url(self, read_ext, datapath):
641639

642640
# FILE

pandas/tests/io/test_common.py

-5
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,6 @@ def test_read_expands_user_home_dir(
245245
),
246246
],
247247
)
248-
@pytest.mark.filterwarnings(
249-
"ignore:This method will be removed in future versions. "
250-
r"Use 'tree.iter\(\)' or 'list\(tree.iter\(\)\)' instead."
251-
":PendingDeprecationWarning"
252-
)
253248
def test_read_fspath_all(self, reader, module, path, datapath):
254249
pytest.importorskip(module)
255250
path = datapath(*path)

0 commit comments

Comments
 (0)