Skip to content

Commit fb1d44e

Browse files
committed
TST: remove fixtures where not needed
1 parent aa4f240 commit fb1d44e

File tree

1 file changed

+32
-34
lines changed

1 file changed

+32
-34
lines changed

pandas/tests/reshape/test_reshape.py

+32-34
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def df(self):
224224
'B': ['b', 'b', 'c'],
225225
'C': [1, 2, 3]})
226226

227-
@pytest.fixture(params=['uint8', 'int64', np.float64, bool, None])
227+
@pytest.fixture(params=['uint8', 'i8', np.float64, bool, None])
228228
def dtype(self, request):
229229
return np.dtype(request.param)
230230

@@ -240,7 +240,7 @@ def effective_dtype(self, dtype):
240240
return dtype
241241

242242
def test_throws_on_dtype_object(self, df):
243-
with pytest.raises(TypeError):
243+
with pytest.raises(ValueError):
244244
get_dummies(df, dtype='object')
245245

246246
def test_basic(self, sparse, dtype):
@@ -347,26 +347,26 @@ def test_include_na(self, sparse, dtype):
347347
dtype=self.effective_dtype(dtype))
348348
tm.assert_numpy_array_equal(res_just_na.values, exp_just_na.values)
349349

350-
def test_unicode(self, sparse, dtype):
350+
def test_unicode(self, sparse):
351351
# See GH 6885 - get_dummies chokes on unicode values
352352
import unicodedata
353353
e = 'e'
354354
eacute = unicodedata.lookup('LATIN SMALL LETTER E WITH ACUTE')
355355
s = [e, eacute, eacute]
356-
res = get_dummies(s, prefix='letter', sparse=sparse, dtype=dtype)
356+
res = get_dummies(s, prefix='letter', sparse=sparse)
357357
exp = DataFrame({'letter_e': [1, 0, 0],
358358
u('letter_%s') % eacute: [0, 1, 1]},
359-
dtype=self.effective_dtype(dtype))
359+
dtype=np.uint8)
360360
assert_frame_equal(res, exp)
361361

362-
def test_dataframe_dummies_all_obj(self, df, sparse, dtype):
362+
def test_dataframe_dummies_all_obj(self, df, sparse):
363363
df = df[['A', 'B']]
364-
result = get_dummies(df, sparse=sparse, dtype=dtype)
364+
result = get_dummies(df, sparse=sparse)
365365
expected = DataFrame({'A_a': [1, 0, 1],
366366
'A_b': [0, 1, 0],
367367
'B_b': [1, 1, 0],
368368
'B_c': [0, 0, 1]},
369-
dtype=self.effective_dtype(dtype))
369+
dtype=np.uint8)
370370
assert_frame_equal(result, expected)
371371

372372
def test_dataframe_dummies_mix_default(self, df, sparse, dtype):
@@ -381,30 +381,30 @@ def test_dataframe_dummies_mix_default(self, df, sparse, dtype):
381381
expected = expected[['C', 'A_a', 'A_b', 'B_b', 'B_c']]
382382
assert_frame_equal(result, expected)
383383

384-
def test_dataframe_dummies_prefix_list(self, df, sparse, dtype):
384+
def test_dataframe_dummies_prefix_list(self, df, sparse):
385385
prefixes = ['from_A', 'from_B']
386-
result = get_dummies(df, prefix=prefixes, sparse=sparse, dtype=dtype)
386+
result = get_dummies(df, prefix=prefixes, sparse=sparse)
387387
expected = DataFrame({'C': [1, 2, 3],
388388
'from_A_a': [1, 0, 1],
389389
'from_A_b': [0, 1, 0],
390390
'from_B_b': [1, 1, 0],
391-
'from_B_c': [0, 0, 1]})
392-
cols = expected.columns[1:]
393-
expected[cols] = expected[cols].astype(dtype)
391+
'from_B_c': [0, 0, 1]},
392+
dtype=np.uint8)
393+
expected[['C']] = df[['C']]
394394
expected = expected[['C', 'from_A_a', 'from_A_b',
395395
'from_B_b', 'from_B_c']]
396396
assert_frame_equal(result, expected)
397397

398-
def test_dataframe_dummies_prefix_str(self, df, sparse, dtype):
398+
def test_dataframe_dummies_prefix_str(self, df, sparse):
399399
# not that you should do this...
400-
result = get_dummies(df, prefix='bad', sparse=sparse, dtype=dtype)
400+
result = get_dummies(df, prefix='bad', sparse=sparse)
401401
bad_columns = ['bad_a', 'bad_b', 'bad_b', 'bad_c']
402402
expected = DataFrame([[1, 1, 0, 1, 0],
403403
[2, 0, 1, 1, 0],
404404
[3, 1, 0, 0, 1]],
405405
columns=['C'] + bad_columns,
406-
dtype=self.effective_dtype(dtype))
407-
expected['C'] = [1, 2, 3]
406+
dtype=np.uint8)
407+
expected[['C']] = df[['C']]
408408
assert_frame_equal(result, expected)
409409

