Skip to content

Commit 739945e

Browse files
jan-muepull[bot]
authored andcommitted
fix inconsistent namespace usage (#37842)
1 parent bbff738 commit 739945e

File tree

10 files changed

+142
-144
lines changed

10 files changed

+142
-144
lines changed

pandas/tests/arithmetic/test_period.py

+63-65
Large diffs are not rendered by default.

pandas/tests/arrays/floating/test_construction.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
def test_uses_pandas_na():
11-
a = pd.array([1, None], dtype=pd.Float64Dtype())
11+
a = pd.array([1, None], dtype=Float64Dtype())
1212
assert a[1] is pd.NA
1313

1414

pandas/tests/arrays/sparse/test_dtype.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@ def test_update_dtype_raises(original, dtype, expected_error_msg):
200200

201201
def test_repr():
202202
# GH-34352
203-
result = str(pd.SparseDtype("int64", fill_value=0))
203+
result = str(SparseDtype("int64", fill_value=0))
204204
expected = "Sparse[int64, 0]"
205205
assert result == expected
206206

207-
result = str(pd.SparseDtype(object, fill_value="0"))
207+
result = str(SparseDtype(object, fill_value="0"))
208208
expected = "Sparse[object, '0']"
209209
assert result == expected

pandas/tests/arrays/test_datetimelike.py

+24-24
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def period_index(freqstr):
3131
the PeriodIndex behavior.
3232
"""
3333
# TODO: non-monotone indexes; NaTs, different start dates
34-
pi = pd.period_range(start=pd.Timestamp("2000-01-01"), periods=100, freq=freqstr)
34+
pi = pd.period_range(start=Timestamp("2000-01-01"), periods=100, freq=freqstr)
3535
return pi
3636

3737

@@ -45,7 +45,7 @@ def datetime_index(freqstr):
4545
the DatetimeIndex behavior.
4646
"""
4747
# TODO: non-monotone indexes; NaTs, different start dates, timezones
48-
dti = pd.date_range(start=pd.Timestamp("2000-01-01"), periods=100, freq=freqstr)
48+
dti = pd.date_range(start=Timestamp("2000-01-01"), periods=100, freq=freqstr)
4949
return dti
5050

5151

@@ -58,7 +58,7 @@ def timedelta_index():
5858
the TimedeltaIndex behavior.
5959
"""
6060
# TODO: flesh this out
61-
return pd.TimedeltaIndex(["1 Day", "3 Hours", "NaT"])
61+
return TimedeltaIndex(["1 Day", "3 Hours", "NaT"])
6262

6363

6464
class SharedTests:
@@ -139,7 +139,7 @@ def test_take(self):
139139

140140
tm.assert_index_equal(self.index_cls(result), expected)
141141

142-
@pytest.mark.parametrize("fill_value", [2, 2.0, pd.Timestamp.now().time])
142+
@pytest.mark.parametrize("fill_value", [2, 2.0, Timestamp.now().time])
143143
def test_take_fill_raises(self, fill_value):
144144
data = np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9
145145

@@ -539,7 +539,7 @@ def test_median(self, arr1d):
539539
class TestDatetimeArray(SharedTests):
540540
index_cls = pd.DatetimeIndex
541541
array_cls = DatetimeArray
542-
dtype = pd.Timestamp
542+
dtype = Timestamp
543543

544544
@pytest.fixture
545545
def arr1d(self, tz_naive_fixture, freqstr):
@@ -741,7 +741,7 @@ def test_take_fill_valid(self, arr1d):
741741
arr = arr1d
742742
dti = self.index_cls(arr1d)
743743

744-
now = pd.Timestamp.now().tz_localize(dti.tz)
744+
now = Timestamp.now().tz_localize(dti.tz)
745745
result = arr.take([-1, 1], allow_fill=True, fill_value=now)
746746
assert result[0] == now
747747

@@ -752,10 +752,10 @@ def test_take_fill_valid(self, arr1d):
752752

753753
with pytest.raises(TypeError, match=msg):
754754
# fill_value Period invalid
755-
arr.take([-1, 1], allow_fill=True, fill_value=pd.Period("2014Q1"))
755+
arr.take([-1, 1], allow_fill=True, fill_value=Period("2014Q1"))
756756

757757
tz = None if dti.tz is not None else "US/Eastern"
758-
now = pd.Timestamp.now().tz_localize(tz)
758+
now = Timestamp.now().tz_localize(tz)
759759
msg = "Cannot compare tz-naive and tz-aware datetime-like objects"
760760
with pytest.raises(TypeError, match=msg):
761761
# Timestamp with mismatched tz-awareness
@@ -828,22 +828,22 @@ def test_strftime_nat(self):
828828

829829

830830
class TestTimedeltaArray(SharedTests):
831-
index_cls = pd.TimedeltaIndex
831+
index_cls = TimedeltaIndex
832832
array_cls = TimedeltaArray
833833
dtype = pd.Timedelta
834834

835835
def test_from_tdi(self):
836-
tdi = pd.TimedeltaIndex(["1 Day", "3 Hours"])
836+
tdi = TimedeltaIndex(["1 Day", "3 Hours"])
837837
arr = TimedeltaArray(tdi)
838838
assert list(arr) == list(tdi)
839839

840840
# Check that Index.__new__ knows what to do with TimedeltaArray
841841
tdi2 = pd.Index(arr)
842-
assert isinstance(tdi2, pd.TimedeltaIndex)
842+
assert isinstance(tdi2, TimedeltaIndex)
843843
assert list(tdi2) == list(arr)
844844

845845
def test_astype_object(self):
846-
tdi = pd.TimedeltaIndex(["1 Day", "3 Hours"])
846+
tdi = TimedeltaIndex(["1 Day", "3 Hours"])
847847
arr = TimedeltaArray(tdi)
848848
asobj = arr.astype("O")
849849
assert isinstance(asobj, np.ndarray)
@@ -868,7 +868,7 @@ def test_total_seconds(self, timedelta_index):
868868

869869
tm.assert_numpy_array_equal(result, expected.values)
870870

871-
@pytest.mark.parametrize("propname", pd.TimedeltaIndex._field_ops)
871+
@pytest.mark.parametrize("propname", TimedeltaIndex._field_ops)
872872
def test_int_properties(self, timedelta_index, propname):
873873
tdi = timedelta_index
874874
arr = TimedeltaArray(tdi)
@@ -928,7 +928,7 @@ def test_take_fill_valid(self, timedelta_index):
928928
result = arr.take([-1, 1], allow_fill=True, fill_value=td1)
929929
assert result[0] == td1
930930

931-
now = pd.Timestamp.now()
931+
now = Timestamp.now()
932932
value = now
933933
msg = f"value should be a '{arr._scalar_type.__name__}' or 'NaT'. Got"
934934
with pytest.raises(TypeError, match=msg):
@@ -947,9 +947,9 @@ def test_take_fill_valid(self, timedelta_index):
947947

948948

949949
class TestPeriodArray(SharedTests):
950-
index_cls = pd.PeriodIndex
950+
index_cls = PeriodIndex
951951
array_cls = PeriodArray
952-
dtype = pd.Period
952+
dtype = Period
953953

954954
@pytest.fixture
955955
def arr1d(self, period_index):
@@ -962,7 +962,7 @@ def test_from_pi(self, arr1d):
962962

963963
# Check that Index.__new__ knows what to do with PeriodArray
964964
pi2 = pd.Index(arr)
965-
assert isinstance(pi2, pd.PeriodIndex)
965+
assert isinstance(pi2, PeriodIndex)
966966
assert list(pi2) == list(arr)
967967

968968
def test_astype_object(self, arr1d):
@@ -1075,7 +1075,7 @@ def test_strftime_nat(self):
10751075
"array,casting_nats",
10761076
[
10771077
(
1078-
pd.TimedeltaIndex(["1 Day", "3 Hours", "NaT"])._data,
1078+
TimedeltaIndex(["1 Day", "3 Hours", "NaT"])._data,
10791079
(pd.NaT, np.timedelta64("NaT", "ns")),
10801080
),
10811081
(
@@ -1099,7 +1099,7 @@ def test_casting_nat_setitem_array(array, casting_nats):
10991099
"array,non_casting_nats",
11001100
[
11011101
(
1102-
pd.TimedeltaIndex(["1 Day", "3 Hours", "NaT"])._data,
1102+
TimedeltaIndex(["1 Day", "3 Hours", "NaT"])._data,
11031103
(np.datetime64("NaT", "ns"), pd.NaT.value),
11041104
),
11051105
(
@@ -1164,8 +1164,8 @@ def test_to_numpy_extra(array):
11641164
"values",
11651165
[
11661166
pd.to_datetime(["2020-01-01", "2020-02-01"]),
1167-
pd.TimedeltaIndex([1, 2], unit="D"),
1168-
pd.PeriodIndex(["2020-01-01", "2020-02-01"], freq="D"),
1167+
TimedeltaIndex([1, 2], unit="D"),
1168+
PeriodIndex(["2020-01-01", "2020-02-01"], freq="D"),
11691169
],
11701170
)
11711171
@pytest.mark.parametrize(
@@ -1195,12 +1195,12 @@ def test_searchsorted_datetimelike_with_listlike(values, klass, as_index):
11951195
"values",
11961196
[
11971197
pd.to_datetime(["2020-01-01", "2020-02-01"]),
1198-
pd.TimedeltaIndex([1, 2], unit="D"),
1199-
pd.PeriodIndex(["2020-01-01", "2020-02-01"], freq="D"),
1198+
TimedeltaIndex([1, 2], unit="D"),
1199+
PeriodIndex(["2020-01-01", "2020-02-01"], freq="D"),
12001200
],
12011201
)
12021202
@pytest.mark.parametrize(
1203-
"arg", [[1, 2], ["a", "b"], [pd.Timestamp("2020-01-01", tz="Europe/London")] * 2]
1203+
"arg", [[1, 2], ["a", "b"], [Timestamp("2020-01-01", tz="Europe/London")] * 2]
12041204
)
12051205
def test_searchsorted_datetimelike_with_listlike_invalid_dtype(values, arg):
12061206
# https://github.com/pandas-dev/pandas/issues/32762

pandas/tests/indexes/categorical/test_formats.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
"""
44
import pandas._config.config as cf
55

6-
import pandas as pd
6+
from pandas import CategoricalIndex
77

88

99
class TestCategoricalIndexRepr:
1010
def test_string_categorical_index_repr(self):
1111
# short
12-
idx = pd.CategoricalIndex(["a", "bb", "ccc"])
12+
idx = CategoricalIndex(["a", "bb", "ccc"])
1313
expected = """CategoricalIndex(['a', 'bb', 'ccc'], categories=['a', 'bb', 'ccc'], ordered=False, dtype='category')""" # noqa
1414
assert repr(idx) == expected
1515

1616
# multiple lines
17-
idx = pd.CategoricalIndex(["a", "bb", "ccc"] * 10)
17+
idx = CategoricalIndex(["a", "bb", "ccc"] * 10)
1818
expected = """CategoricalIndex(['a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a',
1919
'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb',
2020
'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc'],
@@ -23,7 +23,7 @@ def test_string_categorical_index_repr(self):
2323
assert repr(idx) == expected
2424

2525
# truncated
26-
idx = pd.CategoricalIndex(["a", "bb", "ccc"] * 100)
26+
idx = CategoricalIndex(["a", "bb", "ccc"] * 100)
2727
expected = """CategoricalIndex(['a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a',
2828
...
2929
'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc'],
@@ -32,20 +32,20 @@ def test_string_categorical_index_repr(self):
3232
assert repr(idx) == expected
3333

3434
# larger categories
35-
idx = pd.CategoricalIndex(list("abcdefghijklmmo"))
35+
idx = CategoricalIndex(list("abcdefghijklmmo"))
3636
expected = """CategoricalIndex(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
3737
'm', 'm', 'o'],
3838
categories=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', ...], ordered=False, dtype='category')""" # noqa
3939

4040
assert repr(idx) == expected
4141

4242
# short
43-
idx = pd.CategoricalIndex(["あ", "いい", "ううう"])
43+
idx = CategoricalIndex(["あ", "いい", "ううう"])
4444
expected = """CategoricalIndex(['あ', 'いい', 'ううう'], categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category')""" # noqa
4545
assert repr(idx) == expected
4646

4747
# multiple lines
48-
idx = pd.CategoricalIndex(["あ", "いい", "ううう"] * 10)
48+
idx = CategoricalIndex(["あ", "いい", "ううう"] * 10)
4949
expected = """CategoricalIndex(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ',
5050
'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい',
5151
'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう'],
@@ -54,7 +54,7 @@ def test_string_categorical_index_repr(self):
5454
assert repr(idx) == expected
5555

5656
# truncated
57-
idx = pd.CategoricalIndex(["あ", "いい", "ううう"] * 100)
57+
idx = CategoricalIndex(["あ", "いい", "ううう"] * 100)
5858
expected = """CategoricalIndex(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ',
5959
...
6060
'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう'],
@@ -63,7 +63,7 @@ def test_string_categorical_index_repr(self):
6363
assert repr(idx) == expected
6464

6565
# larger categories
66-
idx = pd.CategoricalIndex(list("あいうえおかきくけこさしすせそ"))
66+
idx = CategoricalIndex(list("あいうえおかきくけこさしすせそ"))
6767
expected = """CategoricalIndex(['あ', 'い', 'う', 'え', 'お', 'か', 'き', 'く', 'け', 'こ', 'さ', 'し',
6868
'す', 'せ', 'そ'],
6969
categories=['あ', 'い', 'う', 'え', 'お', 'か', 'き', 'く', ...], ordered=False, dtype='category')""" # noqa
@@ -74,12 +74,12 @@ def test_string_categorical_index_repr(self):
7474
with cf.option_context("display.unicode.east_asian_width", True):
7575

7676
# short
77-
idx = pd.CategoricalIndex(["あ", "いい", "ううう"])
77+
idx = CategoricalIndex(["あ", "いい", "ううう"])
7878
expected = """CategoricalIndex(['あ', 'いい', 'ううう'], categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category')""" # noqa
7979
assert repr(idx) == expected
8080

8181
# multiple lines
82-
idx = pd.CategoricalIndex(["あ", "いい", "ううう"] * 10)
82+
idx = CategoricalIndex(["あ", "いい", "ううう"] * 10)
8383
expected = """CategoricalIndex(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい',
8484
'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう',
8585
'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい',
@@ -89,7 +89,7 @@ def test_string_categorical_index_repr(self):
8989
assert repr(idx) == expected
9090

9191
# truncated
92-
idx = pd.CategoricalIndex(["あ", "いい", "ううう"] * 100)
92+
idx = CategoricalIndex(["あ", "いい", "ううう"] * 100)
9393
expected = """CategoricalIndex(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい',
9494
'ううう', 'あ',
9595
...
@@ -100,7 +100,7 @@ def test_string_categorical_index_repr(self):
100100
assert repr(idx) == expected
101101

102102
# larger categories
103-
idx = pd.CategoricalIndex(list("あいうえおかきくけこさしすせそ"))
103+
idx = CategoricalIndex(list("あいうえおかきくけこさしすせそ"))
104104
expected = """CategoricalIndex(['あ', 'い', 'う', 'え', 'お', 'か', 'き', 'く', 'け', 'こ',
105105
'さ', 'し', 'す', 'せ', 'そ'],
106106
categories=['あ', 'い', 'う', 'え', 'お', 'か', 'き', 'く', ...], ordered=False, dtype='category')""" # noqa

0 commit comments

Comments
 (0)