Skip to content

CLN/TST: address FIXMEs #44637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pandas/_testing/_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ def _assert_caught_no_extra_warnings(
if actual_warning.category == ResourceWarning and unclosed in str(
actual_warning.message
):
# FIXME: kludge because pytest.filterwarnings does not
# suppress these, xref GH#38630
# FIXME(GH#38630): kludge because pytest.filterwarnings does not
# suppress these
continue

extra_warnings.append(
Expand Down
10 changes: 1 addition & 9 deletions pandas/core/arrays/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1195,15 +1195,7 @@ def length(self):
Return an Index with entries denoting the length of each Interval in
the IntervalArray.
"""
try:
return self.right - self.left
except TypeError as err:
# length not defined for some types, e.g. string
msg = (
"IntervalArray contains Intervals without defined length, "
"e.g. Intervals with string endpoints"
)
raise TypeError(msg) from err
return self.right - self.left

@property
def mid(self):
Expand Down
14 changes: 3 additions & 11 deletions pandas/tests/base/test_unique.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import numpy as np
import pytest

from pandas._libs import iNaT

from pandas.core.dtypes.common import (
is_datetime64tz_dtype,
needs_i8_conversion,
)
from pandas.core.dtypes.common import is_datetime64tz_dtype

import pandas as pd
from pandas import NumericIndex
Expand Down Expand Up @@ -49,11 +44,8 @@ def test_unique_null(null_obj, index_or_series_obj):
elif isinstance(obj, pd.MultiIndex):
pytest.skip(f"MultiIndex can't hold '{null_obj}'")

values = obj.values
if needs_i8_conversion(obj.dtype):
values[0:2] = iNaT
else:
values[0:2] = null_obj
values = obj._values
values[0:2] = null_obj

klass = type(obj)
repeated_values = np.repeat(values, range(1, len(values) + 1))
Expand Down
13 changes: 5 additions & 8 deletions pandas/tests/extension/base/constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

import pandas as pd
from pandas.api.extensions import ExtensionArray
from pandas.core.internals.blocks import (
DatetimeTZBlock,
ExtensionBlock,
)
from pandas.core.internals.blocks import EABackedBlock
from pandas.tests.extension.base.base import BaseExtensionTests


Expand All @@ -29,14 +26,14 @@ def test_series_constructor(self, data):
assert result.dtype == data.dtype
assert len(result) == len(data)
if hasattr(result._mgr, "blocks"):
assert isinstance(result._mgr.blocks[0], (ExtensionBlock, DatetimeTZBlock))
assert isinstance(result._mgr.blocks[0], EABackedBlock)
assert result._mgr.array is data

# Series[EA] is unboxed / boxed correctly
result2 = pd.Series(result)
assert result2.dtype == data.dtype
if hasattr(result._mgr, "blocks"):
assert isinstance(result2._mgr.blocks[0], (ExtensionBlock, DatetimeTZBlock))
assert isinstance(result2._mgr.blocks[0], EABackedBlock)

def test_series_constructor_no_data_with_index(self, dtype, na_value):
result = pd.Series(index=[1, 2, 3], dtype=dtype)
Expand Down Expand Up @@ -71,15 +68,15 @@ def test_dataframe_constructor_from_dict(self, data, from_series):
assert result.dtypes["A"] == data.dtype
assert result.shape == (len(data), 1)
if hasattr(result._mgr, "blocks"):
assert isinstance(result._mgr.blocks[0], (ExtensionBlock, DatetimeTZBlock))
assert isinstance(result._mgr.blocks[0], EABackedBlock)
assert isinstance(result._mgr.arrays[0], ExtensionArray)

def test_dataframe_from_series(self, data):
result = pd.DataFrame(pd.Series(data))
assert result.dtypes[0] == data.dtype
assert result.shape == (len(data), 1)
if hasattr(result._mgr, "blocks"):
assert isinstance(result._mgr.blocks[0], (ExtensionBlock, DatetimeTZBlock))
assert isinstance(result._mgr.blocks[0], EABackedBlock)
assert isinstance(result._mgr.arrays[0], ExtensionArray)

def test_series_given_mismatched_index_raises(self, data):
Expand Down
16 changes: 6 additions & 10 deletions pandas/tests/extension/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ class TestGetitem(BaseDatetimeTests, base.BaseGetitemTests):


class TestMethods(BaseDatetimeTests, base.BaseMethodsTests):
@pytest.mark.skip(reason="Incorrect expected")
def test_value_counts(self, all_data, dropna):
pass

def test_combine_add(self, data_repeated):
# Timestamp.__add__(Timestamp) not defined
pass
Expand Down Expand Up @@ -140,23 +136,23 @@ def test_arith_frame_with_scalar(self, data, all_arithmetic_operators):

def test_arith_series_with_scalar(self, data, all_arithmetic_operators):
if all_arithmetic_operators in self.implements:
s = pd.Series(data)
self.check_opname(s, all_arithmetic_operators, s.iloc[0], exc=None)
ser = pd.Series(data)
self.check_opname(ser, all_arithmetic_operators, ser.iloc[0], exc=None)
else:
# ... but not the rest.
super().test_arith_series_with_scalar(data, all_arithmetic_operators)

def test_add_series_with_extension_array(self, data):
# Datetime + Datetime not implemented
s = pd.Series(data)
ser = pd.Series(data)
msg = "cannot add DatetimeArray and DatetimeArray"
with pytest.raises(TypeError, match=msg):
s + data
ser + data

def test_arith_series_with_array(self, data, all_arithmetic_operators):
if all_arithmetic_operators in self.implements:
s = pd.Series(data)
self.check_opname(s, all_arithmetic_operators, s.iloc[0], exc=None)
ser = pd.Series(data)
self.check_opname(ser, all_arithmetic_operators, ser.iloc[0], exc=None)
else:
# ... but not the rest.
super().test_arith_series_with_scalar(data, all_arithmetic_operators)
Expand Down
14 changes: 7 additions & 7 deletions pandas/tests/extension/test_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ def test_transpose(self, data):

class TestGetitem(BaseSparseTests, base.BaseGetitemTests):
def test_get(self, data):
s = pd.Series(data, index=[2 * i for i in range(len(data))])
if np.isnan(s.values.fill_value):
assert np.isnan(s.get(4)) and np.isnan(s.iloc[2])
ser = pd.Series(data, index=[2 * i for i in range(len(data))])
if np.isnan(ser.values.fill_value):
assert np.isnan(ser.get(4)) and np.isnan(ser.iloc[2])
else:
assert s.get(4) == s.iloc[2]
assert s.get(2) == s.iloc[1]
assert ser.get(4) == ser.iloc[2]
assert ser.get(2) == ser.iloc[1]

def test_reindex(self, data, na_value):
self._check_unsupported(data)
Expand Down Expand Up @@ -454,8 +454,8 @@ def _compare_other(self, s, data, comparison_op, other):
tm.assert_series_equal(result, expected)

# series
s = pd.Series(data)
result = op(s, other)
ser = pd.Series(data)
result = op(ser, other)
tm.assert_series_equal(result, expected)


Expand Down
8 changes: 1 addition & 7 deletions pandas/tests/frame/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,20 +800,14 @@ def test_setitem_single_column_mixed_datetime(self):
assert df["timestamp"].dtype == np.object_
assert df.loc["b", "timestamp"] == iNaT

# allow this syntax
# allow this syntax (as of GH#3216)
df.loc["c", "timestamp"] = np.nan
assert isna(df.loc["c", "timestamp"])

# allow this syntax
df.loc["d", :] = np.nan
assert not isna(df.loc["c", :]).all()

# FIXME: don't leave commented-out
# as of GH 3216 this will now work!
# try to set with a list like item
# pytest.raises(
# Exception, df.loc.__setitem__, ('d', 'timestamp'), [np.nan])

def test_setitem_mixed_datetime(self):
# GH 9336
expected = DataFrame(
Expand Down
26 changes: 12 additions & 14 deletions pandas/tests/frame/methods/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,31 @@ def test_diff_requires_integer(self):
with pytest.raises(ValueError, match="periods must be an integer"):
df.diff(1.5)

def test_diff_allows_np_integer(self):
# np.int64 is OK GH#44572
df = DataFrame(np.random.randn(2, 2))
res = df.diff(np.int64(1))
expected = df.diff(1)
tm.assert_frame_equal(res, expected)

def test_diff(self, datetime_frame):
the_diff = datetime_frame.diff(1)
# GH#44572 np.int64 is accepted
@pytest.mark.parametrize("num", [1, np.int64(1)])
def test_diff(self, datetime_frame, num):
df = datetime_frame
the_diff = df.diff(num)

tm.assert_series_equal(
the_diff["A"], datetime_frame["A"] - datetime_frame["A"].shift(1)
)
expected = df["A"] - df["A"].shift(num)
tm.assert_series_equal(the_diff["A"], expected)

def test_diff_int_dtype(self):
# int dtype
a = 10_000_000_000_000_000
b = a + 1
s = Series([a, b])
ser = Series([a, b])

rs = DataFrame({"s": s}).diff()
rs = DataFrame({"s": ser}).diff()
assert rs.s[1] == 1

def test_diff_mixed_numeric(self, datetime_frame):
# mixed numeric
tf = datetime_frame.astype("float32")
the_diff = tf.diff(1)
tm.assert_series_equal(the_diff["A"], tf["A"] - tf["A"].shift(1))

def test_diff_axis1_nonconsolidated(self):
# GH#10907
df = DataFrame({"y": Series([2]), "z": Series([3])})
df.insert(0, "x", 1)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/methods/test_transpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,4 @@ def test_transpose_get_view_dt64tzget_view(self):
assert result._mgr.nblocks == 1

rtrip = result._mgr.blocks[0].values
assert np.shares_memory(arr._data, rtrip._data)
assert np.shares_memory(arr._ndarray, rtrip._ndarray)
8 changes: 3 additions & 5 deletions pandas/tests/frame/methods/test_truncate.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,16 @@ def test_truncate_nonsortedindex(self, frame_or_series):
obj.truncate(before=3, after=9)

def test_sort_values_nonsortedindex(self):
# TODO: belongs elsewhere?

rng = date_range("2011-01-01", "2012-01-01", freq="W")
ts = DataFrame(
{"A": np.random.randn(len(rng)), "B": np.random.randn(len(rng))}, index=rng
)

decreasing = ts.sort_values("A", ascending=False)

msg = "truncate requires a sorted index"
with pytest.raises(ValueError, match=msg):
ts.sort_values("A", ascending=False).truncate(
before="2011-11", after="2011-12"
)
decreasing.truncate(before="2011-11", after="2011-12")

def test_truncate_nonsortedindex_axis1(self):
# GH#17935
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/frame/test_block_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,7 @@ def test_stale_cached_series_bug_473(self):
assert pd.isna(Y["g"]["c"])

def test_strange_column_corruption_issue(self):
# FIXME: dont leave commented-out
# (wesm) Unclear how exactly this is related to internal matters
# TODO(wesm): Unclear how exactly this is related to internal matters
df = DataFrame(index=[0, 1])
df[0] = np.nan
wasCol = {}
Expand Down
5 changes: 1 addition & 4 deletions pandas/tests/indexes/categorical/test_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,10 @@ def test_ensure_copied_data(self, index):
#
# Must be tested separately from other indexes because
# self.values is not an ndarray.
# GH#29918 Index.base has been removed
# FIXME: is this test still meaningful?
_base = lambda ar: ar if getattr(ar, "base", None) is None else ar.base

result = CategoricalIndex(index.values, copy=True)
tm.assert_index_equal(index, result)
assert _base(index.values) is not _base(result.values)
assert not np.shares_memory(result._data._codes, index._data._codes)

result = CategoricalIndex(index.values, copy=False)
assert result._data._codes is index._data._codes
Expand Down
5 changes: 0 additions & 5 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ def test_constructor_copy(self, index):
arr[0] = "SOMEBIGLONGSTRING"
assert new_index[0] != "SOMEBIGLONGSTRING"

# FIXME: dont leave commented-out
# what to do here?
# arr = np.array(5.)
# pytest.raises(Exception, arr.view, Index)

@pytest.mark.parametrize("cast_as_obj", [True, False])
@pytest.mark.parametrize(
"index",
Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/io/pytables/test_append.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,6 @@ def test_append_to_multiple_dropna(setup_path):
tm.assert_index_equal(store.select("df1").index, store.select("df2").index)


@pytest.mark.xfail(reason="append_to_multiple_dropna_false is not raising as failed")
def test_append_to_multiple_dropna_false(setup_path):
df1 = tm.makeTimeDataFrame()
df2 = tm.makeTimeDataFrame().rename(columns="{}_2".format)
Expand All @@ -910,8 +909,7 @@ def test_append_to_multiple_dropna_false(setup_path):
{"df1a": ["A", "B"], "df2a": None}, df, selector="df1a", dropna=False
)

# TODO Update error message to desired message for this case
msg = "Cannot select as multiple after appending with dropna=False"
msg = "all tables must have exactly the same nrows!"
with pytest.raises(ValueError, match=msg):
store.select_as_multiple(["df1a", "df2a"])

Expand Down
6 changes: 0 additions & 6 deletions pandas/tests/series/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1397,12 +1397,6 @@ def test_constructor_dtype_timedelta64(self):
td = Series([np.timedelta64(1, "s")])
assert td.dtype == "timedelta64[ns]"

# FIXME: dont leave commented-out
# these are frequency conversion astypes
# for t in ['s', 'D', 'us', 'ms']:
# with pytest.raises(TypeError):
# td.astype('m8[%s]' % t)

# valid astype
with tm.assert_produces_warning(FutureWarning):
# astype(int64) deprecated
Expand Down