Skip to content

Commit cc993d8

Browse files
committed
add additional test
1 parent 13a2d18 commit cc993d8

File tree

2 files changed

+50
-36
lines changed

2 files changed

+50
-36
lines changed

pandas/core/reshape/tile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def _convert_bin_to_numeric_type(bins, dtype):
309309
310310
Parameters
311311
----------
312-
bins : list-liek of bins
312+
bins : list-like of bins
313313
dtype : dtype of data
314314
315315
Raises

pandas/tests/reshape/test_tile.py

+49-35
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,10 @@ def test_cut_corner(self):
105105
pytest.raises(ValueError, cut, [1, 2, 3], 0.5)
106106

107107
@pytest.mark.parametrize('arg', [2, np.eye(2), DataFrame(np.eye(2))])
108-
@pytest.mark.parametrize('bins', [2, np.array(2), np.arange(1, 2), [1, 2],
109-
Series([1, 2]), Index([1, 2])])
110108
@pytest.mark.parametrize('cut_func', [cut, qcut])
111-
def test_cut_not_1d_arg(self, arg, bins, cut_func):
109+
def test_cut_not_1d_arg(self, arg, cut_func):
112110
with pytest.raises(ValueError):
113-
cut_func(arg, bins)
111+
cut_func(arg, 2)
114112

115113
def test_cut_out_of_range_more(self):
116114
# #1511
@@ -259,18 +257,6 @@ def test_qcut_nas(self):
259257
result = qcut(arr, 4)
260258
assert isna(result[:20]).all()
261259

262-
@pytest.mark.parametrize('s', [
263-
Series(DatetimeIndex(['20180101', NaT, '20180103'])),
264-
Series(TimedeltaIndex(['0 days', NaT, '2 days']))],
265-
ids=lambda x: str(x.dtype))
266-
def test_qcut_nat(self, s):
267-
# GH 19768
268-
intervals = IntervalIndex.from_tuples(
269-
[(s[0] - Nano(), s[2] - Day()), np.nan, (s[2] - Day(), s[2])])
270-
expected = Series(Categorical(intervals, ordered=True))
271-
result = qcut(s, 2)
272-
tm.assert_series_equal(result, expected)
273-
274260
def test_qcut_index(self):
275261
result = qcut([0, 2], 2)
276262
intervals = [Interval(-0.001, 1), Interval(1, 2)]
@@ -460,6 +446,37 @@ def test_single_bin(self):
460446
result = cut(s, 1, labels=False)
461447
tm.assert_series_equal(result, expected)
462448

449+
@pytest.mark.parametrize(
450+
"array_1_writeable, array_2_writeable",
451+
[(True, True), (True, False), (False, False)])
452+
def test_cut_read_only(self, array_1_writeable, array_2_writeable):
453+
# issue 18773
454+
array_1 = np.arange(0, 100, 10)
455+
array_1.flags.writeable = array_1_writeable
456+
457+
array_2 = np.arange(0, 100, 10)
458+
array_2.flags.writeable = array_2_writeable
459+
460+
hundred_elements = np.arange(100)
461+
462+
tm.assert_categorical_equal(cut(hundred_elements, array_1),
463+
cut(hundred_elements, array_2))
464+
465+
466+
class TestDatelike(object):
467+
468+
@pytest.mark.parametrize('s', [
469+
Series(DatetimeIndex(['20180101', NaT, '20180103'])),
470+
Series(TimedeltaIndex(['0 days', NaT, '2 days']))],
471+
ids=lambda x: str(x.dtype))
472+
def test_qcut_nat(self, s):
473+
# GH 19768
474+
intervals = IntervalIndex.from_tuples(
475+
[(s[0] - Nano(), s[2] - Day()), np.nan, (s[2] - Day(), s[2])])
476+
expected = Series(Categorical(intervals, ordered=True))
477+
result = qcut(s, 2)
478+
tm.assert_series_equal(result, expected)
479+
463480
def test_datetime_cut(self):
464481
# GH 14714
465482
# testing for time data to be present as series
@@ -496,11 +513,19 @@ def test_datetime_cut(self):
496513
result, bins = cut(data, 3, retbins=True)
497514
tm.assert_series_equal(Series(result), expected)
498515

499-
def test_datetimetz_cut(self):
516+
@pytest.mark.parametrize('bins', [
517+
3, [Timestamp('2013-01-01 04:57:07.200000').value,
518+
Timestamp('2013-01-01 21:00:00').value,
519+
Timestamp('2013-01-02 13:00:00').value,
520+
Timestamp('2013-01-03 05:00:00').value]])
521+
@pytest.mark.parametrize('const', [list, np.array, Index, Series])
522+
def test_datetimetz_cut(self, bins, const):
500523
# GH 19872
501524
tz = 'US/Eastern'
502525
s = Series(date_range('20130101', periods=3, tz=tz))
503-
result = cut(s, 3)
526+
if not isinstance(bins, int):
527+
bins = const(bins)
528+
result = cut(s, bins)
504529
expected = (
505530
Series(IntervalIndex([
506531
Interval(Timestamp('2012-12-31 23:57:07.200000', tz=tz),
@@ -512,7 +537,12 @@ def test_datetimetz_cut(self):
512537
.astype(CDT(ordered=True)))
513538
tm.assert_series_equal(result, expected)
514539

515-
result = qcut(s, 3)
540+
@pytest.mark.parametrize('bins', [3, np.linspace(0, 1, 4)])
541+
def test_datetimetz_qcut(self, bins):
542+
# GH 19872
543+
tz = 'US/Eastern'
544+
s = Series(date_range('20130101', periods=3, tz=tz))
545+
result = qcut(s, bins)
516546
expected = (
517547
Series(IntervalIndex([
518548
Interval(Timestamp('2012-12-31 23:59:59.999999999', tz=tz),
@@ -559,19 +589,3 @@ def f():
559589
mask = result.isna()
560590
tm.assert_numpy_array_equal(
561591
mask, np.array([False, True, True, True, True]))
562-
563-
@pytest.mark.parametrize(
564-
"array_1_writeable, array_2_writeable",
565-
[(True, True), (True, False), (False, False)])
566-
def test_cut_read_only(self, array_1_writeable, array_2_writeable):
567-
# issue 18773
568-
array_1 = np.arange(0, 100, 10)
569-
array_1.flags.writeable = array_1_writeable
570-
571-
array_2 = np.arange(0, 100, 10)
572-
array_2.flags.writeable = array_2_writeable
573-
574-
hundred_elements = np.arange(100)
575-
576-
tm.assert_categorical_equal(cut(hundred_elements, array_1),
577-
cut(hundred_elements, array_2))

0 commit comments

Comments
 (0)