Skip to content

Commit e3492a7

Browse files
committed
STYLE: Inconsistent namespace - Indexes (pandas-dev#39992)
1 parent 0c18cc6 commit e3492a7

14 files changed

+66
-67
lines changed

pandas/tests/indexes/common.py

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

@@ -611,7 +611,7 @@ def test_map(self):
611611
index = self.create_index()
612612

613613
# we don't infer UInt64
614-
if isinstance(index, pd.UInt64Index):
614+
if isinstance(index, UInt64Index):
615615
expected = index.astype("int64")
616616
else:
617617
expected = index
@@ -630,13 +630,13 @@ def test_map(self):
630630
def test_map_dictlike(self, mapper):
631631

632632
index = self.create_index()
633-
if isinstance(index, pd.CategoricalIndex):
633+
if isinstance(index, CategoricalIndex):
634634
pytest.skip(f"skipping tests for {type(index)}")
635635

636636
identity = mapper(index.values, index)
637637

638638
# we don't infer to UInt64 for a dict
639-
if isinstance(index, pd.UInt64Index) and isinstance(identity, dict):
639+
if isinstance(index, UInt64Index) and isinstance(identity, dict):
640640
expected = index.astype("int64")
641641
else:
642642
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
@@ -506,8 +506,8 @@ def test_construction_outofbounds(self):
506506
def test_construction_with_ndarray(self):
507507
# GH 5152
508508
dates = [datetime(2013, 10, 7), datetime(2013, 10, 8), datetime(2013, 10, 9)]
509-
data = DatetimeIndex(dates, freq=pd.offsets.BDay()).values
510-
result = DatetimeIndex(data, freq=pd.offsets.BDay())
509+
data = DatetimeIndex(dates, freq=offsets.BDay()).values
510+
result = DatetimeIndex(data, freq=offsets.BDay())
511511
expected = DatetimeIndex(["2013-10-07", "2013-10-08", "2013-10-09"], freq="B")
512512
tm.assert_index_equal(result, expected)
513513

pandas/tests/indexes/datetimes/test_date_range.py

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

10101010
def test_date_range_with_custom_holidays():
10111011
# GH 30593
1012-
freq = pd.offsets.CustomBusinessHour(start="15:00", holidays=["2020-11-26"])
1012+
freq = offsets.CustomBusinessHour(start="15:00", holidays=["2020-11-26"])
10131013
result = date_range(start="2020-11-25 15:00", periods=4, freq=freq)
10141014
expected = DatetimeIndex(
10151015
[

pandas/tests/indexes/datetimes/test_datetime.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def test_asarray_tz_naive(self):
210210
# optionally, object
211211
result = np.asarray(idx, dtype=object)
212212

213-
expected = np.array([pd.Timestamp("2000-01-01"), pd.Timestamp("2000-01-02")])
213+
expected = np.array([Timestamp("2000-01-01"), Timestamp("2000-01-02")])
214214
tm.assert_numpy_array_equal(result, expected)
215215

216216
def test_asarray_tz_aware(self):
@@ -228,7 +228,7 @@ def test_asarray_tz_aware(self):
228228

229229
# Future behavior with no warning
230230
expected = np.array(
231-
[pd.Timestamp("2000-01-01", tz=tz), pd.Timestamp("2000-01-02", tz=tz)]
231+
[Timestamp("2000-01-01", tz=tz), Timestamp("2000-01-02", tz=tz)]
232232
)
233233
result = np.asarray(idx, dtype=object)
234234

pandas/tests/indexes/multi/test_conversion.py

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

8888
def test_to_frame_dtype_fidelity():
8989
# GH 22420
90-
mi = pd.MultiIndex.from_arrays(
90+
mi = MultiIndex.from_arrays(
9191
[
9292
pd.date_range("19910905", periods=6, tz="US/Eastern"),
9393
[1, 1, 1, 2, 2, 2],
@@ -116,7 +116,7 @@ def test_to_frame_dtype_fidelity():
116116
def test_to_frame_resulting_column_order():
117117
# GH 22420
118118
expected = ["z", 0, "a"]
119-
mi = pd.MultiIndex.from_arrays(
119+
mi = MultiIndex.from_arrays(
120120
[["a", "b", "c"], ["x", "y", "z"], ["q", "w", "e"]], names=expected
121121
)
122122
result = mi.to_frame().columns.tolist()

pandas/tests/indexes/multi/test_drop.py

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

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

pandas/tests/indexes/multi/test_equivalence.py

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

220220
def test_equals_missing_values_differently_sorted():
221221
# GH#38439
222-
mi1 = pd.MultiIndex.from_tuples([(81.0, np.nan), (np.nan, np.nan)])
223-
mi2 = pd.MultiIndex.from_tuples([(np.nan, np.nan), (81.0, np.nan)])
222+
mi1 = MultiIndex.from_tuples([(81.0, np.nan), (np.nan, np.nan)])
223+
mi2 = MultiIndex.from_tuples([(np.nan, np.nan), (81.0, np.nan)])
224224
assert not mi1.equals(mi2)
225225

226-
mi2 = pd.MultiIndex.from_tuples([(81.0, np.nan), (np.nan, np.nan)])
226+
mi2 = MultiIndex.from_tuples([(81.0, np.nan), (np.nan, np.nan)])
227227
assert mi1.equals(mi2)
228228

229229

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 Index, MultiIndex
65
import pandas._testing as tm
76

@@ -51,12 +50,12 @@ def test_join_self(idx, join_type):
5150

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

5756
# inner
5857
jidx, lidx, ridx = midx.join(idx, how="inner", return_indexers=True)
59-
exp_idx = pd.MultiIndex.from_product([np.arange(4), [1, 2]], names=["a", "b"])
58+
exp_idx = MultiIndex.from_product([np.arange(4), [1, 2]], names=["a", "b"])
6059
exp_lidx = np.array([1, 2, 5, 6, 9, 10, 13, 14], dtype=np.intp)
6160
exp_ridx = np.array([0, 1, 0, 1, 0, 1, 0, 1], dtype=np.intp)
6261
tm.assert_index_equal(jidx, exp_idx)
@@ -93,8 +92,8 @@ def test_join_multi_wrong_order():
9392
# GH 25760
9493
# GH 28956
9594

96-
midx1 = pd.MultiIndex.from_product([[1, 2], [3, 4]], names=["a", "b"])
97-
midx2 = pd.MultiIndex.from_product([[1, 2], [3, 4]], names=["b", "a"])
95+
midx1 = MultiIndex.from_product([[1, 2], [3, 4]], names=["a", "b"])
96+
midx2 = MultiIndex.from_product([[1, 2], [3, 4]], names=["b", "a"])
9897

9998
join_idx, lidx, ridx = midx1.join(midx2, return_indexers=True)
10099

@@ -108,8 +107,8 @@ def test_join_multi_wrong_order():
108107
def test_join_multi_return_indexers():
109108
# GH 34074
110109

111-
midx1 = pd.MultiIndex.from_product([[1, 2], [3, 4], [5, 6]], names=["a", "b", "c"])
112-
midx2 = pd.MultiIndex.from_product([[1, 2], [3, 4]], names=["a", "b"])
110+
midx1 = MultiIndex.from_product([[1, 2], [3, 4], [5, 6]], names=["a", "b", "c"])
111+
midx2 = MultiIndex.from_product([[1, 2], [3, 4]], names=["a", "b"])
113112

114113
result = midx1.join(midx2, return_indexers=False)
115114
tm.assert_index_equal(result, midx1)

pandas/tests/indexes/multi/test_reindex.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_reindex_preserves_names_when_target_is_list_or_ndarray(idx):
4949
target = idx.copy()
5050
idx.names = target.names = [None, None]
5151

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

5454
# list & ndarray cases
5555
assert idx.reindex([])[0].names == [None, None]
@@ -70,14 +70,14 @@ def test_reindex_preserves_names_when_target_is_list_or_ndarray(idx):
7070

7171
def test_reindex_lvl_preserves_names_when_target_is_list_or_array():
7272
# GH7774
73-
idx = pd.MultiIndex.from_product([[0, 1], ["a", "b"]], names=["foo", "bar"])
73+
idx = MultiIndex.from_product([[0, 1], ["a", "b"]], names=["foo", "bar"])
7474
assert idx.reindex([], level=0)[0].names == ["foo", "bar"]
7575
assert idx.reindex([], level=1)[0].names == ["foo", "bar"]
7676

7777

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

@@ -94,9 +94,9 @@ def test_reindex_base(idx):
9494

9595

9696
def test_reindex_non_unique():
97-
idx = pd.MultiIndex.from_tuples([(0, 0), (1, 1), (1, 1), (2, 2)])
97+
idx = MultiIndex.from_tuples([(0, 0), (1, 1), (1, 1), (2, 2)])
9898
a = pd.Series(np.arange(4), index=idx)
99-
new_idx = pd.MultiIndex.from_tuples([(0, 0), (1, 1), (2, 2)])
99+
new_idx = MultiIndex.from_tuples([(0, 0), (1, 1), (2, 2)])
100100

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

pandas/tests/indexes/multi/test_reshape.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ def test_insert(idx):
7575
+ [("test", 17), ("test", 18)]
7676
)
7777

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

8080
left.loc[("test", 17)] = 11
8181
left.loc[("test", 18)] = 12
8282

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

8585
tm.assert_series_equal(left, right)
8686

pandas/tests/indexes/multi/test_setops.py

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

177177
# name from non-empty array
178178
result = first.difference([("foo", "one")], sort=sort)
179-
expected = pd.MultiIndex.from_tuples(
179+
expected = MultiIndex.from_tuples(
180180
[("bar", "one"), ("baz", "two"), ("foo", "two"), ("qux", "one"), ("qux", "two")]
181181
)
182182
expected.names = first.names
@@ -189,7 +189,7 @@ def test_difference(idx, sort):
189189

190190
def test_difference_sort_special():
191191
# GH-24959
192-
idx = pd.MultiIndex.from_product([[1, 0], ["a", "b"]])
192+
idx = MultiIndex.from_product([[1, 0], ["a", "b"]])
193193
# sort=None, the default
194194
result = idx.difference([])
195195
tm.assert_index_equal(result, idx)
@@ -198,17 +198,17 @@ def test_difference_sort_special():
198198
@pytest.mark.xfail(reason="Not implemented.")
199199
def test_difference_sort_special_true():
200200
# TODO decide on True behaviour
201-
idx = pd.MultiIndex.from_product([[1, 0], ["a", "b"]])
201+
idx = MultiIndex.from_product([[1, 0], ["a", "b"]])
202202
result = idx.difference([], sort=True)
203-
expected = pd.MultiIndex.from_product([[0, 1], ["a", "b"]])
203+
expected = MultiIndex.from_product([[0, 1], ["a", "b"]])
204204
tm.assert_index_equal(result, expected)
205205

206206

207207
def test_difference_sort_incomparable():
208208
# GH-24959
209-
idx = pd.MultiIndex.from_product([[1, pd.Timestamp("2000"), 2], ["a", "b"]])
209+
idx = MultiIndex.from_product([[1, pd.Timestamp("2000"), 2], ["a", "b"]])
210210

211-
other = pd.MultiIndex.from_product([[3, pd.Timestamp("2000"), 4], ["c", "d"]])
211+
other = MultiIndex.from_product([[3, pd.Timestamp("2000"), 4], ["c", "d"]])
212212
# sort=None, the default
213213
# MultiIndex.difference deviates here from other difference
214214
# implementations in not catching the TypeError
@@ -222,8 +222,8 @@ def test_difference_sort_incomparable():
222222

223223

224224
def test_difference_sort_incomparable_true():
225-
idx = pd.MultiIndex.from_product([[1, pd.Timestamp("2000"), 2], ["a", "b"]])
226-
other = pd.MultiIndex.from_product([[3, pd.Timestamp("2000"), 4], ["c", "d"]])
225+
idx = MultiIndex.from_product([[1, pd.Timestamp("2000"), 2], ["a", "b"]])
226+
other = MultiIndex.from_product([[3, pd.Timestamp("2000"), 4], ["c", "d"]])
227227

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

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

335335

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

343343

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

349349
# default, sort=None
350350
other = idx[slice_]
@@ -360,16 +360,16 @@ def test_union_sort_other_empty(slice_):
360360
def test_union_sort_other_empty_sort(slice_):
361361
# TODO decide on True behaviour
362362
# # sort=True
363-
idx = pd.MultiIndex.from_product([[1, 0], ["a", "b"]])
363+
idx = MultiIndex.from_product([[1, 0], ["a", "b"]])
364364
other = idx[:0]
365365
result = idx.union(other, sort=True)
366-
expected = pd.MultiIndex.from_product([[0, 1], ["a", "b"]])
366+
expected = MultiIndex.from_product([[0, 1], ["a", "b"]])
367367
tm.assert_index_equal(result, expected)
368368

369369

370370
def test_union_sort_other_incomparable():
371371
# https://github.com/pandas-dev/pandas/issues/24959
372-
idx = pd.MultiIndex.from_product([[1, pd.Timestamp("2000")], ["a", "b"]])
372+
idx = MultiIndex.from_product([[1, pd.Timestamp("2000")], ["a", "b"]])
373373

374374
# default, sort=None
375375
with tm.assert_produces_warning(RuntimeWarning):
@@ -385,14 +385,14 @@ def test_union_sort_other_incomparable():
385385
def test_union_sort_other_incomparable_sort():
386386
# TODO decide on True behaviour
387387
# # sort=True
388-
idx = pd.MultiIndex.from_product([[1, pd.Timestamp("2000")], ["a", "b"]])
388+
idx = MultiIndex.from_product([[1, pd.Timestamp("2000")], ["a", "b"]])
389389
with pytest.raises(TypeError, match="Cannot compare"):
390390
idx.union(idx[:1], sort=True)
391391

392392

393393
def test_union_non_object_dtype_raises():
394394
# GH#32646 raise NotImplementedError instead of less-informative error
395-
mi = pd.MultiIndex.from_product([["a", "b"], [1, 2]])
395+
mi = MultiIndex.from_product([["a", "b"], [1, 2]])
396396

397397
idx = mi.levels[1]
398398

@@ -414,8 +414,8 @@ def test_union_empty_self_different_names():
414414
"method", ["union", "intersection", "difference", "symmetric_difference"]
415415
)
416416
def test_setops_disallow_true(method):
417-
idx1 = pd.MultiIndex.from_product([["a", "b"], [1, 2]])
418-
idx2 = pd.MultiIndex.from_product([["b", "c"], [1, 2]])
417+
idx1 = MultiIndex.from_product([["a", "b"], [1, 2]])
418+
idx2 = MultiIndex.from_product([["b", "c"], [1, 2]])
419419

420420
with pytest.raises(ValueError, match="The 'sort' keyword only takes"):
421421
getattr(idx1, method)(idx2, sort=True)
@@ -461,8 +461,8 @@ def test_intersect_with_duplicates(tuples, exp_tuples):
461461
)
462462
def test_maybe_match_names(data, names, expected):
463463
# GH#38323
464-
mi = pd.MultiIndex.from_tuples([], names=["a", "b"])
465-
mi2 = pd.MultiIndex.from_tuples([data], names=names)
464+
mi = MultiIndex.from_tuples([], names=["a", "b"])
465+
mi2 = MultiIndex.from_tuples([data], names=names)
466466
result = mi._maybe_match_names(mi2)
467467
assert result == expected
468468

pandas/tests/indexes/period/test_setops.py

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

341341
def test_intersection_equal_duplicates(self):
342342
# GH#38302
343-
idx = pd.period_range("2011-01-01", periods=2)
343+
idx = period_range("2011-01-01", periods=2)
344344
idx_dup = idx.append(idx)
345345
result = idx_dup.intersection(idx_dup)
346346
tm.assert_index_equal(result, idx)

0 commit comments

Comments
 (0)