Skip to content

Commit 2b631b5

Browse files
author
MomIsBestFriend
committed
Merge remote-tracking branch 'upstream/master' into CLN-libs
2 parents e151183 + 571a73b commit 2b631b5

30 files changed

+506
-485
lines changed

ci/code_checks.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,7 @@ fi
259259
if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
260260

261261
MSG='Doctests frame.py' ; echo $MSG
262-
pytest -q --doctest-modules pandas/core/frame.py \
263-
-k" -itertuples -join -reindex -reindex_axis -round"
262+
pytest -q --doctest-modules pandas/core/frame.py
264263
RET=$(($RET + $?)) ; echo $MSG "DONE"
265264

266265
MSG='Doctests series.py' ; echo $MSG
@@ -294,8 +293,7 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
294293
MSG='Doctests interval classes' ; echo $MSG
295294
pytest -q --doctest-modules \
296295
pandas/core/indexes/interval.py \
297-
pandas/core/arrays/interval.py \
298-
-k"-from_arrays -from_breaks -from_intervals -from_tuples -set_closed -to_tuples -interval_range"
296+
pandas/core/arrays/interval.py
299297
RET=$(($RET + $?)) ; echo $MSG "DONE"
300298

301299
MSG='Doctests arrays'; echo $MSG

pandas/conftest.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from pandas import DataFrame
1818
import pandas._testing as tm
1919
from pandas.core import ops
20+
from pandas.core.indexes.api import Index, MultiIndex
2021

