diff --git a/pandas/io/tests/parser/c_parser_only.py b/pandas/io/tests/parser/c_parser_only.py index 2f2a3ab507f8f..c781b0549ee60 100644 --- a/pandas/io/tests/parser/c_parser_only.py +++ b/pandas/io/tests/parser/c_parser_only.py @@ -371,49 +371,3 @@ def test_internal_null_byte(self): result = self.read_csv(StringIO(data), names=names) tm.assert_frame_equal(result, expected) - - def test_empty_dtype(self): - # see gh-14712 - data = 'a,b' - - expected = pd.DataFrame(columns=['a', 'b'], dtype=np.float64) - result = self.read_csv(StringIO(data), header=0, dtype=np.float64) - tm.assert_frame_equal(result, expected) - - expected = pd.DataFrame({'a': pd.Categorical([]), - 'b': pd.Categorical([])}, - index=[]) - result = self.read_csv(StringIO(data), header=0, - dtype='category') - tm.assert_frame_equal(result, expected) - - expected = pd.DataFrame(columns=['a', 'b'], dtype='datetime64[ns]') - result = self.read_csv(StringIO(data), header=0, - dtype='datetime64[ns]') - tm.assert_frame_equal(result, expected) - - expected = pd.DataFrame({'a': pd.Series([], dtype='timedelta64[ns]'), - 'b': pd.Series([], dtype='timedelta64[ns]')}, - index=[]) - result = self.read_csv(StringIO(data), header=0, - dtype='timedelta64[ns]') - tm.assert_frame_equal(result, expected) - - expected = pd.DataFrame(columns=['a', 'b']) - expected['a'] = expected['a'].astype(np.float64) - result = self.read_csv(StringIO(data), header=0, - dtype={'a': np.float64}) - tm.assert_frame_equal(result, expected) - - expected = pd.DataFrame(columns=['a', 'b']) - expected['a'] = expected['a'].astype(np.float64) - result = self.read_csv(StringIO(data), header=0, - dtype={0: np.float64}) - tm.assert_frame_equal(result, expected) - - expected = pd.DataFrame(columns=['a', 'b']) - expected['a'] = expected['a'].astype(np.int32) - expected['b'] = expected['b'].astype(np.float64) - result = self.read_csv(StringIO(data), header=0, - dtype={'a': np.int32, 1: np.float64}) - tm.assert_frame_equal(result, expected) diff --git a/pandas/io/tests/parser/dtypes.py b/pandas/io/tests/parser/dtypes.py index 058bfea7ae330..18c37b31f6480 100644 --- a/pandas/io/tests/parser/dtypes.py +++ b/pandas/io/tests/parser/dtypes.py @@ -226,3 +226,49 @@ def test_dtype_with_converter(self): converters={'a': lambda x: str(x)}) expected = DataFrame({'a': ['1.1', '1.2'], 'b': [2.2, 2.3]}) tm.assert_frame_equal(result, expected) + + def test_empty_dtype(self): + # see gh-14712 + data = 'a,b' + + expected = pd.DataFrame(columns=['a', 'b'], dtype=np.float64) + result = self.read_csv(StringIO(data), header=0, dtype=np.float64) + tm.assert_frame_equal(result, expected) + + expected = pd.DataFrame({'a': pd.Categorical([]), + 'b': pd.Categorical([])}, + index=[]) + result = self.read_csv(StringIO(data), header=0, + dtype='category') + tm.assert_frame_equal(result, expected) + + expected = pd.DataFrame(columns=['a', 'b'], dtype='datetime64[ns]') + result = self.read_csv(StringIO(data), header=0, + dtype='datetime64[ns]') + tm.assert_frame_equal(result, expected) + + expected = pd.DataFrame({'a': pd.Series([], dtype='timedelta64[ns]'), + 'b': pd.Series([], dtype='timedelta64[ns]')}, + index=[]) + result = self.read_csv(StringIO(data), header=0, + dtype='timedelta64[ns]') + tm.assert_frame_equal(result, expected) + + expected = pd.DataFrame(columns=['a', 'b']) + expected['a'] = expected['a'].astype(np.float64) + result = self.read_csv(StringIO(data), header=0, + dtype={'a': np.float64}) + tm.assert_frame_equal(result, expected) + + expected = pd.DataFrame(columns=['a', 'b']) + expected['a'] = expected['a'].astype(np.float64) + result = self.read_csv(StringIO(data), header=0, + dtype={0: np.float64}) + tm.assert_frame_equal(result, expected) + + expected = pd.DataFrame(columns=['a', 'b']) + expected['a'] = expected['a'].astype(np.int32) + expected['b'] = expected['b'].astype(np.float64) + result = self.read_csv(StringIO(data), header=0, + dtype={'a': np.int32, 1: np.float64}) + tm.assert_frame_equal(result, expected)