Skip to content

Commit 760dfa3

Browse files
committed
CLN: Move stuff in tests.indexes to more logical locations
1 parent 70352c2 commit 760dfa3

File tree

2 files changed

+24
-32
lines changed

2 files changed

+24
-32
lines changed

pandas/tests/indexes/common.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
from datetime import datetime
12
import gc
23
from typing import Type
34

45
import numpy as np
56
import pytest
67

78
from pandas._libs import iNaT
9+
from pandas._libs.tslibs import Timestamp
810

911
from pandas.core.dtypes.common import is_datetime64tz_dtype
1012
from pandas.core.dtypes.dtypes import CategoricalDtype
@@ -738,3 +740,25 @@ def test_shallow_copy_shares_cache(self, simple_index):
738740
shallow_copy = idx._shallow_copy(idx._data)
739741
assert shallow_copy._cache is not idx._cache
740742
assert shallow_copy._cache == {}
743+
744+
def test_index_groupby(self, simple_index):
745+
idx = simple_index[:5]
746+
to_groupby = np.array([1, 2, np.nan, 2, 1])
747+
tm.assert_dict_equal(
748+
idx.groupby(to_groupby), {1.0: idx[[0, 4]], 2.0: idx[[1, 3]]}
749+
)
750+
751+
to_groupby = DatetimeIndex(
752+
[
753+
datetime(2011, 11, 1),
754+
datetime(2011, 12, 1),
755+
pd.NaT,
756+
datetime(2011, 12, 1),
757+
datetime(2011, 11, 1),
758+
],
759+
tz="UTC",
760+
).values
761+
762+
ex_keys = [Timestamp("2011-11-01"), Timestamp("2011-12-01")]
763+
expected = {ex_keys[0]: idx[[0, 4]], ex_keys[1]: idx[[1, 3]]}
764+
tm.assert_dict_equal(idx.groupby(to_groupby), expected)

pandas/tests/indexes/test_numeric.py renamed to pandas/tests/indexes/numeric/test_numeric.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from datetime import datetime
2-
31
import numpy as np
42
import pytest
53

@@ -51,36 +49,6 @@ def test_arithmetic_explicit_conversions(self, klass):
5149
tm.assert_index_equal(result, expected)
5250

5351

54-
class TestNumericIndex:
55-
def test_index_groupby(self):
56-
int_idx = Index(range(6))
57-
float_idx = Index(np.arange(0, 0.6, 0.1))
58-
obj_idx = Index("A B C D E F".split())
59-
dt_idx = pd.date_range("2013-01-01", freq="M", periods=6)
60-
61-
for idx in [int_idx, float_idx, obj_idx, dt_idx]:
62-
to_groupby = np.array([1, 2, np.nan, np.nan, 2, 1])
63-
tm.assert_dict_equal(
64-
idx.groupby(to_groupby), {1.0: idx[[0, 5]], 2.0: idx[[1, 4]]}
65-
)
66-
67-
to_groupby = pd.DatetimeIndex(
68-
[
69-
datetime(2011, 11, 1),
70-
datetime(2011, 12, 1),
71-
pd.NaT,
72-
pd.NaT,
73-
datetime(2011, 12, 1),
74-
datetime(2011, 11, 1),
75-
],
76-
tz="UTC",
77-
).values
78-
79-
ex_keys = [Timestamp("2011-11-01"), Timestamp("2011-12-01")]
80-
expected = {ex_keys[0]: idx[[0, 5]], ex_keys[1]: idx[[1, 4]]}
81-
tm.assert_dict_equal(idx.groupby(to_groupby), expected)
82-
83-
8452
class Numeric(Base):
8553
def test_where(self):
8654
# Tested in numeric.test_indexing

0 commit comments

Comments
 (0)