410410
def test_dataframe_dummies_subset(self, df, sparse, dtype):
@@ -418,25 +418,24 @@ def test_dataframe_dummies_subset(self, df, sparse, dtype):
418418
expected[columns] = expected[columns].astype(dtype)
419419
assert_frame_equal(result, expected)
420420

421-
def test_dataframe_dummies_prefix_sep(self, df, sparse, dtype):
422-
result = get_dummies(df, prefix_sep='..', sparse=sparse, dtype=dtype)
421+
def test_dataframe_dummies_prefix_sep(self, df, sparse):
422+
result = get_dummies(df, prefix_sep='..', sparse=sparse)
423423
expected = DataFrame({'C': [1, 2, 3],
424424
'A..a': [1, 0, 1],
425425
'A..b': [0, 1, 0],
426426
'B..b': [1, 1, 0],
427-
'B..c': [0, 0, 1]})
427+
'B..c': [0, 0, 1]},
428+
dtype=np.uint8)
429+
expected[['C']] = df[['C']]
428430
expected = expected[['C', 'A..a', 'A..b', 'B..b', 'B..c']]
429-
cols = expected.columns[1:]
430-
expected[cols] = expected[cols].astype(self.effective_dtype(dtype))
431431
assert_frame_equal(result, expected)
432432

433-
result = get_dummies(df, prefix_sep=['..', '__'],
434-
sparse=sparse, dtype=dtype)
433+
result = get_dummies(df, prefix_sep=['..', '__'], sparse=sparse)
435434
expected = expected.rename(columns={'B..b': 'B__b', 'B..c': 'B__c'})
436435
assert_frame_equal(result, expected)
437436

438437
result = get_dummies(df, prefix_sep={'A': '..', 'B': '__'},
439-
sparse=sparse, dtype=dtype)
438+
sparse=sparse)
440439
assert_frame_equal(result, expected)
441440

442441
def test_dataframe_dummies_prefix_bad_length(self, df, sparse):
@@ -447,12 +446,12 @@ def test_dataframe_dummies_prefix_sep_bad_length(self, df, sparse):
447446
with pytest.raises(ValueError):
448447
get_dummies(df, prefix_sep=['bad'], sparse=sparse)
449448

450-
def test_dataframe_dummies_prefix_dict(self, sparse, dtype):
449+
def test_dataframe_dummies_prefix_dict(self, sparse):
451450
prefixes = {'A': 'from_A', 'B': 'from_B'}
452451
df = DataFrame({'A': ['a', 'b', 'a'],
453452
'B': ['b', 'b', 'c'],
454453
'C': [1, 2, 3]})
455-
result = get_dummies(df, prefix=prefixes, sparse=sparse, dtype=dtype)
454+
result = get_dummies(df, prefix=prefixes, sparse=sparse)
456455

457456
expected = DataFrame({'from_A_a': [1, 0, 1],
458457
'from_A_b': [0, 1, 0],
@@ -461,8 +460,7 @@ def test_dataframe_dummies_prefix_dict(self, sparse, dtype):
461460
'C': [1, 2, 3]})
462461

463462
columns = ['from_A_a', 'from_A_b', 'from_B_b', 'from_B_c']
464-
effective_dtype = self.effective_dtype(dtype)
465-
expected[columns] = expected[columns].astype(effective_dtype)
463+
expected[columns] = expected[columns].astype(np.uint8)
466464
assert_frame_equal(result, expected)
467465

468466
def test_dataframe_dummies_with_na(self, df, sparse, dtype):
@@ -610,23 +608,23 @@ def test_dataframe_dummies_drop_first_with_na(self, df, sparse, dtype):
610608
expected = expected[['C', 'A_b', 'B_c']]
611609
assert_frame_equal(result, expected)
612610

613-
def test_int_int(self, dtype):
611+
def test_int_int(self):
614612
data = Series([1, 2, 1])
615-
result = pd.get_dummies(data, dtype=dtype)
613+
result = pd.get_dummies(data)
616614
expected = DataFrame([[1, 0],
617615
[0, 1],
618616
[1, 0]],
619617
columns=[1, 2],
620-
dtype=self.effective_dtype(dtype))
618+
dtype=np.uint8)
621619
tm.assert_frame_equal(result, expected)
622620

623621
data = Series(pd.Categorical(['a', 'b', 'a']))
624-
result = pd.get_dummies(data, dtype=dtype)
622+
result = pd.get_dummies(data)
625623
expected = DataFrame([[1, 0],
626624
[0, 1],
627625
[1, 0]],
628626
columns=pd.Categorical(['a', 'b']),
629-
dtype=self.effective_dtype(dtype))
627+
dtype=np.uint8)
630628
tm.assert_frame_equal(result, expected)
631629

632630
def test_int_df(self, dtype):

0 commit comments

Comments
 (0)