Skip to content

Commit c497b5f

Browse files
authored
CLN/TST: address FIXMEs (#44637)
1 parent 658199d commit c497b5f

File tree

15 files changed

+44
-94
lines changed

15 files changed

+44
-94
lines changed

pandas/_testing/_warnings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ def _assert_caught_no_extra_warnings(
151151
if actual_warning.category == ResourceWarning and unclosed in str(
152152
actual_warning.message
153153
):
154-
# FIXME: kludge because pytest.filterwarnings does not
155-
# suppress these, xref GH#38630
154+
# FIXME(GH#38630): kludge because pytest.filterwarnings does not
155+
# suppress these
156156
continue
157157

158158
extra_warnings.append(

pandas/core/arrays/interval.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,15 +1195,7 @@ def length(self):
11951195
Return an Index with entries denoting the length of each Interval in
11961196
the IntervalArray.
11971197
"""
1198-
try:
1199-
return self.right - self.left
1200-
except TypeError as err:
1201-
# length not defined for some types, e.g. string
1202-
msg = (
1203-
"IntervalArray contains Intervals without defined length, "
1204-
"e.g. Intervals with string endpoints"
1205-
)
1206-
raise TypeError(msg) from err
1198+
return self.right - self.left
12071199

12081200
@property
12091201
def mid(self):

pandas/tests/base/test_unique.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import numpy as np
22
import pytest
33

4-
from pandas._libs import iNaT
5-
6-
from pandas.core.dtypes.common import (
7-
is_datetime64tz_dtype,
8-
needs_i8_conversion,
9-
)
4+
from pandas.core.dtypes.common import is_datetime64tz_dtype
105

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

52-
values = obj.values
53-
if needs_i8_conversion(obj.dtype):
54-
values[0:2] = iNaT
55-
else:
56-
values[0:2] = null_obj
47+
values = obj._values
48+
values[0:2] = null_obj
5749

5850
klass = type(obj)
5951
repeated_values = np.repeat(values, range(1, len(values) + 1))

pandas/tests/extension/base/constructors.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33

44
import pandas as pd
55
from pandas.api.extensions import ExtensionArray
6-
from pandas.core.internals.blocks import (
7-
DatetimeTZBlock,
8-
ExtensionBlock,
9-
)
6+
from pandas.core.internals.blocks import EABackedBlock
107
from pandas.tests.extension.base.base import BaseExtensionTests
118

129

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

3532
# Series[EA] is unboxed / boxed correctly
3633
result2 = pd.Series(result)
3734
assert result2.dtype == data.dtype
3835
if hasattr(result._mgr, "blocks"):
39-
assert isinstance(result2._mgr.blocks[0], (ExtensionBlock, DatetimeTZBlock))
36+
assert isinstance(result2._mgr.blocks[0], EABackedBlock)
4037

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

7774
def test_dataframe_from_series(self, data):
7875
result = pd.DataFrame(pd.Series(data))
7976
assert result.dtypes[0] == data.dtype
8077
assert result.shape == (len(data), 1)
8178
if hasattr(result._mgr, "blocks"):
82-
assert isinstance(result._mgr.blocks[0], (ExtensionBlock, DatetimeTZBlock))
79+
assert isinstance(result._mgr.blocks[0], EABackedBlock)
8380
assert isinstance(result._mgr.arrays[0], ExtensionArray)
8481

8582
def test_series_given_mismatched_index_raises(self, data):

pandas/tests/extension/test_datetime.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,6 @@ class TestGetitem(BaseDatetimeTests, base.BaseGetitemTests):
108108

109109

110110
class TestMethods(BaseDatetimeTests, base.BaseMethodsTests):
111-
@pytest.mark.skip(reason="Incorrect expected")
112-
def test_value_counts(self, all_data, dropna):
113-
pass
114-
115111
def test_combine_add(self, data_repeated):
116112
# Timestamp.__add__(Timestamp) not defined
117113
pass
@@ -140,23 +136,23 @@ def test_arith_frame_with_scalar(self, data, all_arithmetic_operators):
140136

141137
def test_arith_series_with_scalar(self, data, all_arithmetic_operators):
142138
if all_arithmetic_operators in self.implements:
143-
s = pd.Series(data)
144-
self.check_opname(s, all_arithmetic_operators, s.iloc[0], exc=None)
139+
ser = pd.Series(data)
140+
self.check_opname(ser, all_arithmetic_operators, ser.iloc[0], exc=None)
145141
else:
146142
# ... but not the rest.
147143
super().test_arith_series_with_scalar(data, all_arithmetic_operators)
148144

149145
def test_add_series_with_extension_array(self, data):
150146
# Datetime + Datetime not implemented
151-
s = pd.Series(data)
147+
ser = pd.Series(data)
152148
msg = "cannot add DatetimeArray and DatetimeArray"
153149
with pytest.raises(TypeError, match=msg):
154-
s + data
150+
ser + data
155151

156152
def test_arith_series_with_array(self, data, all_arithmetic_operators):
157153
if all_arithmetic_operators in self.implements:
158-
s = pd.Series(data)
159-
self.check_opname(s, all_arithmetic_operators, s.iloc[0], exc=None)
154+
ser = pd.Series(data)
155+
self.check_opname(ser, all_arithmetic_operators, ser.iloc[0], exc=None)
160156
else:
161157
# ... but not the rest.
162158
super().test_arith_series_with_scalar(data, all_arithmetic_operators)

pandas/tests/extension/test_sparse.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ def test_transpose(self, data):
179179

180180
class TestGetitem(BaseSparseTests, base.BaseGetitemTests):
181181
def test_get(self, data):
182-
s = pd.Series(data, index=[2 * i for i in range(len(data))])
183-
if np.isnan(s.values.fill_value):
184-
assert np.isnan(s.get(4)) and np.isnan(s.iloc[2])
182+
ser = pd.Series(data, index=[2 * i for i in range(len(data))])
183+
if np.isnan(ser.values.fill_value):
184+
assert np.isnan(ser.get(4)) and np.isnan(ser.iloc[2])
185185
else:
186-
assert s.get(4) == s.iloc[2]
187-
assert s.get(2) == s.iloc[1]
186+
assert ser.get(4) == ser.iloc[2]
187+
assert ser.get(2) == ser.iloc[1]
188188

189189
def test_reindex(self, data, na_value):
190190
self._check_unsupported(data)
@@ -454,8 +454,8 @@ def _compare_other(self, s, data, comparison_op, other):
454454
tm.assert_series_equal(result, expected)
455455

456456
# series
457-
s = pd.Series(data)
458-
result = op(s, other)
457+
ser = pd.Series(data)
458+
result = op(ser, other)
459459
tm.assert_series_equal(result, expected)
460460

461461

pandas/tests/frame/indexing/test_indexing.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -800,20 +800,14 @@ def test_setitem_single_column_mixed_datetime(self):
800800
assert df["timestamp"].dtype == np.object_
801801
assert df.loc["b", "timestamp"] == iNaT
802802

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

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

811-
# FIXME: don't leave commented-out
812-
# as of GH 3216 this will now work!
813-
# try to set with a list like item
814-
# pytest.raises(
815-
# Exception, df.loc.__setitem__, ('d', 'timestamp'), [np.nan])
816-
817811
def test_setitem_mixed_datetime(self):
818812
# GH 9336
819813
expected = DataFrame(

pandas/tests/frame/methods/test_diff.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,31 @@ def test_diff_requires_integer(self):
1717
with pytest.raises(ValueError, match="periods must be an integer"):
1818
df.diff(1.5)
1919

20-
def test_diff_allows_np_integer(self):
21-
# np.int64 is OK GH#44572
22-
df = DataFrame(np.random.randn(2, 2))
23-
res = df.diff(np.int64(1))
24-
expected = df.diff(1)
25-
tm.assert_frame_equal(res, expected)
26-
27-
def test_diff(self, datetime_frame):
28-
the_diff = datetime_frame.diff(1)
20+
# GH#44572 np.int64 is accepted
21+
@pytest.mark.parametrize("num", [1, np.int64(1)])
22+
def test_diff(self, datetime_frame, num):
23+
df = datetime_frame
24+
the_diff = df.diff(num)
2925

30-
tm.assert_series_equal(
31-
the_diff["A"], datetime_frame["A"] - datetime_frame["A"].shift(1)
32-
)
26+
expected = df["A"] - df["A"].shift(num)
27+
tm.assert_series_equal(the_diff["A"], expected)
3328

29+
def test_diff_int_dtype(self):
3430
# int dtype
3531
a = 10_000_000_000_000_000
3632
b = a + 1
37-
s = Series([a, b])
33+
ser = Series([a, b])
3834

39-
rs = DataFrame({"s": s}).diff()
35+
rs = DataFrame({"s": ser}).diff()
4036
assert rs.s[1] == 1
4137

38+
def test_diff_mixed_numeric(self, datetime_frame):
4239
# mixed numeric
4340
tf = datetime_frame.astype("float32")
4441
the_diff = tf.diff(1)
4542
tm.assert_series_equal(the_diff["A"], tf["A"] - tf["A"].shift(1))
4643

44+
def test_diff_axis1_nonconsolidated(self):
4745
# GH#10907
4846
df = DataFrame({"y": Series([2]), "z": Series([3])})
4947
df.insert(0, "x", 1)

pandas/tests/frame/methods/test_transpose.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,4 @@ def test_transpose_get_view_dt64tzget_view(self):
115115
assert result._mgr.nblocks == 1
116116

117117
rtrip = result._mgr.blocks[0].values
118-
assert np.shares_memory(arr._data, rtrip._data)
118+
assert np.shares_memory(arr._ndarray, rtrip._ndarray)

pandas/tests/frame/methods/test_truncate.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,16 @@ def test_truncate_nonsortedindex(self, frame_or_series):
8585
obj.truncate(before=3, after=9)
8686

8787
def test_sort_values_nonsortedindex(self):
88-
# TODO: belongs elsewhere?
89-
9088
rng = date_range("2011-01-01", "2012-01-01", freq="W")
9189
ts = DataFrame(
9290
{"A": np.random.randn(len(rng)), "B": np.random.randn(len(rng))}, index=rng
9391
)
9492

93+
decreasing = ts.sort_values("A", ascending=False)
94+
9595
msg = "truncate requires a sorted index"
9696
with pytest.raises(ValueError, match=msg):
97-
ts.sort_values("A", ascending=False).truncate(
98-
before="2011-11", after="2011-12"
99-
)
97+
decreasing.truncate(before="2011-11", after="2011-12")
10098

10199
def test_truncate_nonsortedindex_axis1(self):
102100
# GH#17935

pandas/tests/frame/test_block_internals.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,7 @@ def test_stale_cached_series_bug_473(self):
352352
assert pd.isna(Y["g"]["c"])
353353

354354
def test_strange_column_corruption_issue(self):
355-
# FIXME: dont leave commented-out
356-
# (wesm) Unclear how exactly this is related to internal matters
355+
# TODO(wesm): Unclear how exactly this is related to internal matters
357356
df = DataFrame(index=[0, 1])
358357
df[0] = np.nan
359358
wasCol = {}

pandas/tests/indexes/categorical/test_category.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,10 @@ def test_ensure_copied_data(self, index):
264264
#
265265
# Must be tested separately from other indexes because
266266
# self.values is not an ndarray.
267-
# GH#29918 Index.base has been removed
268-
# FIXME: is this test still meaningful?
269-
_base = lambda ar: ar if getattr(ar, "base", None) is None else ar.base
270267

271268
result = CategoricalIndex(index.values, copy=True)
272269
tm.assert_index_equal(index, result)
273-
assert _base(index.values) is not _base(result.values)
270+
assert not np.shares_memory(result._data._codes, index._data._codes)
274271

275272
result = CategoricalIndex(index.values, copy=False)
276273
assert result._data._codes is index._data._codes

pandas/tests/indexes/test_base.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ def test_constructor_copy(self, index):
8282
arr[0] = "SOMEBIGLONGSTRING"
8383
assert new_index[0] != "SOMEBIGLONGSTRING"
8484

85-
# FIXME: dont leave commented-out
86-
# what to do here?
87-
# arr = np.array(5.)
88-
# pytest.raises(Exception, arr.view, Index)
89-
9085
@pytest.mark.parametrize("cast_as_obj", [True, False])
9186
@pytest.mark.parametrize(
9287
"index",

pandas/tests/io/pytables/test_append.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,6 @@ def test_append_to_multiple_dropna(setup_path):
896896
tm.assert_index_equal(store.select("df1").index, store.select("df2").index)
897897

898898

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

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

pandas/tests/series/test_constructors.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,12 +1397,6 @@ def test_constructor_dtype_timedelta64(self):
13971397
td = Series([np.timedelta64(1, "s")])
13981398
assert td.dtype == "timedelta64[ns]"
13991399

1400-
# FIXME: dont leave commented-out
1401-
# these are frequency conversion astypes
1402-
# for t in ['s', 'D', 'us', 'ms']:
1403-
# with pytest.raises(TypeError):
1404-
# td.astype('m8[%s]' % t)
1405-
14061400
# valid astype
14071401
with tm.assert_produces_warning(FutureWarning):
14081402
# astype(int64) deprecated

0 commit comments

Comments
 (0)