Skip to content

Commit 7b5f93e

Browse files
authored
STYLE: Inconsistent namespace - Indexes (#39992) (#40001)
1 parent db95fdc commit 7b5f93e

14 files changed

+66
-67
lines changed

pandas/tests/indexes/common.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def test_numpy_repeat(self):
355355
@pytest.mark.parametrize("klass", [list, tuple, np.array, Series])
356356
def test_where(self, klass):
357357
i = self.create_index()
358-
if isinstance(i, (pd.DatetimeIndex, pd.TimedeltaIndex)):
358+
if isinstance(i, (DatetimeIndex, TimedeltaIndex)):
359359
# where does not preserve freq
360360
i = i._with_freq(None)
361361

@@ -605,7 +605,7 @@ def test_map(self):
605605
index = self.create_index()
606606

607607
# we don't infer UInt64
608-
if isinstance(index, pd.UInt64Index):
608+
if isinstance(index, UInt64Index):
609609
expected = index.astype("int64")
610610
else:
611611
expected = index
@@ -624,13 +624,13 @@ def test_map(self):
624624
def test_map_dictlike(self, mapper):
625625

626626
index = self.create_index()
627-
if isinstance(index, pd.CategoricalIndex):
627+
if isinstance(index, CategoricalIndex):
628628
pytest.skip(f"skipping tests for {type(index)}")
629629

630630
identity = mapper(index.values, index)
631631

632632
# we don't infer to UInt64 for a dict
633-
if isinstance(index, pd.UInt64Index) and isinstance(identity, dict):
633+
if isinstance(index, UInt64Index) and isinstance(identity, dict):
634634
expected = index.astype("int64")
635635
else:
636636
expected = index

pandas/tests/indexes/datetimes/methods/test_astype.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,13 @@ def test_astype_object_tz(self, tz):
202202

203203
def test_astype_object_with_nat(self):
204204
idx = DatetimeIndex(
205-
[datetime(2013, 1, 1), datetime(2013, 1, 2), pd.NaT, datetime(2013, 1, 4)],
205+
[datetime(2013, 1, 1), datetime(2013, 1, 2), NaT, datetime(2013, 1, 4)],
206206
name="idx",
207207
)
208208
expected_list = [
209209
Timestamp("2013-01-01"),
210210
Timestamp("2013-01-02"),
211-
pd.NaT,
211+
NaT,
212212
Timestamp("2013-01-04"),
213213
]
214214
expected = Index(expected_list, dtype=object, name="idx")

pandas/tests/indexes/datetimes/test_constructors.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,8 @@ def test_construction_outofbounds(self):
523523
def test_construction_with_ndarray(self):
524524
# GH 5152
525525
dates = [datetime(2013, 10, 7), datetime(2013, 10, 8), datetime(2013, 10, 9)]
526-
data = DatetimeIndex(dates, freq=pd.offsets.BDay()).values
527-
result = DatetimeIndex(data, freq=pd.offsets.BDay())
526+
data = DatetimeIndex(dates, freq=offsets.BDay()).values
527+
result = DatetimeIndex(data, freq=offsets.BDay())
528528
expected = DatetimeIndex(["2013-10-07", "2013-10-08", "2013-10-09"], freq="B")
529529
tm.assert_index_equal(result, expected)
530530

pandas/tests/indexes/datetimes/test_date_range.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ def test_range_with_millisecond_resolution(self, start_end):
10261026

10271027
def test_date_range_with_custom_holidays():
10281028
# GH 30593
1029-
freq = pd.offsets.CustomBusinessHour(start="15:00", holidays=["2020-11-26"])
1029+
freq = offsets.CustomBusinessHour(start="15:00", holidays=["2020-11-26"])
10301030
result = date_range(start="2020-11-25 15:00", periods=4, freq=freq)
10311031
expected = DatetimeIndex(
10321032
[

pandas/tests/indexes/datetimes/test_datetime.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def test_asarray_tz_naive(self):
217217
# optionally, object
218218
result = np.asarray(idx, dtype=object)
219219

220-
expected = np.array([pd.Timestamp("2000-01-01"), pd.Timestamp("2000-01-02")])
220+
expected = np.array([Timestamp("2000-01-01"), Timestamp("2000-01-02")])
221221
tm.assert_numpy_array_equal(result, expected)
222222

223223
def test_asarray_tz_aware(self):
@@ -235,7 +235,7 @@ def test_asarray_tz_aware(self):
235235

236236
# Future behavior with no warning
237237
expected = np.array(
238-
[pd.Timestamp("2000-01-01", tz=tz), pd.Timestamp("2000-01-02", tz=tz)]
238+
[Timestamp("2000-01-01", tz=tz), Timestamp("2000-01-02", tz=tz)]
239239
)
240240
result = np.asarray(idx, dtype=object)
241241

pandas/tests/indexes/multi/test_conversion.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def test_to_frame():
9090

9191
def test_to_frame_dtype_fidelity():
9292
# GH 22420
93-
mi = pd.MultiIndex.from_arrays(
93+
mi = MultiIndex.from_arrays(
9494
[
9595
pd.date_range("19910905", periods=6, tz="US/Eastern"),
9696
[1, 1, 1, 2, 2, 2],
@@ -119,7 +119,7 @@ def test_to_frame_dtype_fidelity():
119119
def test_to_frame_resulting_column_order():
120120
# GH 22420
121121
expected = ["z", 0, "a"]
122-
mi = pd.MultiIndex.from_arrays(
122+
mi = MultiIndex.from_arrays(
123123
[["a", "b", "c"], ["x", "y", "z"], ["q", "w", "e"]], names=expected
124124
)
125125
result = mi.to_frame().columns.tolist()

pandas/tests/indexes/multi/test_drop.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def test_single_level_drop_partially_missing_elements():
187187

188188
def test_droplevel_multiindex_one_level():
189189
# GH#37208
190-
index = pd.MultiIndex.from_tuples([(2,)], names=("b",))
190+
index = MultiIndex.from_tuples([(2,)], names=("b",))
191191
result = index.droplevel([])
192192
expected = pd.Int64Index([2], name="b")
193193
tm.assert_index_equal(result, expected)

pandas/tests/indexes/multi/test_equivalence.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ def test_equals_missing_values():
223223

224224
def test_equals_missing_values_differently_sorted():
225225
# GH#38439
226-
mi1 = pd.MultiIndex.from_tuples([(81.0, np.nan), (np.nan, np.nan)])
227-
mi2 = pd.MultiIndex.from_tuples([(np.nan, np.nan), (81.0, np.nan)])
226+
mi1 = MultiIndex.from_tuples([(81.0, np.nan), (np.nan, np.nan)])
227+
mi2 = MultiIndex.from_tuples([(np.nan, np.nan), (81.0, np.nan)])
228228
assert not mi1.equals(mi2)
229229

230-
mi2 = pd.MultiIndex.from_tuples([(81.0, np.nan), (np.nan, np.nan)])
230+
mi2 = MultiIndex.from_tuples([(81.0, np.nan), (np.nan, np.nan)])
231231
assert mi1.equals(mi2)
232232

233233

pandas/tests/indexes/multi/test_join.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import numpy as np
22
import pytest
33

4-
import pandas as pd
54
from pandas import (
65
Index,
76
MultiIndex,
@@ -54,12 +53,12 @@ def test_join_self(idx, join_type):
5453

5554
def test_join_multi():
5655
# GH 10665
57-
midx = pd.MultiIndex.from_product([np.arange(4), np.arange(4)], names=["a", "b"])
56+
midx = MultiIndex.from_product([np.arange(4), np.arange(4)], names=["a", "b"])
5857
idx = Index([1, 2, 5], name="b")
5958

6059
# inner
6160
jidx, lidx, ridx = midx.join(idx, how="inner", return_indexers=True)
62-
exp_idx = pd.MultiIndex.from_product([np.arange(4), [1, 2]], names=["a", "b"])
61+
exp_idx = MultiIndex.from_product([np.arange(4), [1, 2]], names=["a", "b"])
6362
exp_lidx = np.array([1, 2, 5, 6, 9, 10, 13, 14], dtype=np.intp)
6463
exp_ridx = np.array([0, 1, 0, 1, 0, 1, 0, 1], dtype=np.intp)
6564
tm.assert_index_equal(jidx, exp_idx)
@@ -96,8 +95,8 @@ def test_join_multi_wrong_order():
9695
# GH 25760
9796
# GH 28956
9897

99-
midx1 = pd.MultiIndex.from_product([[1, 2], [3, 4]], names=["a", "b"])
100-
midx2 = pd.MultiIndex.from_product([[1, 2], [3, 4]], names=["b", "a"])
98+
midx1 = MultiIndex.from_product([[1, 2], [3, 4]], names=["a", "b"])
99+
midx2 = MultiIndex.from_product([[1, 2], [3, 4]], names=["b", "a"])
101100

102101
join_idx, lidx, ridx = midx1.join(midx2, return_indexers=True)
103102

@@ -111,8 +110,8 @@ def test_join_multi_wrong_order():
111110
def test_join_multi_return_indexers():
112111
# GH 34074
113112

114-
midx1 = pd.MultiIndex.from_product([[1, 2], [3, 4], [5, 6]], names=["a", "b", "c"])
115-
midx2 = pd.MultiIndex.from_product([[1, 2], [3, 4]], names=["a", "b"])
113+
midx1 = MultiIndex.from_product([[1, 2], [3, 4], [5, 6]], names=["a", "b", "c"])
114+
midx2 = MultiIndex.from_product([[1, 2], [3, 4]], names=["a", "b"])
116115

117116
result = midx1.join(midx2, return_indexers=False)
118117
tm.assert_index_equal(result, midx1)

pandas/tests/indexes/multi/test_reindex.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_reindex_preserves_names_when_target_is_list_or_ndarray(idx):
5252
target = idx.copy()
5353
idx.names = target.names = [None, None]
5454

55-
other_dtype = pd.MultiIndex.from_product([[1, 2], [3, 4]])
55+
other_dtype = MultiIndex.from_product([[1, 2], [3, 4]])
5656

5757
# list & ndarray cases
5858
assert idx.reindex([])[0].names == [None, None]
@@ -73,14 +73,14 @@ def test_reindex_preserves_names_when_target_is_list_or_ndarray(idx):
7373

7474
def test_reindex_lvl_preserves_names_when_target_is_list_or_array():
7575
# GH7774
76-
idx = pd.MultiIndex.from_product([[0, 1], ["a", "b"]], names=["foo", "bar"])
76+
idx = MultiIndex.from_product([[0, 1], ["a", "b"]], names=["foo", "bar"])
7777
assert idx.reindex([], level=0)[0].names == ["foo", "bar"]
7878
assert idx.reindex([], level=1)[0].names == ["foo", "bar"]
7979

8080

8181
def test_reindex_lvl_preserves_type_if_target_is_empty_list_or_array():
8282
# GH7774
83-
idx = pd.MultiIndex.from_product([[0, 1], ["a", "b"]])
83+
idx = MultiIndex.from_product([[0, 1], ["a", "b"]])
8484
assert idx.reindex([], level=0)[0].levels[0].dtype.type == np.int64
8585
assert idx.reindex([], level=1)[0].levels[1].dtype.type == np.object_
8686

@@ -97,9 +97,9 @@ def test_reindex_base(idx):
9797

9898

9999
def test_reindex_non_unique():
100-
idx = pd.MultiIndex.from_tuples([(0, 0), (1, 1), (1, 1), (2, 2)])
100+
idx = MultiIndex.from_tuples([(0, 0), (1, 1), (1, 1), (2, 2)])
101101
a = pd.Series(np.arange(4), index=idx)
102-
new_idx = pd.MultiIndex.from_tuples([(0, 0), (1, 1), (2, 2)])
102+
new_idx = MultiIndex.from_tuples([(0, 0), (1, 1), (2, 2)])
103103

104104
msg = "cannot handle a non-unique multi-index!"
105105
with pytest.raises(ValueError, match=msg):

pandas/tests/indexes/multi/test_reshape.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ def test_insert(idx):
7878
+ [("test", 17), ("test", 18)]
7979
)
8080

81-
left = pd.Series(np.linspace(0, 10, 11), pd.MultiIndex.from_tuples(idx[:-2]))
81+
left = pd.Series(np.linspace(0, 10, 11), MultiIndex.from_tuples(idx[:-2]))
8282

8383
left.loc[("test", 17)] = 11
8484
left.loc[("test", 18)] = 12
8585

86-
right = pd.Series(np.linspace(0, 12, 13), pd.MultiIndex.from_tuples(idx))
86+
right = pd.Series(np.linspace(0, 12, 13), MultiIndex.from_tuples(idx))
8787

8888
tm.assert_series_equal(left, right)
8989

pandas/tests/indexes/multi/test_setops.py

+21-21
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def test_difference(idx, sort):
180180

181181
# name from non-empty array
182182
result = first.difference([("foo", "one")], sort=sort)
183-
expected = pd.MultiIndex.from_tuples(
183+
expected = MultiIndex.from_tuples(
184184
[("bar", "one"), ("baz", "two"), ("foo", "two"), ("qux", "one"), ("qux", "two")]
185185
)
186186
expected.names = first.names
@@ -193,7 +193,7 @@ def test_difference(idx, sort):
193193

194194
def test_difference_sort_special():
195195
# GH-24959
196-
idx = pd.MultiIndex.from_product([[1, 0], ["a", "b"]])
196+
idx = MultiIndex.from_product([[1, 0], ["a", "b"]])
197197
# sort=None, the default
198198
result = idx.difference([])
199199
tm.assert_index_equal(result, idx)
@@ -202,17 +202,17 @@ def test_difference_sort_special():
202202
@pytest.mark.xfail(reason="Not implemented.")
203203
def test_difference_sort_special_true():
204204
# TODO decide on True behaviour
205-
idx = pd.MultiIndex.from_product([[1, 0], ["a", "b"]])
205+
idx = MultiIndex.from_product([[1, 0], ["a", "b"]])
206206
result = idx.difference([], sort=True)
207-
expected = pd.MultiIndex.from_product([[0, 1], ["a", "b"]])
207+
expected = MultiIndex.from_product([[0, 1], ["a", "b"]])
208208
tm.assert_index_equal(result, expected)
209209

210210

211211
def test_difference_sort_incomparable():
212212
# GH-24959
213-
idx = pd.MultiIndex.from_product([[1, pd.Timestamp("2000"), 2], ["a", "b"]])
213+
idx = MultiIndex.from_product([[1, pd.Timestamp("2000"), 2], ["a", "b"]])
214214

215-
other = pd.MultiIndex.from_product([[3, pd.Timestamp("2000"), 4], ["c", "d"]])
215+
other = MultiIndex.from_product([[3, pd.Timestamp("2000"), 4], ["c", "d"]])
216216
# sort=None, the default
217217
# MultiIndex.difference deviates here from other difference
218218
# implementations in not catching the TypeError
@@ -226,8 +226,8 @@ def test_difference_sort_incomparable():
226226

227227

228228
def test_difference_sort_incomparable_true():
229-
idx = pd.MultiIndex.from_product([[1, pd.Timestamp("2000"), 2], ["a", "b"]])
230-
other = pd.MultiIndex.from_product([[3, pd.Timestamp("2000"), 4], ["c", "d"]])
229+
idx = MultiIndex.from_product([[1, pd.Timestamp("2000"), 2], ["a", "b"]])
230+
other = MultiIndex.from_product([[3, pd.Timestamp("2000"), 4], ["c", "d"]])
231231

232232
msg = "The 'sort' keyword only takes the values of None or False; True was passed."
233233
with pytest.raises(ValueError, match=msg):
@@ -332,23 +332,23 @@ def test_intersection_non_object(idx, sort):
332332

333333
def test_intersect_equal_sort():
334334
# GH-24959
335-
idx = pd.MultiIndex.from_product([[1, 0], ["a", "b"]])
335+
idx = MultiIndex.from_product([[1, 0], ["a", "b"]])
336336
tm.assert_index_equal(idx.intersection(idx, sort=False), idx)
337337
tm.assert_index_equal(idx.intersection(idx, sort=None), idx)
338338

339339

340340
@pytest.mark.xfail(reason="Not implemented.")
341341
def test_intersect_equal_sort_true():
342342
# TODO decide on True behaviour
343-
idx = pd.MultiIndex.from_product([[1, 0], ["a", "b"]])
344-
sorted_ = pd.MultiIndex.from_product([[0, 1], ["a", "b"]])
343+
idx = MultiIndex.from_product([[1, 0], ["a", "b"]])
344+
sorted_ = MultiIndex.from_product([[0, 1], ["a", "b"]])
345345
tm.assert_index_equal(idx.intersection(idx, sort=True), sorted_)
346346

347347

348348
@pytest.mark.parametrize("slice_", [slice(None), slice(0)])
349349
def test_union_sort_other_empty(slice_):
350350
# https://github.com/pandas-dev/pandas/issues/24959
351-
idx = pd.MultiIndex.from_product([[1, 0], ["a", "b"]])
351+
idx = MultiIndex.from_product([[1, 0], ["a", "b"]])
352352

353353
# default, sort=None
354354
other = idx[slice_]
@@ -364,16 +364,16 @@ def test_union_sort_other_empty(slice_):
364364
def test_union_sort_other_empty_sort(slice_):
365365
# TODO decide on True behaviour
366366
# # sort=True
367-
idx = pd.MultiIndex.from_product([[1, 0], ["a", "b"]])
367+
idx = MultiIndex.from_product([[1, 0], ["a", "b"]])
368368
other = idx[:0]
369369
result = idx.union(other, sort=True)
370-
expected = pd.MultiIndex.from_product([[0, 1], ["a", "b"]])
370+
expected = MultiIndex.from_product([[0, 1], ["a", "b"]])
371371
tm.assert_index_equal(result, expected)
372372

373373

374374
def test_union_sort_other_incomparable():
375375
# https://github.com/pandas-dev/pandas/issues/24959
376-
idx = pd.MultiIndex.from_product([[1, pd.Timestamp("2000")], ["a", "b"]])
376+
idx = MultiIndex.from_product([[1, pd.Timestamp("2000")], ["a", "b"]])
377377

378378
# default, sort=None
379379
with tm.assert_produces_warning(RuntimeWarning):
@@ -389,14 +389,14 @@ def test_union_sort_other_incomparable():
389389
def test_union_sort_other_incomparable_sort():
390390
# TODO decide on True behaviour
391391
# # sort=True
392-
idx = pd.MultiIndex.from_product([[1, pd.Timestamp("2000")], ["a", "b"]])
392+
idx = MultiIndex.from_product([[1, pd.Timestamp("2000")], ["a", "b"]])
393393
with pytest.raises(TypeError, match="Cannot compare"):
394394
idx.union(idx[:1], sort=True)
395395

396396

397397
def test_union_non_object_dtype_raises():
398398
# GH#32646 raise NotImplementedError instead of less-informative error
399-
mi = pd.MultiIndex.from_product([["a", "b"], [1, 2]])
399+
mi = MultiIndex.from_product([["a", "b"], [1, 2]])
400400

401401
idx = mi.levels[1]
402402

@@ -418,8 +418,8 @@ def test_union_empty_self_different_names():
418418
"method", ["union", "intersection", "difference", "symmetric_difference"]
419419
)
420420
def test_setops_disallow_true(method):
421-
idx1 = pd.MultiIndex.from_product([["a", "b"], [1, 2]])
422-
idx2 = pd.MultiIndex.from_product([["b", "c"], [1, 2]])
421+
idx1 = MultiIndex.from_product([["a", "b"], [1, 2]])
422+
idx2 = MultiIndex.from_product([["b", "c"], [1, 2]])
423423

424424
with pytest.raises(ValueError, match="The 'sort' keyword only takes"):
425425
getattr(idx1, method)(idx2, sort=True)
@@ -465,8 +465,8 @@ def test_intersect_with_duplicates(tuples, exp_tuples):
465465
)
466466
def test_maybe_match_names(data, names, expected):
467467
# GH#38323
468-
mi = pd.MultiIndex.from_tuples([], names=["a", "b"])
469-
mi2 = pd.MultiIndex.from_tuples([data], names=names)
468+
mi = MultiIndex.from_tuples([], names=["a", "b"])
469+
mi2 = MultiIndex.from_tuples([data], names=names)
470470
result = mi._maybe_match_names(mi2)
471471
assert result == expected
472472

pandas/tests/indexes/period/test_setops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def test_difference_freq(self, sort):
344344

345345
def test_intersection_equal_duplicates(self):
346346
# GH#38302
347-
idx = pd.period_range("2011-01-01", periods=2)
347+
idx = period_range("2011-01-01", periods=2)
348348
idx_dup = idx.append(idx)
349349
result = idx_dup.intersection(idx_dup)
350350
tm.assert_index_equal(result, idx)

0 commit comments

Comments
 (0)