Skip to content
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
2 changes: 1 addition & 1 deletion pandas/tests/arrays/boolean/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def data():
"""Fixture returning boolean array with valid and missing values."""
return pd.array(
[True, False] * 4 + [np.nan] + [True, False] * 44 + [np.nan] + [True, False],
[True, False] * 2 + [np.nan] + [True, False] + [np.nan] + [True, False],
dtype="boolean",
)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/arrays/boolean/test_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def data():
"""Fixture returning boolean array with valid and missing data"""
return pd.array(
[True, False] * 4 + [np.nan] + [True, False] * 44 + [np.nan] + [True, False],
[True, False] * 2 + [np.nan] + [True, False] + [np.nan] + [True, False],
dtype="boolean",
)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/arrays/boolean/test_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def data():
"""Fixture returning boolean array, with valid and missing values."""
return pd.array(
[True, False] * 4 + [np.nan] + [True, False] * 44 + [np.nan] + [True, False],
[True, False] * 2 + [np.nan] + [True, False] + [np.nan] + [True, False],
dtype="boolean",
)

Expand Down
7 changes: 1 addition & 6 deletions pandas/tests/arrays/floating/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import numpy as np
import pytest

import pandas as pd
Expand All @@ -18,11 +17,7 @@ def dtype(request):
def data(dtype):
"""Fixture returning 'data' array according to parametrized float 'dtype'"""
return pd.array(
list(np.arange(0.1, 0.9, 0.1))
+ [pd.NA]
+ list(np.arange(1, 9.8, 0.1))
+ [pd.NA]
+ [9.9, 10.0],
[0.1, 0.2, 0.3, 0.4] + [pd.NA] + [1.0, 1.1] + [pd.NA] + [9.9, 10.0],
dtype=dtype,
)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/arrays/integer/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def data(dtype):
Used to test dtype conversion with and without missing values.
"""
return pd.array(
list(range(8)) + [pd.NA] + list(range(10, 98)) + [pd.NA] + [99, 100],
[0, 1, 2, 3] + [pd.NA] + [10, 11] + [pd.NA] + [99, 100],
dtype=dtype,
)

Expand Down
10 changes: 9 additions & 1 deletion pandas/tests/extension/base/casting.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,17 @@ def test_astype_str(self, data):
)
def test_astype_string(self, data, nullable_string_dtype):
# GH-33465, GH#45326 as of 2.0 we decode bytes instead of calling str(obj)
def as_str(x):
if isinstance(x, bytes):
return x.decode()
elif x is data.dtype.na_value:
return x
else:
return str(x)

result = pd.Series(data[:5]).astype(nullable_string_dtype)
expected = pd.Series(
[str(x) if not isinstance(x, bytes) else x.decode() for x in data[:5]],
[as_str(x) for x in data[:5]],
dtype=nullable_string_dtype,
)
tm.assert_series_equal(result, expected)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/extension/base/getitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def test_take_series(self, data):
result = s.take([0, -1])
expected = pd.Series(
data._from_sequence([data[0], data[len(data) - 1]], dtype=s.dtype),
index=range(0, 198, 99),
index=s.index.take([0, -1]),
)
tm.assert_series_equal(result, expected)

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/extension/base/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class BaseInterfaceTests:
# ------------------------------------------------------------------------

def test_len(self, data):
assert len(data) == 100
assert len(data) == 10

def test_size(self, data):
assert data.size == 100
assert data.size == 10

def test_ndim(self, data):
assert data.ndim == 1
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/extension/base/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def test_value_counts_default_dropna(self, data):

@pytest.mark.parametrize("dropna", [True, False])
def test_value_counts(self, all_data, dropna):
all_data = all_data[:10]
if dropna:
other = all_data[~all_data.isna()]
else:
Expand All @@ -52,7 +51,7 @@ def test_value_counts(self, all_data, dropna):

def test_value_counts_with_normalize(self, data):
# GH 33172
data = data[:10].unique()
data = data.unique()
values = np.array(data[~data.isna()])
ser = pd.Series(data, dtype=data.dtype)

Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/extension/base/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,7 @@ class BaseUnaryOpsTests(BaseOpsUtil):
def test_invert(self, data):
ser = pd.Series(data, name="name")
try:
# 10 is an arbitrary choice here, just avoid iterating over
# the whole array to trim test runtime
[~x for x in data[:10]]
[~x for x in data]
except TypeError:
# scalars don't support invert -> we don't expect the vectorized
# operation to succeed
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/extension/base/printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_array_repr(self, data, size):
if size == "small":
data = data[:5]
else:
data = type(data)._concat_same_type([data] * 5)
data = type(data)._concat_same_type([data] * 20)

result = repr(data)
assert type(data).__name__ in result
Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/extension/base/reshaping.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,9 @@ def test_stack(self, data, columns, future_stack):
)
@pytest.mark.parametrize("obj", ["series", "frame"])
def test_unstack(self, data, index, obj):
data = data[: len(index)]
final_length = min(len(index), len(data))
index = index[:final_length]
data = data[:final_length]
if obj == "series":
ser = pd.Series(data, index=index)
else:
Expand Down
14 changes: 7 additions & 7 deletions pandas/tests/extension/base/setitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ def test_setitem_iloc_scalar_mixed(self, data):

def test_setitem_iloc_scalar_single(self, data):
df = pd.DataFrame({"B": data})
df.iloc[10, 0] = data[1]
assert df.loc[10, "B"] == data[1]
df.iloc[9, 0] = data[1]
assert df.loc[9, "B"] == data[1]

def test_setitem_iloc_scalar_multiple_homogoneous(self, data):
df = pd.DataFrame({"A": data, "B": data})
df.iloc[10, 1] = data[1]
assert df.loc[10, "B"] == data[1]
df.iloc[9, 1] = data[1]
assert df.loc[9, "B"] == data[1]

@pytest.mark.parametrize(
"mask",
Expand Down Expand Up @@ -281,9 +281,9 @@ def test_setitem_mask_broadcast(self, data, setter):
else: # __setitem__
target = ser

target[mask] = data[10]
assert ser[0] == data[10]
assert ser[1] == data[10]
target[mask] = data[9]
assert ser[0] == data[9]
assert ser[1] == data[9]

def test_setitem_expand_columns(self, data):
df = pd.DataFrame({"A": data})
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/extension/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def dtype():
@pytest.fixture
def data():
"""
Length-100 array for this type.
Length-10 array for this type.
* data[0] and data[1] should both be non missing
* data[0] and data[1] should not be equal
Expand All @@ -25,7 +25,7 @@ def data():
@pytest.fixture
def data_for_twos(dtype):
"""
Length-100 array in which all the elements are two.
Length-10 array in which all the elements are two.
Call pytest.skip in your fixture if the dtype does not support divmod.
"""
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/extension/decimal/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ def to_decimal(values, context=None):
return DecimalArray([decimal.Decimal(x) for x in values], context=context)


