Skip to content

Commit d64f117

Browse files
authored
CLN: address TODOs/FIXMEs (#44348)
1 parent 0ecc2c7 commit d64f117

23 files changed

+89
-80
lines changed

pandas/core/frame.py

+3
Original file line numberDiff line numberDiff line change
@@ -3732,6 +3732,9 @@ def _setitem_array(self, key, value):
37323732
self.iloc[indexer] = value
37333733

37343734
else:
3735+
# Note: unlike self.iloc[:, indexer] = value, this will
3736+
# never try to overwrite values inplace
3737+
37353738
if isinstance(value, DataFrame):
37363739
check_key_length(self.columns, key, value)
37373740
for k1, k2 in zip(key, value.columns):

pandas/core/internals/managers.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1045,8 +1045,7 @@ def iset(
10451045
self._rebuild_blknos_and_blklocs()
10461046

10471047
# Note: we exclude DTA/TDA here
1048-
vdtype = getattr(value, "dtype", None)
1049-
value_is_extension_type = is_1d_only_ea_dtype(vdtype)
1048+
value_is_extension_type = is_1d_only_ea_dtype(value.dtype)
10501049

10511050
# categorical/sparse/datetimetz
10521051
if value_is_extension_type:

pandas/core/series.py

+1
Original file line numberDiff line numberDiff line change
@@ -4538,6 +4538,7 @@ def rename(
45384538
dtype: int64
45394539
"""
45404540
if axis is not None:
4541+
# Make sure we raise if an invalid 'axis' is passed.
45414542
axis = self._get_axis_number(axis)
45424543

45434544
if callable(index) or is_dict_like(index):

pandas/tests/frame/methods/test_quantile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ def test_quantile_ea_with_na(self, obj, index):
617617
expected = type(obj)(expected)
618618
tm.assert_equal(result, expected)
619619

620-
# TODO: filtering can be removed after GH#39763 is fixed
620+
# TODO(GH#39763): filtering can be removed after GH#39763 is fixed
621621
@pytest.mark.filterwarnings("ignore:Using .astype to convert:FutureWarning")
622622
def test_quantile_ea_all_na(self, obj, index, frame_or_series):
623623

pandas/tests/frame/test_constructors.py

+13
Original file line numberDiff line numberDiff line change
@@ -2585,6 +2585,19 @@ def test_error_from_2darray(self, col_a, col_b):
25852585
DataFrame({"a": col_a, "b": col_b})
25862586

25872587

2588+
class TestDataFrameConstructorIndexInference:
2589+
def test_frame_from_dict_of_series_overlapping_monthly_period_indexes(self):
2590+
rng1 = pd.period_range("1/1/1999", "1/1/2012", freq="M")
2591+
s1 = Series(np.random.randn(len(rng1)), rng1)
2592+
2593+
rng2 = pd.period_range("1/1/1980", "12/1/2001", freq="M")
2594+
s2 = Series(np.random.randn(len(rng2)), rng2)
2595+
df = DataFrame({"s1": s1, "s2": s2})
2596+
2597+
exp = pd.period_range("1/1/1980", "1/1/2012", freq="M")
2598+
tm.assert_index_equal(df.index, exp)
2599+
2600+
25882601
class TestDataFrameConstructorWithDtypeCoercion:
25892602
def test_floating_values_integer_dtype(self):
25902603
# GH#40110 make DataFrame behavior with arraylike floating data and

pandas/tests/indexes/base_class/test_setops.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ def test_union_sort_other_incomparable(self):
9090

9191
@pytest.mark.xfail(reason="GH#25151 need to decide on True behavior")
9292
def test_union_sort_other_incomparable_true(self):
93-
# TODO decide on True behaviour
93+
# TODO(GH#25151): decide on True behaviour
9494
# sort=True
9595
idx = Index([1, pd.Timestamp("2000")])
9696
with pytest.raises(TypeError, match=".*"):
9797
idx.union(idx[:1], sort=True)
9898

9999
@pytest.mark.xfail(reason="GH#25151 need to decide on True behavior")
100100
def test_intersection_equal_sort_true(self):
101-
# TODO decide on True behaviour
101+
# TODO(GH#25151): decide on True behaviour
102102
idx = Index(["c", "a", "b"])
103103
sorted_ = Index(["a", "b", "c"])
104104
tm.assert_index_equal(idx.intersection(idx, sort=True), sorted_)

pandas/tests/indexes/datetimes/test_date_range.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ def test_cached_range_bug(self):
746746
assert len(rng) == 50
747747
assert rng[0] == datetime(2010, 9, 1, 5)
748748

749-
def test_timezone_comparaison_bug(self):
749+
def test_timezone_comparison_bug(self):
750750
# smoke test
751751
start = Timestamp("20130220 10:00", tz="US/Eastern")
752752
result = date_range(start, periods=2, tz="US/Eastern")

pandas/tests/indexes/multi/test_setops.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def test_difference_sort_special():
203203

204204
@pytest.mark.xfail(reason="Not implemented.")
205205
def test_difference_sort_special_true():
206-
# TODO decide on True behaviour
206+
# TODO(GH#25151): decide on True behaviour
207207
idx = MultiIndex.from_product([[1, 0], ["a", "b"]])
208208
result = idx.difference([], sort=True)
209209
expected = MultiIndex.from_product([[0, 1], ["a", "b"]])
@@ -340,7 +340,7 @@ def test_intersect_equal_sort():
340340

341341
@pytest.mark.xfail(reason="Not implemented.")
342342
def test_intersect_equal_sort_true():
343-
# TODO decide on True behaviour
343+
# TODO(GH#25151): decide on True behaviour
344344
idx = MultiIndex.from_product([[1, 0], ["a", "b"]])
345345
sorted_ = MultiIndex.from_product([[0, 1], ["a", "b"]])
346346
tm.assert_index_equal(idx.intersection(idx, sort=True), sorted_)
@@ -363,7 +363,7 @@ def test_union_sort_other_empty(slice_):
363363

364364
@pytest.mark.xfail(reason="Not implemented.")
365365
def test_union_sort_other_empty_sort(slice_):
366-
# TODO decide on True behaviour
366+
# TODO(GH#25151): decide on True behaviour
367367
# # sort=True
368368
idx = MultiIndex.from_product([[1, 0], ["a", "b"]])
369369
other = idx[:0]
@@ -388,7 +388,7 @@ def test_union_sort_other_incomparable():
388388

389389
@pytest.mark.xfail(reason="Not implemented.")
390390
def test_union_sort_other_incomparable_sort():
391-
# TODO decide on True behaviour
391+
# TODO(GH#25151): decide on True behaviour
392392
# # sort=True
393393
idx = MultiIndex.from_product([[1, pd.Timestamp("2000")], ["a", "b"]])
394394
with pytest.raises(TypeError, match="Cannot compare"):

pandas/tests/indexes/numeric/test_setops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def test_union_sort_other_special(self, slice_):
155155
@pytest.mark.xfail(reason="Not implemented")
156156
@pytest.mark.parametrize("slice_", [slice(None), slice(0)])
157157
def test_union_sort_special_true(self, slice_):
158-
# TODO: decide on True behaviour
158+
# TODO(GH#25151): decide on True behaviour
159159
# sort=True
160160
idx = Index([1, 0, 2])
161161
# default, sort=None

pandas/tests/indexes/period/test_setops.py

-12
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,6 @@ def test_union_misc(self, sort):
153153
expected = index.astype(object).union(index2.astype(object), sort=sort)
154154
tm.assert_index_equal(result, expected)
155155

156-
# TODO: belongs elsewhere
157-
def test_union_dataframe_index(self):
158-
rng1 = period_range("1/1/1999", "1/1/2012", freq="M")
159-
s1 = pd.Series(np.random.randn(len(rng1)), rng1)
160-
161-
rng2 = period_range("1/1/1980", "12/1/2001", freq="M")
162-
s2 = pd.Series(np.random.randn(len(rng2)), rng2)
163-
df = pd.DataFrame({"s1": s1, "s2": s2})
164-
165-
exp = period_range("1/1/1980", "1/1/2012", freq="M")
166-
tm.assert_index_equal(df.index, exp)
167-
168156
def test_intersection(self, sort):
169157
index = period_range("1/1/2000", "1/20/2000", freq="D")
170158

pandas/tests/indexes/ranges/test_range.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,10 @@ def test_delete_preserves_rangeindex_list_middle(self):
204204
loc = [1, 2, 3, 4]
205205
result = idx.delete(loc)
206206
expected = RangeIndex(0, 6, 5)
207-
tm.assert_index_equal(result, expected, exact="equiv") # TODO: retain!
207+
tm.assert_index_equal(result, expected, exact=True)
208208

209209
result = idx.delete(loc[::-1])
210-
tm.assert_index_equal(result, expected, exact="equiv") # TODO: retain!
210+
tm.assert_index_equal(result, expected, exact=True)
211211

212212
def test_delete_all_preserves_rangeindex(self):
213213
idx = RangeIndex(0, 6, 1)

pandas/tests/indexes/test_base.py

-14
Original file line numberDiff line numberDiff line change
@@ -525,20 +525,6 @@ def test_asof_numeric_vs_bool_raises(self):
525525
with pytest.raises(TypeError, match=msg):
526526
right.asof(left)
527527

528-
# TODO: this tests Series.asof
529-
def test_asof_nanosecond_index_access(self):
530-
s = Timestamp("20130101").value
531-
r = DatetimeIndex([s + 50 + i for i in range(100)])
532-
ser = Series(np.random.randn(100), index=r)
533-
534-
first_value = ser.asof(ser.index[0])
535-
536-
# this does not yet work, as parsing strings is done via dateutil
537-
# assert first_value == x['2013-01-01 00:00:00.000000050+0000']
538-
539-
expected_ts = np_datetime64_compat("2013-01-01 00:00:00.000000050+0000", "ns")
540-
assert first_value == ser[Timestamp(expected_ts)]
541-
542528
@pytest.mark.parametrize("index", ["string"], indirect=True)
543529
def test_booleanindex(self, index):
544530
bool_index = np.ones(len(index), dtype=bool)

pandas/tests/indexes/test_setops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ def test_difference_incomparable(self, opname):
773773
@pytest.mark.xfail(reason="Not implemented")
774774
@pytest.mark.parametrize("opname", ["difference", "symmetric_difference"])
775775
def test_difference_incomparable_true(self, opname):
776-
# TODO: decide on True behaviour
776+
# TODO(GH#25151): decide on True behaviour
777777
# # sort=True, raises
778778
a = Index([3, Timestamp("2000"), 1])
779779
b = Index([2, Timestamp("1999"), 1])

pandas/tests/indexing/test_iloc.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,7 @@ def test_iloc_setitem_fullcol_categorical(self, indexer, key, using_array_manage
9696

9797
# check we dont have a view on cat (may be undesired GH#39986)
9898
df.iloc[0, 0] = "gamma"
99-
if overwrite:
100-
assert cat[0] != "gamma"
101-
else:
102-
assert cat[0] != "gamma"
99+
assert cat[0] != "gamma"
103100

104101
# TODO with mixed dataframe ("split" path), we always overwrite the column
105102
frame = DataFrame({0: np.array([0, 1, 2], dtype=object), 1: range(3)})

pandas/tests/indexing/test_indexing.py

+15
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,21 @@ def test_setitem_ndarray_3d(self, index, frame_or_series, indexer_sli):
129129
with pytest.raises(err, match=msg):
130130
idxr[nd3] = 0
131131

132+
def test_getitem_ndarray_0d(self):
133+
# GH#24924
134+
key = np.array(0)
135+
136+
# dataframe __getitem__
137+
df = DataFrame([[1, 2], [3, 4]])
138+
result = df[key]
139+
expected = Series([1, 3], name=0)
140+
tm.assert_series_equal(result, expected)
141+
142+
# series __getitem__
143+
ser = Series([1, 2])
144+
result = ser[key]
145+
assert result == 1
146+
132147
def test_inf_upcast(self):
133148
# GH 16957
134149
# We should be able to use np.inf as a key

pandas/tests/indexing/test_loc.py

+21-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
time,
77
timedelta,
88
)
9-
from io import StringIO
109
import re
1110

1211
from dateutil.tz import gettz
@@ -558,15 +557,27 @@ def test_loc_setitem_consistency_empty(self):
558557
def test_loc_setitem_consistency_slice_column_len(self):
559558
# .loc[:,column] setting with slice == len of the column
560559
# GH10408
561-
data = """Level_0,,,Respondent,Respondent,Respondent,OtherCat,OtherCat
562-
Level_1,,,Something,StartDate,EndDate,Yes/No,SomethingElse
563-
Region,Site,RespondentID,,,,,
564-
Region_1,Site_1,3987227376,A,5/25/2015 10:59,5/25/2015 11:22,Yes,
565-
Region_1,Site_1,3980680971,A,5/21/2015 9:40,5/21/2015 9:52,Yes,Yes
566-
Region_1,Site_2,3977723249,A,5/20/2015 8:27,5/20/2015 8:41,Yes,
567-
Region_1,Site_2,3977723089,A,5/20/2015 8:33,5/20/2015 9:09,Yes,No"""
568-
569-
df = pd.read_csv(StringIO(data), header=[0, 1], index_col=[0, 1, 2])
560+
levels = [
561+
["Region_1"] * 4,
562+
["Site_1", "Site_1", "Site_2", "Site_2"],
563+
[3987227376, 3980680971, 3977723249, 3977723089],
564+
]
565+
mi = MultiIndex.from_arrays(levels, names=["Region", "Site", "RespondentID"])
566+
567+
clevels = [
568+
["Respondent", "Respondent", "Respondent", "OtherCat", "OtherCat"],
569+
["Something", "StartDate", "EndDate", "Yes/No", "SomethingElse"],
570+
]
571+
cols = MultiIndex.from_arrays(clevels, names=["Level_0", "Level_1"])
572+
573+
values = [
574+
["A", "5/25/2015 10:59", "5/25/2015 11:22", "Yes", np.nan],
575+
["A", "5/21/2015 9:40", "5/21/2015 9:52", "Yes", "Yes"],
576+
["A", "5/20/2015 8:27", "5/20/2015 8:41", "Yes", np.nan],
577+
["A", "5/20/2015 8:33", "5/20/2015 9:09", "Yes", "No"],
578+
]
579+
df = DataFrame(values, index=mi, columns=cols)
580+
570581
df.loc[:, ("Respondent", "StartDate")] = to_datetime(
571582
df.loc[:, ("Respondent", "StartDate")]
572583
)

pandas/tests/indexing/test_scalar.py

+2-15
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ def _check(f, func, values=False):
7474
_check(f, "at")
7575

7676

77-
class TestScalar2:
78-
# TODO: Better name, just separating things that dont need Base class
77+
class TestAtAndiAT:
78+
# at and iat tests that don't need Base class
7979

8080
def test_at_iat_coercion(self):
8181

@@ -214,19 +214,6 @@ def test_iat_setter_incompatible_assignment(self):
214214
expected = DataFrame({"a": [None, 1], "b": [4, 5]})
215215
tm.assert_frame_equal(result, expected)
216216

217-
def test_getitem_zerodim_np_array(self):
218-
# GH24924
219-
# dataframe __getitem__
220-
df = DataFrame([[1, 2], [3, 4]])
221-
result = df[np.array(0)]
222-
expected = Series([1, 3], name=0)
223-
tm.assert_series_equal(result, expected)
224-
225-
# series __getitem__
226-
s = Series([1, 2])
227-
result = s[np.array(0)]
228-
assert result == 1
229-
230217

231218
def test_iat_dont_wrap_object_datetimelike():
232219
# GH#32809 .iat calls go through DataFrame._get_value, should not

pandas/tests/io/formats/test_console.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from pandas._config import detect_console_encoding
66

77

8-
class MockEncoding: # TODO(py27): replace with mock
8+
class MockEncoding:
99
"""
1010
Used to add a side effect when accessing the 'encoding' property. If the
1111
side effect is a str in nature, the value will be returned. Otherwise, the

pandas/tests/plotting/test_backend.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_register_entrypoint(restore_backend):
7171
result = pandas.plotting._core._get_plot_backend("my_backend")
7272
assert result is mod
7373

74-
# TODO: https://github.com/pandas-dev/pandas/issues/27517
74+
# TODO(GH#27517): https://github.com/pandas-dev/pandas/issues/27517
7575
# Remove the td.skip_if_no_mpl
7676
with pandas.option_context("plotting.backend", "my_backend"):
7777
result = pandas.plotting._core._get_plot_backend()

pandas/tests/reshape/test_melt.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -671,13 +671,12 @@ def test_simple(self):
671671
tm.assert_frame_equal(result, expected)
672672

673673
def test_stubs(self):
674-
# GH9204
674+
# GH9204 wide_to_long call should not modify 'stubs' list
675675
df = DataFrame([[0, 1, 2, 3, 8], [4, 5, 6, 7, 9]])
676676
df.columns = ["id", "inc1", "inc2", "edu1", "edu2"]
677677
stubs = ["inc", "edu"]
678678

679-
# TODO: unused?
680-
df_long = wide_to_long(df, stubs, i="id", j="age") # noqa
679+
wide_to_long(df, stubs, i="id", j="age")
681680

682681
assert stubs == ["inc", "edu"]
683682

pandas/tests/scalar/period/test_asfreq.py

-3
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,6 @@ def test_conv_daily(self):
428428
ival_D_saturday = Period(freq="D", year=2007, month=1, day=6)
429429
ival_D_sunday = Period(freq="D", year=2007, month=1, day=7)
430430

431-
# TODO: unused?
432-
# ival_D_monday = Period(freq='D', year=2007, month=1, day=8)
433-
434431
ival_B_friday = Period(freq="B", year=2007, month=1, day=5)
435432
ival_B_monday = Period(freq="B", year=2007, month=1, day=8)
436433

pandas/tests/series/methods/test_asof.py

+16
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
import pytest
33

44
from pandas._libs.tslibs import IncompatibleFrequency
5+
from pandas.compat import np_datetime64_compat
56

67
from pandas import (
8+
DatetimeIndex,
79
Series,
810
Timestamp,
911
date_range,
@@ -15,6 +17,20 @@
1517

1618

1719
class TestSeriesAsof:
20+
def test_asof_nanosecond_index_access(self):
21+
ts = Timestamp("20130101").value
22+
dti = DatetimeIndex([ts + 50 + i for i in range(100)])
23+
ser = Series(np.random.randn(100), index=dti)
24+
25+
first_value = ser.asof(ser.index[0])
26+
27+
# this used to not work bc parsing was done by dateutil that didn't
28+
# handle nanoseconds
29+
assert first_value == ser["2013-01-01 00:00:00.000000050+0000"]
30+
31+
expected_ts = np_datetime64_compat("2013-01-01 00:00:00.000000050+0000", "ns")
32+
assert first_value == ser[Timestamp(expected_ts)]
33+
1834
def test_basic(self):
1935

2036
# array or list or dates

pandas/tests/series/test_logical_ops.py

-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ def test_logical_operators_bool_dtype_with_empty(self):
4949
def test_logical_operators_int_dtype_with_int_dtype(self):
5050
# GH#9016: support bitwise op for integer types
5151

52-
# TODO: unused
53-
# s_0101 = Series([0, 1, 0, 1])
54-
5552
s_0123 = Series(range(4), dtype="int64")
5653
s_3333 = Series([3] * 4)
5754
s_4444 = Series([4] * 4)

0 commit comments

Comments
 (0)