Skip to content

Fix cases of inconsistent namespacing in tests #37842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 63 additions & 65 deletions pandas/tests/arithmetic/test_period.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pandas/tests/arrays/floating/test_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


def test_uses_pandas_na():
a = pd.array([1, None], dtype=pd.Float64Dtype())
a = pd.array([1, None], dtype=Float64Dtype())
assert a[1] is pd.NA


Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/arrays/sparse/test_dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ def test_update_dtype_raises(original, dtype, expected_error_msg):

def test_repr():
# GH-34352
result = str(pd.SparseDtype("int64", fill_value=0))
result = str(SparseDtype("int64", fill_value=0))
expected = "Sparse[int64, 0]"
assert result == expected

result = str(pd.SparseDtype(object, fill_value="0"))
result = str(SparseDtype(object, fill_value="0"))
expected = "Sparse[object, '0']"
assert result == expected
48 changes: 24 additions & 24 deletions pandas/tests/arrays/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def period_index(freqstr):
the PeriodIndex behavior.
"""
# TODO: non-monotone indexes; NaTs, different start dates
pi = pd.period_range(start=pd.Timestamp("2000-01-01"), periods=100, freq=freqstr)
pi = pd.period_range(start=Timestamp("2000-01-01"), periods=100, freq=freqstr)
return pi


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


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


class SharedTests:
Expand Down Expand Up @@ -139,7 +139,7 @@ def test_take(self):

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

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

Expand Down Expand Up @@ -539,7 +539,7 @@ def test_median(self, arr1d):
class TestDatetimeArray(SharedTests):
index_cls = pd.DatetimeIndex
array_cls = DatetimeArray
dtype = pd.Timestamp
dtype = Timestamp

@pytest.fixture
def arr1d(self, tz_naive_fixture, freqstr):
Expand Down Expand Up @@ -741,7 +741,7 @@ def test_take_fill_valid(self, arr1d):
arr = arr1d
dti = self.index_cls(arr1d)

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

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

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

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


class TestTimedeltaArray(SharedTests):
index_cls = pd.TimedeltaIndex
index_cls = TimedeltaIndex
array_cls = TimedeltaArray
dtype = pd.Timedelta

def test_from_tdi(self):
tdi = pd.TimedeltaIndex(["1 Day", "3 Hours"])
tdi = TimedeltaIndex(["1 Day", "3 Hours"])
arr = TimedeltaArray(tdi)
assert list(arr) == list(tdi)

# Check that Index.__new__ knows what to do with TimedeltaArray
tdi2 = pd.Index(arr)
assert isinstance(tdi2, pd.TimedeltaIndex)
assert isinstance(tdi2, TimedeltaIndex)
assert list(tdi2) == list(arr)

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

tm.assert_numpy_array_equal(result, expected.values)

@pytest.mark.parametrize("propname", pd.TimedeltaIndex._field_ops)
@pytest.mark.parametrize("propname", TimedeltaIndex._field_ops)
def test_int_properties(self, timedelta_index, propname):
tdi = timedelta_index
arr = TimedeltaArray(tdi)
Expand Down Expand Up @@ -928,7 +928,7 @@ def test_take_fill_valid(self, timedelta_index):
result = arr.take([-1, 1], allow_fill=True, fill_value=td1)
assert result[0] == td1

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


class TestPeriodArray(SharedTests):
index_cls = pd.PeriodIndex
index_cls = PeriodIndex
array_cls = PeriodArray
dtype = pd.Period
dtype = Period

@pytest.fixture
def arr1d(self, period_index):
Expand All @@ -962,7 +962,7 @@ def test_from_pi(self, arr1d):

# Check that Index.__new__ knows what to do with PeriodArray
pi2 = pd.Index(arr)
assert isinstance(pi2, pd.PeriodIndex)
assert isinstance(pi2, PeriodIndex)
assert list(pi2) == list(arr)

def test_astype_object(self, arr1d):
Expand Down Expand Up @@ -1075,7 +1075,7 @@ def test_strftime_nat(self):
"array,casting_nats",
[
(
pd.TimedeltaIndex(["1 Day", "3 Hours", "NaT"])._data,
TimedeltaIndex(["1 Day", "3 Hours", "NaT"])._data,
(pd.NaT, np.timedelta64("NaT", "ns")),
),
(
Expand All @@ -1099,7 +1099,7 @@ def test_casting_nat_setitem_array(array, casting_nats):
"array,non_casting_nats",
[
(
pd.TimedeltaIndex(["1 Day", "3 Hours", "NaT"])._data,
TimedeltaIndex(["1 Day", "3 Hours", "NaT"])._data,
(np.datetime64("NaT", "ns"), pd.NaT.value),
),
(
Expand Down Expand Up @@ -1164,8 +1164,8 @@ def test_to_numpy_extra(array):
"values",
[
pd.to_datetime(["2020-01-01", "2020-02-01"]),
pd.TimedeltaIndex([1, 2], unit="D"),
pd.PeriodIndex(["2020-01-01", "2020-02-01"], freq="D"),
TimedeltaIndex([1, 2], unit="D"),
PeriodIndex(["2020-01-01", "2020-02-01"], freq="D"),
],
)
@pytest.mark.parametrize(
Expand Down Expand Up @@ -1195,12 +1195,12 @@ def test_searchsorted_datetimelike_with_listlike(values, klass, as_index):
"values",
[
pd.to_datetime(["2020-01-01", "2020-02-01"]),
pd.TimedeltaIndex([1, 2], unit="D"),
pd.PeriodIndex(["2020-01-01", "2020-02-01"], freq="D"),
TimedeltaIndex([1, 2], unit="D"),
PeriodIndex(["2020-01-01", "2020-02-01"], freq="D"),
],
)
@pytest.mark.parametrize(
"arg", [[1, 2], ["a", "b"], [pd.Timestamp("2020-01-01", tz="Europe/London")] * 2]
"arg", [[1, 2], ["a", "b"], [Timestamp("2020-01-01", tz="Europe/London")] * 2]
)
def test_searchsorted_datetimelike_with_listlike_invalid_dtype(values, arg):
# https://github.com/pandas-dev/pandas/issues/32762
Expand Down
26 changes: 13 additions & 13 deletions pandas/tests/indexes/categorical/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
"""
import pandas._config.config as cf

