Skip to content

Commit 50234e9

Browse files
committed
Tests for concat_same_type
1 parent 755bc5c commit 50234e9

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

pandas/tests/arrays/test_datetimelike.py

+49
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ def test_take_fill(self):
119119
arr.take([0, 1], allow_fill=True,
120120
fill_value=pd.Timestamp.now().time)
121121

122+
def test_concat_same_type(self):
123+
data = np.arange(10, dtype='i8')
124+
125+
idx = self.index_cls._simple_new(data, freq='D').insert(0, pd.NaT)
126+
arr = index_to_array(idx)
127+
128+
result = arr._concat_same_type([arr[:-1], arr[1:], arr])
129+
expected = idx._concat_same_dtype([idx[:-1], idx[1:], idx], None)
130+
131+
tm.assert_index_equal(self.index_cls(result), expected)
132+
122133

123134
class TestDatetimeArray(SharedTests):
124135
index_cls = pd.DatetimeIndex
@@ -200,6 +211,19 @@ def test_int_properties(self, datetime_index, propname):
200211

201212
tm.assert_numpy_array_equal(result, expected)
202213

214+
def test_concat_same_type_invalid(self, datetime_index):
215+
# different timezones
216+
dti = datetime_index
217+
arr = DatetimeArrayMixin(dti)
218+
219+
if arr.tz is None:
220+
other = arr.tz_localize('UTC')
221+
else:
222+
other = arr.tz_localize(None)
223+
224+
with pytest.raises(AssertionError):
225+
arr._concat_same_type([arr, other])
226+
203227

204228
class TestTimedeltaArray(SharedTests):
205229
index_cls = pd.TimedeltaIndex
@@ -239,6 +263,19 @@ def test_astype_object(self):
239263
assert asobj.dtype == 'O'
240264
assert list(asobj) == list(tdi)
241265

266+
def test_concat_same_type_invalid(self, timedelta_index):
267+
# different freqs
268+
tdi = timedelta_index
269+
arr = TimedeltaArrayMixin(tdi)
270+
271+
other = pd.timedelta_range('1D', periods=5, freq='2D')
272+
# FIXME: TimedeltaArray should inherit freq='2D' without specifying it
273+
other = TimedeltaArrayMixin(other, freq='2D')
274+
assert other.freq != arr.freq
275+
276+
with pytest.raises(AssertionError):
277+
arr._concat_same_type([arr, other])
278+
242279

243280
class TestPeriodArray(SharedTests):
244281
index_cls = pd.PeriodIndex
@@ -315,3 +352,15 @@ def test_int_properties(self, period_index, propname):
315352
expected = np.array(getattr(pi, propname))
316353

317354
tm.assert_numpy_array_equal(result, expected)
355+
356+
def test_concat_same_type_invalid(self, period_index):
357+
# different freqs
358+
pi = period_index
359+
arr = PeriodArrayMixin(pi)
360+
361+
other = pd.period_range('2016Q3', periods=5, freq='3Q')
362+
other = PeriodArrayMixin(other)
363+
assert other.freq != arr.freq
364+
365+
with pytest.raises(AssertionError):
366+
arr._concat_same_type([arr, other])

0 commit comments

Comments
 (0)