Skip to content

Commit af7ee9a

Browse files
authored
Restructure the hierarchy of Index unit tests (#2080)
Proposal: `databricks/koalas/tests/test_indexes.py` -> `databricks/koalas/tests/indexes/test_base.py` Create `databricks/koalas/tests/indexes/test_datetime.py`
1 parent 9bac655 commit af7ee9a

File tree

3 files changed

+102
-38
lines changed

3 files changed

+102
-38
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#
2+
# Copyright (C) 2019 Databricks, Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#

databricks/koalas/tests/test_indexes.py renamed to databricks/koalas/tests/indexes/test_base.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -370,44 +370,6 @@ def test_index_unique(self):
370370
with self.assertRaisesRegex(KeyError, "Requested level (hi)*"):
371371
kidx.unique(level="hi")
372372

373-
def test_datetime_index_properties(self):
374-
pidx_list = [
375-
pd.DatetimeIndex([0]),
376-
pd.DatetimeIndex(["2004-01-01", "2002-12-31", "2000-04-01"]),
377-
] + [
378-
pd.date_range("2000-01-01", periods=3, freq=unit)
379-
for unit in ["ns", "us", "ms", "s", "m", "h", "D"]
380-
]
381-
382-
for pidx in pidx_list:
383-
kidx = ks.from_pandas(pidx)
384-
self.assert_eq(kidx.year, pidx.year)
385-
self.assert_eq(kidx.month, pidx.month)
386-
self.assert_eq(kidx.day, pidx.day)
387-
self.assert_eq(kidx.hour, pidx.hour)
388-
self.assert_eq(kidx.minute, pidx.minute)
389-
self.assert_eq(kidx.second, pidx.second)
390-
self.assert_eq(kidx.microsecond, pidx.microsecond)
391-
self.assert_eq(kidx.week, pidx.week)
392-
self.assert_eq(kidx.weekofyear, pidx.weekofyear)
393-
self.assert_eq(kidx.dayofweek, pidx.dayofweek)
394-
self.assert_eq(kidx.weekday, pidx.weekday)
395-
self.assert_eq(kidx.dayofyear, pidx.dayofyear)
396-
self.assert_eq(kidx.quarter, pidx.quarter)
397-
self.assert_eq(kidx.daysinmonth, pidx.daysinmonth)
398-
self.assert_eq(kidx.days_in_month, pidx.days_in_month)
399-
self.assert_eq(kidx.is_month_start, pd.Index(pidx.is_month_start))
400-
self.assert_eq(kidx.is_month_end, pd.Index(pidx.is_month_end))
401-
self.assert_eq(kidx.is_quarter_start, pd.Index(pidx.is_quarter_start))
402-
self.assert_eq(kidx.is_quarter_end, pd.Index(pidx.is_quarter_end))
403-
self.assert_eq(kidx.is_year_start, pd.Index(pidx.is_year_start))
404-
self.assert_eq(kidx.is_year_end, pd.Index(pidx.is_year_end))
405-
self.assert_eq(kidx.is_leap_year, pd.Index(pidx.is_leap_year))
406-
407-
if LooseVersion(pd.__version__) >= LooseVersion("1.2.0"):
408-
self.assert_eq(kidx.day_of_year, pidx.day_of_year)
409-
self.assert_eq(kidx.day_of_week, pidx.day_of_week)
410-
411373
def test_multi_index_copy(self):
412374
arrays = [[1, 1, 2, 2], ["red", "blue", "red", "blue"]]
413375
idx = pd.MultiIndex.from_arrays(arrays, names=("number", "color"))
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#
2+
# Copyright (C) 2019 Databricks, Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
from distutils.version import LooseVersion
18+
19+
import pandas as pd
20+
import databricks.koalas as ks
21+
22+
from databricks.koalas.testing.utils import ReusedSQLTestCase, TestUtils
23+
24+
25+
class DatetimeIndexTest(ReusedSQLTestCase, TestUtils):
26+
@property
27+
def fixed_freqs(self):
28+
return [
29+
"D",
30+
"H",
31+
"T", # min
32+
"S",
33+
"L", # ms
34+
"U", # us
35+
# 'N' not supported
36+
]
37+
38+
@property
39+
def non_fixed_freqs(self):
40+
return ["W", "Q"]
41+
42+
@property
43+
def pidxs(self):
44+
return [
45+
pd.DatetimeIndex([0]),
46+
pd.DatetimeIndex(["2004-01-01", "2002-12-31", "2000-04-01"]),
47+
] + [
48+
pd.date_range("2000-01-01", periods=3, freq=freq)
49+
for freq in (self.fixed_freqs + self.non_fixed_freqs)
50+
]
51+
52+
@property
53+
def kidxs(self):
54+
return [ks.from_pandas(pidx) for pidx in self.pidxs]
55+
56+
@property
57+
def idx_pairs(self):
58+
return list(zip(self.kidxs, self.pidxs))
59+
60+
def test_properties(self):
61+
for kidx, pidx in self.idx_pairs:
62+
self.assert_eq(kidx.year, pidx.year)
63+
self.assert_eq(kidx.month, pidx.month)
64+
self.assert_eq(kidx.day, pidx.day)
65+
self.assert_eq(kidx.hour, pidx.hour)
66+
self.assert_eq(kidx.minute, pidx.minute)
67+
self.assert_eq(kidx.second, pidx.second)
68+
self.assert_eq(kidx.microsecond, pidx.microsecond)
69+
self.assert_eq(kidx.week, pidx.week)
70+
self.assert_eq(kidx.weekofyear, pidx.weekofyear)
71+
self.assert_eq(kidx.dayofweek, pidx.dayofweek)
72+
self.assert_eq(kidx.weekday, pidx.weekday)
73+
self.assert_eq(kidx.dayofyear, pidx.dayofyear)
74+
self.assert_eq(kidx.quarter, pidx.quarter)
75+
self.assert_eq(kidx.daysinmonth, pidx.daysinmonth)
76+
self.assert_eq(kidx.days_in_month, pidx.days_in_month)
77+
self.assert_eq(kidx.is_month_start, pd.Index(pidx.is_month_start))
78+
self.assert_eq(kidx.is_month_end, pd.Index(pidx.is_month_end))
79+
self.assert_eq(kidx.is_quarter_start, pd.Index(pidx.is_quarter_start))
80+
self.assert_eq(kidx.is_quarter_end, pd.Index(pidx.is_quarter_end))
81+
self.assert_eq(kidx.is_year_start, pd.Index(pidx.is_year_start))
82+
self.assert_eq(kidx.is_year_end, pd.Index(pidx.is_year_end))
83+
self.assert_eq(kidx.is_leap_year, pd.Index(pidx.is_leap_year))
84+
85+
if LooseVersion(pd.__version__) >= LooseVersion("1.2.0"):
86+
self.assert_eq(kidx.day_of_year, pidx.day_of_year)
87+
self.assert_eq(kidx.day_of_week, pidx.day_of_week)

0 commit comments

Comments
 (0)