Skip to content

Commit 7316414

Browse files
committed
use CONFTEST dtypes in parametrization
1 parent c52d7e0 commit 7316414

File tree

2 files changed

+11
-30
lines changed

2 files changed

+11
-30
lines changed

doc/source/whatsnew/v1.0.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ Indexing
742742
- Fix assignment of column via `.loc` with numpy non-ns datetime type (:issue:`27395`)
743743
- Bug in :meth:`Float64Index.astype` where ``np.inf`` was not handled properly when casting to an integer dtype (:issue:`28475`)
744744
- :meth:`Index.union` could fail when the left contained duplicates (:issue:`28257`)
745-
- Bug when indexing with ``.loc`` where the index was a :class:`CategoricalIndex` with integer or float categories, a ValueError was raised (:issue:`17569`)
745+
- Bug when indexing with ``.loc`` where the index was a :class:`CategoricalIndex` with integer and float categories, a ValueError was raised (:issue:`17569`)
746746
- :meth:`Index.get_indexer_non_unique` could fail with `TypeError` in some cases, such as when searching for ints in a string index (:issue:`28257`)
747747
- Bug in :meth:`Float64Index.get_loc` incorrectly raising ``TypeError`` instead of ``KeyError`` (:issue:`29189`)
748748

pandas/tests/indexing/test_categorical.py

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pandas.core.dtypes.dtypes import CategoricalDtype
66

77
import pandas as pd
8+
from pandas import conftest
89
from pandas import (
910
Categorical,
1011
CategoricalIndex,
@@ -772,41 +773,17 @@ def test_map_with_dict_or_series(self):
772773
[1.5, 2.5, 3.5],
773774
[-1.5, -2.5, -3.5],
774775
# numpy int/uint
775-
*[
776-
np.array([1, 2, 3], dtype=dtype)
777-
for dtype in [
778-
np.int8,
779-
np.int16,
780-
np.int32,
781-
np.int64,
782-
np.uint8,
783-
np.uint16,
784-
np.uint32,
785-
np.uint64,
786-
]
787-
],
776+
*[np.array([1, 2, 3], dtype=dtype) for dtype in conftest.ALL_INT_DTYPES],
788777
# numpy floats
789-
*[
790-
np.array([1.5, 2.5, 3.5], dtype=dtype)
791-
for dtype in (np.float16, np.float32, np.float64)
792-
],
778+
*[np.array([1.5, 2.5, 3.5], dtype=dtyp) for dtyp in conftest.FLOAT_DTYPES],
779+
# numpy object
780+
np.array([1, "b", 3.5], dtype=object),
793781
# pandas scalars
794782
[Interval(1, 4), Interval(4, 6), Interval(6, 9)],
795783
[Timestamp(2019, 1, 1), Timestamp(2019, 2, 1), Timestamp(2019, 3, 1)],
796784
[Timedelta(1, "d"), Timedelta(2, "d"), Timedelta(3, "D")],
797785
# pandas Integer arrays
798-
*[
799-
pd.array([1, 2, 3], dtype=dtype)
800-
for dtype in [
801-
"Int8",
802-
"Int16",
803-
"Int32",
804-
"Int64",
805-
"UInt8",
806-
"UInt32",
807-
"UInt64",
808-
]
809-
],
786+
*[pd.array([1, 2, 3], dtype=dtype) for dtype in conftest.ALL_EA_INT_DTYPES],
810787
# other pandas arrays
811788
pd.IntervalIndex.from_breaks([1, 4, 6, 9]).array,
812789
pd.date_range("2019-01-01", periods=3).array,
@@ -817,19 +794,23 @@ def test_loc_with_non_string_categories(self, idx_values, ordered_fixture):
817794
# GH-17569
818795
cat_idx = CategoricalIndex(idx_values, ordered=ordered_fixture)
819796
df = DataFrame({"A": ["foo", "bar", "baz"]}, index=cat_idx)
797+
820798
# scalar selection
821799
result = df.loc[idx_values[0]]
822800
expected = Series(["foo"], index=["A"], name=idx_values[0])
823801
tm.assert_series_equal(result, expected)
802+
824803
# list selection
825804
result = df.loc[idx_values[:2]]
826805
expected = DataFrame(["foo", "bar"], index=cat_idx[:2], columns=["A"])
827806
tm.assert_frame_equal(result, expected)
807+
828808
# scalar assignment
829809
result = df.copy()
830810
result.loc[idx_values[0]] = "qux"
831811
expected = DataFrame({"A": ["qux", "bar", "baz"]}, index=cat_idx)
832812
tm.assert_frame_equal(result, expected)
813+
833814
# list assignment
834815
result = df.copy()
835816
result.loc[idx_values[:2], "A"] = ["qux", "qux2"]

0 commit comments

Comments
 (0)