def make_data():
return [decimal.Decimal(val) for val in np.random.default_rng(2).random(100)]
def make_data(n: int):
return [decimal.Decimal(val) for val in np.random.default_rng(2).random(n)]


DecimalArray._add_arithmetic_ops()
10 changes: 5 additions & 5 deletions pandas/tests/extension/decimal/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ def dtype():

@pytest.fixture
def data():
return DecimalArray(make_data())
return DecimalArray(make_data(10))


@pytest.fixture
def data_for_twos():
return DecimalArray([decimal.Decimal(2) for _ in range(100)])
return DecimalArray([decimal.Decimal(2) for _ in range(10)])


@pytest.fixture
Expand Down Expand Up @@ -340,7 +340,7 @@ def test_groupby_agg():
# Ensure that the result of agg is inferred to be decimal dtype
# https://github.com/pandas-dev/pandas/issues/29141

data = make_data()[:5]
data = make_data(5)
df = pd.DataFrame(
{"id1": [0, 0, 0, 1, 1], "id2": [0, 1, 0, 1, 1], "decimals": DecimalArray(data)}
)
Expand Down Expand Up @@ -377,7 +377,7 @@ def DecimalArray__my_sum(self):

monkeypatch.setattr(DecimalArray, "my_sum", DecimalArray__my_sum, raising=False)

data = make_data()[:5]
data = make_data(5)
df = pd.DataFrame({"id": [0, 0, 0, 1, 1], "decimals": DecimalArray(data)})
expected = pd.Series(to_decimal([data[0] + data[1] + data[2], data[3] + data[4]]))

Expand All @@ -399,7 +399,7 @@ def DecimalArray__array__(self, dtype=None):

monkeypatch.setattr(DecimalArray, "__array__", DecimalArray__array__, raising=False)

data = make_data()
data = make_data(10)
s = pd.Series(DecimalArray(data))
df = pd.DataFrame({"a": s, "b": range(len(s))})

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/extension/json/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def _pad_or_backfill(self, *, method, limit=None, copy=True):
return super()._pad_or_backfill(method=method, limit=limit, copy=copy)


def make_data():
def make_data(n: int):
# TODO: Use a regular dict. See _NDFrameIndexer._setitem_with_indexer
rng = np.random.default_rng(2)
return [
Expand All @@ -265,5 +265,5 @@ def make_data():
for _ in range(rng.integers(0, 10))
]
)
for _ in range(100)
for _ in range(n)
]
11 changes: 5 additions & 6 deletions pandas/tests/extension/json/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def dtype():

@pytest.fixture
def data():
"""Length-100 PeriodArray for semantics test."""
data = make_data()
"""Length-10 JSONArray for semantics test."""
data = make_data(10)

# Why the while loop? NumPy is unable to construct an ndarray from
# equal-length ndarrays. Many of our operations involve coercing the
Expand All @@ -36,7 +36,7 @@ def data():
# the first two elements, so that's what we'll check.

while len(data[0]) == len(data[1]):
data = make_data()
data = make_data(10)

return JSONArray(data)

Expand Down Expand Up @@ -190,9 +190,8 @@ def test_ffill_limit_area(
)

def test_value_counts(self, all_data, dropna, request):
if len(all_data) == 100 or dropna:
mark = pytest.mark.xfail(reason="unhashable")
request.applymarker(mark)
if len(all_data) == 10 or dropna:
request.applymarker(unhashable)
super().test_value_counts(all_data, dropna)

@unhashable
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/extension/list/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ def _concat_same_type(cls, to_concat):
return cls(data)


def make_data():
def make_data(n: int):
# TODO: Use a regular dict. See _NDFrameIndexer._setitem_with_indexer
rng = np.random.default_rng(2)
data = np.empty(100, dtype=object)
data = np.empty(n, dtype=object)
data[:] = [
[rng.choice(list(string.ascii_letters)) for _ in range(rng.integers(0, 10))]
for _ in range(100)
for _ in range(n)
]
return data
6 changes: 3 additions & 3 deletions pandas/tests/extension/list/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ def dtype():

@pytest.fixture
def data():
"""Length-100 ListArray for semantics test."""
data = make_data()
"""Length-10 ListArray for semantics test."""
data = make_data(10)

while len(data[0]) == len(data[1]):
data = make_data()
data = make_data(10)

return ListArray(data)

Expand Down
Loading
Loading