import pandas as pd
from pandas import CategoricalIndex
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is because "CategoricalIndex" appears in some strings already



class TestCategoricalIndexRepr:
def test_string_categorical_index_repr(self):
# short
idx = pd.CategoricalIndex(["a", "bb", "ccc"])
idx = CategoricalIndex(["a", "bb", "ccc"])
expected = """CategoricalIndex(['a', 'bb', 'ccc'], categories=['a', 'bb', 'ccc'], ordered=False, dtype='category')""" # noqa
assert repr(idx) == expected

# multiple lines
idx = pd.CategoricalIndex(["a", "bb", "ccc"] * 10)
idx = CategoricalIndex(["a", "bb", "ccc"] * 10)
expected = """CategoricalIndex(['a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a',
'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb',
'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc'],
Expand All @@ -23,7 +23,7 @@ def test_string_categorical_index_repr(self):
assert repr(idx) == expected

# truncated
idx = pd.CategoricalIndex(["a", "bb", "ccc"] * 100)
idx = CategoricalIndex(["a", "bb", "ccc"] * 100)
expected = """CategoricalIndex(['a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a',
...
'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc'],
Expand All @@ -32,20 +32,20 @@ def test_string_categorical_index_repr(self):
assert repr(idx) == expected

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

assert repr(idx) == expected

# short
idx = pd.CategoricalIndex(["あ", "いい", "ううう"])
idx = CategoricalIndex(["あ", "いい", "ううう"])
expected = """CategoricalIndex(['あ', 'いい', 'ううう'], categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category')""" # noqa
assert repr(idx) == expected

# multiple lines
idx = pd.CategoricalIndex(["あ", "いい", "ううう"] * 10)
idx = CategoricalIndex(["あ", "いい", "ううう"] * 10)
expected = """CategoricalIndex(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ',
'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい',
'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう'],
Expand All @@ -54,7 +54,7 @@ def test_string_categorical_index_repr(self):
assert repr(idx) == expected

# truncated
idx = pd.CategoricalIndex(["あ", "いい", "ううう"] * 100)
idx = CategoricalIndex(["あ", "いい", "ううう"] * 100)
expected = """CategoricalIndex(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ',
...
'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう'],
Expand All @@ -63,7 +63,7 @@ def test_string_categorical_index_repr(self):
assert repr(idx) == expected

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

# short
idx = pd.CategoricalIndex(["あ", "いい", "ううう"])
idx = CategoricalIndex(["あ", "いい", "ううう"])
expected = """CategoricalIndex(['あ', 'いい', 'ううう'], categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category')""" # noqa
assert repr(idx) == expected

# multiple lines
idx = pd.CategoricalIndex(["あ", "いい", "ううう"] * 10)
idx = CategoricalIndex(["あ", "いい", "ううう"] * 10)
expected = """CategoricalIndex(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい',
'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう',
'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい',
Expand All @@ -89,7 +89,7 @@ def test_string_categorical_index_repr(self):
assert repr(idx) == expected

# truncated
idx = pd.CategoricalIndex(["あ", "いい", "ううう"] * 100)
idx = CategoricalIndex(["あ", "いい", "ううう"] * 100)
expected = """CategoricalIndex(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい',
'ううう', 'あ',
...
Expand All @@ -100,7 +100,7 @@ def test_string_categorical_index_repr(self):
assert repr(idx) == expected

# larger categories
idx = pd.CategoricalIndex(list("あいうえおかきくけこさしすせそ"))
idx = CategoricalIndex(list("あいうえおかきくけこさしすせそ"))
expected = """CategoricalIndex(['あ', 'い', 'う', 'え', 'お', 'か', 'き', 'く', 'け', 'こ',
'さ', 'し', 'す', 'せ', 'そ'],
categories=['あ', 'い', 'う', 'え', 'お', 'か', 'き', 'く', ...], ordered=False, dtype='category')""" # noqa
Expand Down
Loading