Skip to content

Commit

Permalink
CLN: collected cleanups, warning suppression in tests (pandas-dev#37021)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and Kevin D Smith committed Nov 2, 2020
1 parent b137ba4 commit 7934629
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 43 deletions.
4 changes: 1 addition & 3 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5404,9 +5404,7 @@ def _cmp_method(self, other, op):
with np.errstate(all="ignore"):
result = ops.comparison_op(self._values, np.asarray(other), op)

if is_bool_dtype(result):
return result
return ops.invalid_comparison(self, other, op)
return result

@classmethod
def _add_numeric_methods_binary(cls):
Expand Down
8 changes: 3 additions & 5 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,7 @@ def _maybe_downcast(self, blocks: List["Block"], downcast=None) -> List["Block"]

# no need to downcast our float
# unless indicated
if downcast is None and (
self.is_float or self.is_timedelta or self.is_datetime
):
if downcast is None and (self.is_float or self.is_datelike):
return blocks

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

newb = make_block(values, placement=self.mgr_locs, ndim=self.ndim)
newb = self.make_block(values)

if newb.is_numeric and self.is_numeric:
if newb.shape != self.shape:
Expand Down Expand Up @@ -2484,7 +2482,7 @@ def f(mask, val, idx):
blocks = self.split_and_operate(None, f, False)
else:
values = f(None, self.values.ravel(), None)
blocks = [make_block(values, ndim=self.ndim, placement=self.mgr_locs)]
blocks = [self.make_block(values)]

return blocks

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/internals/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def __repr__(self) -> str:
return f"{type(self).__name__}({repr(self.block)}, {self.indexers})"

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

@cache_readonly
def is_na(self):
def is_na(self) -> bool:
if self.block is None:
return True

Expand Down
9 changes: 7 additions & 2 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -4728,8 +4728,13 @@ def _set_tz(
assert values.tz is None or values.tz == tz

if tz is not None:
name = getattr(values, "name", None)
values = values.ravel()
if isinstance(values, DatetimeIndex):
name = values.name
values = values.asi8
else:
name = None
values = values.ravel()

tz = _ensure_decoded(tz)
values = DatetimeIndex(values, name=name)
values = values.tz_localize("UTC").tz_convert(tz)
Expand Down
9 changes: 0 additions & 9 deletions pandas/tests/extension/test_external_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ class CustomBlock(ExtensionBlock):
_holder = np.ndarray
_can_hold_na = False

def concat_same_type(self, to_concat, placement=None):
"""
Always concatenate disregarding self.ndim as the values are
always 1D in this custom Block
"""
values = np.concatenate([blk.values for blk in to_concat])
placement = self.mgr_locs if self.ndim == 2 else slice(len(values))
return self.make_block_same_class(values, placement=placement)


@pytest.fixture
def df():
Expand Down
20 changes: 12 additions & 8 deletions pandas/tests/frame/apply/test_frame_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,18 @@ def test_transform_bad_dtype(op):
if op in ("backfill", "shift", "pad", "bfill", "ffill"):
pytest.xfail("Transform function works on any datatype")
msg = "Transform function failed"
with pytest.raises(ValueError, match=msg):
df.transform(op)
with pytest.raises(ValueError, match=msg):
df.transform([op])
with pytest.raises(ValueError, match=msg):
df.transform({"A": op})
with pytest.raises(ValueError, match=msg):
df.transform({"A": [op]})

# tshift is deprecated
warn = None if op != "tshift" else FutureWarning
with tm.assert_produces_warning(warn, check_stacklevel=False):
with pytest.raises(ValueError, match=msg):
df.transform(op)
with pytest.raises(ValueError, match=msg):
df.transform([op])
with pytest.raises(ValueError, match=msg):
df.transform({"A": op})
with pytest.raises(ValueError, match=msg):
df.transform({"A": [op]})


@pytest.mark.parametrize("op", transformation_kernels)
Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/frame/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,9 @@ def test_constructor_expanddim_lookup(self):
# raise NotImplementedError
df = DataFrame()

inspect.getmembers(df)
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
# _AXIS_NUMBERS, _AXIS_NAMES lookups
inspect.getmembers(df)

with pytest.raises(NotImplementedError, match="Not supported for DataFrames!"):
df._constructor_expanddim(np.arange(27).reshape(3, 3, 3))
2 changes: 0 additions & 2 deletions pandas/tests/indexes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,6 @@ def test_equals(self, index):
def test_equals_op(self):
# GH9947, GH10637
index_a = self.create_index()
if isinstance(index_a, PeriodIndex):
pytest.skip("Skip check for PeriodIndex")

n = len(index_a)
index_b = index_a[0:-1]
Expand Down
17 changes: 17 additions & 0 deletions pandas/tests/io/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest

pytestmark = [
# fastparquet
pytest.mark.filterwarnings(
"ignore:PY_SSIZE_T_CLEAN will be required.*:DeprecationWarning"
),
# xlrd
pytest.mark.filterwarnings(
"ignore:This method will be removed in future versions:DeprecationWarning"
),
pytest.mark.filterwarnings(
"ignore:This method will be removed in future versions. "
r"Use 'tree.iter\(\)' or 'list\(tree.iter\(\)\)' instead."
":PendingDeprecationWarning"
),
]
14 changes: 10 additions & 4 deletions pandas/tests/io/excel/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import pytest

pytestmark = pytest.mark.filterwarnings(
# Looks like tree.getiterator is deprecated in favor of tree.iter
"ignore:This method will be removed in future versions:PendingDeprecationWarning"
)
pytestmark = [
pytest.mark.filterwarnings(
# Looks like tree.getiterator is deprecated in favor of tree.iter
"ignore:This method will be removed in future versions:"
"PendingDeprecationWarning"
),
pytest.mark.filterwarnings(
"ignore:This method will be removed in future versions:DeprecationWarning"
),
]
2 changes: 0 additions & 2 deletions pandas/tests/io/excel/test_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,6 @@ def test_read_from_s3_url(self, read_ext, s3_resource, s3so):
tm.assert_frame_equal(url_table, local_table)

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

# FILE
Expand Down
5 changes: 0 additions & 5 deletions pandas/tests/io/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,6 @@ def test_read_expands_user_home_dir(
),
],
)
@pytest.mark.filterwarnings(
"ignore:This method will be removed in future versions. "
r"Use 'tree.iter\(\)' or 'list\(tree.iter\(\)\)' instead."
":PendingDeprecationWarning"
)
def test_read_fspath_all(self, reader, module, path, datapath):
pytest.importorskip(module)
path = datapath(*path)
Expand Down

0 comments on commit 7934629

Please sign in to comment.