2122
hypothesis.settings.register_profile(
2223
"ci",
@@ -953,3 +954,69 @@ def __len__(self):
953954
return self._data.__len__()
954955

955956
return TestNonDictMapping
957+
958+
959+
indices_dict = {
960+
"unicode": tm.makeUnicodeIndex(100),
961+
"string": tm.makeStringIndex(100),
962+
"datetime": tm.makeDateIndex(100),
963+
"datetime-tz": tm.makeDateIndex(100, tz="US/Pacific"),
964+
"period": tm.makePeriodIndex(100),
965+
"timedelta": tm.makeTimedeltaIndex(100),
966+
"int": tm.makeIntIndex(100),
967+
"uint": tm.makeUIntIndex(100),
968+
"range": tm.makeRangeIndex(100),
969+
"float": tm.makeFloatIndex(100),
970+
"bool": tm.makeBoolIndex(2),
971+
"categorical": tm.makeCategoricalIndex(100),
972+
"interval": tm.makeIntervalIndex(100),
973+
"empty": Index([]),
974+
"tuples": MultiIndex.from_tuples(zip(["foo", "bar", "baz"], [1, 2, 3])),
975+
"repeats": Index([0, 0, 1, 1, 2, 2]),
976+
}
977+
978+
979+
@pytest.fixture(params=indices_dict.keys())
980+
def indices(request):
981+
# copy to avoid mutation, e.g. setting .name
982+
return indices_dict[request.param].copy()
983+
984+
985+
def _create_series(index):
986+
""" Helper for the _series dict """
987+
size = len(index)
988+
data = np.random.randn(size)
989+
return pd.Series(data, index=index, name="a")
990+
991+
992+
_series = {
993+
f"series-with-{index_id}-index": _create_series(index)
994+
for index_id, index in indices_dict.items()
995+
}
996+
997+
998+
_narrow_dtypes = [
999+
np.float16,
1000+
np.float32,
1001+
np.int8,
1002+
np.int16,
1003+
np.int32,
1004+
np.uint8,
1005+
np.uint16,
1006+
np.uint32,
1007+
]
1008+
_narrow_series = {
1009+
f"{dtype.__name__}-series": tm.makeFloatSeries(name="a").astype(dtype)
1010+
for dtype in _narrow_dtypes
1011+
}
1012+
1013+
_index_or_series_objs = {**indices_dict, **_series, **_narrow_series}
1014+
1015+
1016+
@pytest.fixture(params=_index_or_series_objs.keys())
1017+
def index_or_series_obj(request):
1018+
"""
1019+
Fixture for tests on indexes, series and series with a narrow dtype
1020+
copy to avoid mutation, e.g. setting .name
1021+
"""
1022+
return _index_or_series_objs[request.param].copy(deep=True)

pandas/io/sas/sas_xport.py

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@
7979
Return XportReader object for reading file incrementally."""
8080

8181

82-
_read_sas_doc = """Read a SAS file into a DataFrame.
82+
_read_sas_doc = f"""Read a SAS file into a DataFrame.
8383
84-
%(_base_params_doc)s
85-
%(_format_params_doc)s
86-
%(_params2_doc)s
87-
%(_iterator_doc)s
84+
{_base_params_doc}
85+
{_format_params_doc}
86+
{_params2_doc}
87+
{_iterator_doc}
8888
8989
Returns
9090
-------
@@ -102,31 +102,21 @@
102102
>>> for chunk in itr:
103103
>>> do_something(chunk)
104104
105-
""" % {
106-
"_base_params_doc": _base_params_doc,
107-
"_format_params_doc": _format_params_doc,
108-
"_params2_doc": _params2_doc,
109-
"_iterator_doc": _iterator_doc,
110-
}
111-
105+
"""
112106

113-
_xport_reader_doc = """\
107+
_xport_reader_doc = f"""\
114108
Class for reading SAS Xport files.
115109
116-
%(_base_params_doc)s
117-
%(_params2_doc)s
110+
{_base_params_doc}
111+
{_params2_doc}
118112
119113
Attributes
120114
----------
121115
member_info : list
122116
Contains information about the file
123117
fields : list
124118
Contains information about the variables in the file
125-
""" % {
126-
"_base_params_doc": _base_params_doc,
127-
"_params2_doc": _params2_doc,
128-
}
129-
119+
"""
130120

131121
_read_method_doc = """\
132122
Read observations from SAS Xport file, returning as data frame.
@@ -185,7 +175,7 @@ def _handle_truncated_float_vec(vec, nbytes):
185175

186176
if nbytes != 8:
187177
vec1 = np.zeros(len(vec), np.dtype("S8"))
188-
dtype = np.dtype("S%d,S%d" % (nbytes, 8 - nbytes))
178+
dtype = np.dtype(f"S{nbytes},S{8 - nbytes}")
189179
vec2 = vec1.view(dtype=dtype)
190180
vec2["f0"] = vec
191181
return vec2

pandas/tests/arrays/test_integer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,10 @@ def test_error(self, data, all_arithmetic_operators):
347347
# TODO(extension)
348348
# rpow with a datetimelike coerces the integer array incorrectly
349349
msg = (
350-
r"(:?can only perform ops with numeric values)"
351-
r"|(:?cannot perform .* with this index type: DatetimeArray)"
352-
r"|(:?Addition/subtraction of integers and integer-arrays"
353-
r" with DatetimeArray is no longer supported. *)"
350+
"can only perform ops with numeric values|"
351+
"cannot perform .* with this index type: DatetimeArray|"
352+
"Addition/subtraction of integers and integer-arrays "
353+
"with DatetimeArray is no longer supported. *"
354354
)
355355
with pytest.raises(TypeError, match=msg):
356356
ops(pd.Series(pd.date_range("20180101", periods=len(s))))

pandas/tests/base/test_ops.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,26 +109,26 @@ def test_binary_ops(klass, op_name, op):
109109
assert expected_str in getattr(klass, "r" + op_name).__doc__
110110

111111

112-
class TestTranspose(Ops):
112+
class TestTranspose:
113113
errmsg = "the 'axes' parameter is not supported"
114114

115-
def test_transpose(self):
116-
for obj in self.objs:
117-
tm.assert_equal(obj.transpose(), obj)
115+
def test_transpose(self, index_or_series_obj):
116+
obj = index_or_series_obj
117+
tm.assert_equal(obj.transpose(), obj)
118118

119-
def test_transpose_non_default_axes(self):
120-
for obj in self.objs:
121-
with pytest.raises(ValueError, match=self.errmsg):
122-
obj.transpose(1)
123-
with pytest.raises(ValueError, match=self.errmsg):
124-
obj.transpose(axes=1)
119+
def test_transpose_non_default_axes(self, index_or_series_obj):
120+
obj = index_or_series_obj
121+
with pytest.raises(ValueError, match=self.errmsg):
122+
obj.transpose(1)
123+
with pytest.raises(ValueError, match=self.errmsg):
124+
obj.transpose(axes=1)
125125

126-
def test_numpy_transpose(self):
127-
for obj in self.objs:
128-
tm.assert_equal(np.transpose(obj), obj)
126+
def test_numpy_transpose(self, index_or_series_obj):
127+
obj = index_or_series_obj
128+
tm.assert_equal(np.transpose(obj), obj)
129129

130-
with pytest.raises(ValueError, match=self.errmsg):
131-
np.transpose(obj, axes=1)
130+
with pytest.raises(ValueError, match=self.errmsg):
131+
np.transpose(obj, axes=1)
132132

133133

134134
class TestIndexOps(Ops):

pandas/tests/indexes/conftest.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

pandas/tests/indexes/test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
period_range,
3535
)
3636
import pandas._testing as tm
37+
from pandas.conftest import indices_dict
3738
from pandas.core.indexes.api import (
3839
Index,
3940
MultiIndex,
@@ -42,7 +43,6 @@
4243
ensure_index_from_sequences,
4344
)
4445
from pandas.tests.indexes.common import Base
45-
from pandas.tests.indexes.conftest import indices_dict
4646

4747

4848
class TestIndex(Base):

pandas/tests/indexes/test_setops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from pandas import Float64Index, Int64Index, RangeIndex, UInt64Index
1414
import pandas._testing as tm
1515
from pandas.api.types import pandas_dtype
16-
from pandas.tests.indexes.conftest import indices_dict
16+
from pandas.conftest import indices_dict
1717

1818
COMPATIBLE_INCONSISTENT_PAIRS = {
1919
(Int64Index, RangeIndex): (tm.makeIntIndex, tm.makeRangeIndex),

0 commit comments

Comments
 (0)