def test_from_pandas_basic(self): xpd = pd.DataFrame(self.x) x_from_dict = DataFrame(self.x) x_from_pd = DataFrame.from_pandas(xpd) assert isinstance(x_from_dict, DataFrame) assert isinstance(x_from_pd, DataFrame) x_from_pd = x_from_pd[self.x.keys()] x_from_dict = x_from_dict[self.x.keys()] assert x_from_dict.shape == x_from_pd.shape assert x_from_dict.names.equals(x_from_pd.names) for i in range(x_from_dict.nrow): for j in range(x_from_dict.ncol): assert x_from_dict[i, j] == x_from_pd[i, j]
def test_invalid_construction(self): with pytest.raises(ValueError): DataFrame.from_numpy(np.array([])) with pytest.raises(ValueError): DataFrame.from_numpy(np.array([1, 2, 3])) with pytest.raises(ValueError): DataFrame.from_numpy(np.zeros((2, 3, 4))) with pytest.raises(ValueError): DataFrame.from_numpy(np.zeros(()))
def test_empty_from_shape(self): df = DataFrame.from_shape((0, 0)) assert isinstance(df, DataFrame) assert df.shape == (0, 0) assert len(df.names) == 0 assert df.names.equals(Array([])) assert len(df.dtypes) == 0 assert df.dtypes.equals(Array([]))
class TestEmptyDataFrame: x = DataFrame() y = DataFrame({}) def test_valid_object_creation(self): assert isinstance(self.x, DataFrame) assert isinstance(self.y, DataFrame) assert self.x.shape == (0, 0) assert self.y.shape == (0, 0) assert self.x.nrow == 0 assert self.y.nrow == 0 assert self.x.ncol == 0 assert self.y.ncol == 0 assert len(self.x.dtypes) == 0 assert len(self.y.dtypes) == 0 assert len(self.x.names) == 0 assert len(self.y.names) == 0
def test_from_numpy_basic(self): xdf = DataFrame.from_numpy(self.x) assert isinstance(xdf, DataFrame) assert xdf.shape == self.x.shape assert xdf.names.equals(Array(['C0', 'C1', 'C2', 'C3'])) assert all(xdf.dtypes == int) for i in range(xdf.nrow): for j in range(xdf.ncol): assert xdf[i, j] == self.x[i, j] xdf = DataFrame.from_numpy(self.x, self.names) assert isinstance(xdf, DataFrame) assert xdf.shape == self.x.shape assert xdf.names.equals(Array(self.names)) assert all(xdf.dtypes == int) for i in range(xdf.nrow): for j in range(xdf.ncol): assert xdf[i, j] == self.x[i, j]
def test_from_columns_basic(self): xdf = DataFrame.from_columns(self.x) assert isinstance(xdf, DataFrame) assert xdf.shape == (2, 3) assert xdf.names.equals(Array(['C0', 'C1', 'C2'])) assert xdf.dtypes.equals(Array([int, str, float])) for i in range(xdf.nrow): for j in range(xdf.ncol): assert xdf[i, j] == self.x[j][i] xdf = DataFrame.from_columns(self.x, self.names) assert isinstance(xdf, DataFrame) assert xdf.shape == (2, 3) assert xdf.names.equals(Array(self.names)) assert xdf.dtypes.equals(Array([int, str, float])) for i in range(xdf.nrow): for j in range(xdf.ncol): assert xdf[i, j] == self.x[j][i]
class TestScalarSliceDualIndexing: ''' These should return dataframes and not underlying list objects ''' x = DataFrame({ 'a': [1, 2, 3], 'b': ['a', 'b', 'c'], 'c': [True, False, True] }) def test_valid_int_slice(self): assert isinstance(self.x[0, :], DataFrame) assert not isinstance(self.x[0, :], list) assert not isinstance(self.x[0, :], Array) assert isinstance(self.x[1, :], DataFrame) assert not isinstance(self.x[1, :], list) assert not isinstance(self.x[1, :], Array) assert isinstance(self.x[2, :], DataFrame) assert not isinstance(self.x[2, :], list) assert not isinstance(self.x[2, :], Array) assert isinstance(self.x[-1, :], DataFrame) assert not isinstance(self.x[-1, :], list) assert not isinstance(self.x[-1, :], Array) assert isinstance(self.x[0, 0:], DataFrame) assert not isinstance(self.x[0, 0:], list) assert not isinstance(self.x[0, 0:], Array) assert isinstance(self.x[1, 0:], DataFrame) assert not isinstance(self.x[1, 0:], list) assert not isinstance(self.x[1, 0:], Array) assert isinstance(self.x[0, 0:], DataFrame) assert not isinstance(self.x[0, 0:], list) assert not isinstance(self.x[0, 0:], Array) assert isinstance(self.x[1, 0:], DataFrame) assert not isinstance(self.x[1, 0:], list) assert not isinstance(self.x[1, 0:], Array) assert isinstance(self.x[-1, 0:], DataFrame) assert not isinstance(self.x[-1, 0:], list) assert not isinstance(self.x[-1, 0:], Array) assert isinstance(self.x[1, 0:1], DataFrame) assert not isinstance(self.x[1, 0:1], list) assert not isinstance(self.x[1, 0:1], Array) assert isinstance(self.x[1, 0:2], DataFrame) assert not isinstance(self.x[1, 0:2], list) assert not isinstance(self.x[1, 0:2], Array) assert isinstance(self.x[1, 0:3:2], DataFrame) assert not isinstance(self.x[1, 0:3:2], list) assert not isinstance(self.x[1, 0:3:2], Array)
def test_from_shape_basic(self): shape = (2, 3) df = DataFrame.from_shape(shape) assert isinstance(df, DataFrame) assert df.shape == shape assert df.names.equals(Array(['C0', 'C1', 'C2'])) assert all(df.dtypes == type(None)) for i in range(df.nrow): for j in range(df.ncol): assert df[i, j] is None
class TestScalarListDualIndexing: ''' These should return dataframes and not underlying list objects ''' x = DataFrame({ 'a': [1, 2, 3], 'b': ['a', 'b', 'c'], 'c': [True, False, True] }) def test_valid_int_list(self): assert isinstance(self.x[0, [0]], DataFrame) assert isinstance(self.x[0, [0, 1]], DataFrame)
def test_from_numpy_with_nan(self): ydf = DataFrame.from_numpy(self.y) assert isinstance(ydf, DataFrame) assert ydf.shape == self.y.shape assert ydf.names.equals(Array(['C0', 'C1'])) assert all(ydf.dtypes == float) for i in range(ydf.nrow): for j in range(ydf.ncol): if np.isnan(self.y[i, j]): assert ydf[i, j] is None else: assert ydf[i, j] == self.y[i, j]
def test_from_pandas_with_nan(self): xpd = pd.DataFrame(self.x) xpd.iloc[0, 0] = np.nan xdf = DataFrame.from_pandas(xpd) assert isinstance(xdf, DataFrame) assert xdf.shape == xpd.shape assert xdf[0, 0] is None for i in range(xdf.nrow): for j in range(xdf.ncol): if i == 0 and j == 0: pass else: assert xdf[i, j] == xpd.iloc[i, j]
def test_empty_pandas(self): df = DataFrame.from_pandas(pd.DataFrame()) assert isinstance(df, DataFrame) assert df.shape == (0, 0) assert len(df.names) == 0 assert df.names.equals(Array([])) assert len(df.dtypes) == 0 assert df.dtypes.equals(Array([])) df = DataFrame.from_pandas(pd.DataFrame([])) assert isinstance(df, DataFrame) assert df.shape == (0, 0) assert len(df.names) == 0 assert df.names.equals(Array([])) assert len(df.dtypes) == 0 assert df.dtypes.equals(Array([])) df = DataFrame.from_pandas(pd.DataFrame({})) assert isinstance(df, DataFrame) assert df.shape == (0, 0) assert len(df.names) == 0 assert df.names.equals(Array([])) assert len(df.dtypes) == 0 assert df.dtypes.equals(Array([]))
class TestSliceSingleIndexing: ''' These should return dataframes and not underlying list objects ''' x = DataFrame({ 'a': [1, 2, 3], 'b': ['a', 'b', 'c'], 'c': [True, False, True] }) def test_valid_slice_indexing(self): assert isinstance(self.x[:], DataFrame) assert not isinstance(self.x[:], list) assert not isinstance(self.x[:], Array) assert isinstance(self.x[0:1], DataFrame) assert not isinstance(self.x[0:1], list) assert not isinstance(self.x[0:1], Array) assert isinstance(self.x[0:2], DataFrame) assert not isinstance(self.x[0:2], list) assert not isinstance(self.x[0:2], Array) assert isinstance(self.x[0:3:2], DataFrame) assert not isinstance(self.x[0:3:2], list) assert not isinstance(self.x[0:3:2], Array) assert isinstance(self.x[0:], DataFrame) assert not isinstance(self.x[0:], list) assert not isinstance(self.x[0:], Array) assert isinstance(self.x[1:], DataFrame) assert not isinstance(self.x[1:], list) assert not isinstance(self.x[1:], Array) assert isinstance(self.x[2:], DataFrame) assert not isinstance(self.x[2:], list) assert not isinstance(self.x[2:], Array) # Empty dataframe assert isinstance(self.x[3:], DataFrame) assert not isinstance(self.x[3:], list) assert not isinstance(self.x[3:], Array) assert isinstance(self.x[4:], DataFrame) assert not isinstance(self.x[4:], list) assert not isinstance(self.x[4:], Array) assert isinstance(self.x[5:], DataFrame) assert not isinstance(self.x[5:], list) assert not isinstance(self.x[5:], Array) # Reverse assert isinstance(self.x[::-1], DataFrame) assert not isinstance(self.x[::-1], list) assert not isinstance(self.x[::-1], Array) def test_invalid_slice_indexing(self): with pytest.raises(TypeError): self.x[0.0:] with pytest.raises(TypeError): self.x[0.0:1.0] with pytest.raises(TypeError): self.x[0.0:2.0] with pytest.raises(TypeError): self.x[0.0:3.0:1] with pytest.raises(TypeError): self.x[0.0:3:1] with pytest.raises(TypeError): self.x[0:3:1.0]
class TestScalarTypeSingleIndexing: x = DataFrame({'a': [1, 2, 3], 'b': ['a', 'b', 'c']}) def test_valid_int_indexing(self): ''' Ensure that int indexing works correctly ''' assert isinstance(self.x[0], Array) assert not isinstance(self.x[0], DataFrame) assert self.x[0].equals(Array([1, 2, 3])) assert isinstance(self.x[1], Array) assert not isinstance(self.x[1], DataFrame) assert self.x[1].equals(Array(['a', 'b', 'c'])) assert isinstance(self.x[-1], Array) assert not isinstance(self.x[-1], DataFrame) assert self.x[-1].equals(Array(['a', 'b', 'c'])) assert isinstance(self.x[-2], Array) assert not isinstance(self.x[-2], DataFrame) assert self.x[-2].equals(Array([1, 2, 3])) def test_invalid_int_indexing(self): ''' Ensure that int indexing throws an error when needed ''' with pytest.raises(IndexError): self.x[2] with pytest.raises(IndexError): self.x[3] with pytest.raises(IndexError): self.x[100] with pytest.raises(IndexError): self.x[-3] with pytest.raises(IndexError): self.x[-4] def test_valid_float_indexing(self): ''' No float index can be valid ''' pass def test_invalid_float_indexing(self): ''' Float indexing should always return an error ''' with pytest.raises(KeyError): self.x[0.0] with pytest.raises(KeyError): self.x[1.0] with pytest.raises(KeyError): self.x[-1.0] with pytest.raises(KeyError): self.x[87932.983993] def test_valid_str_indexing(self): assert isinstance(self.x['a'], Array) assert not isinstance(self.x['a'], DataFrame) assert self.x['a'].equals(Array([1, 2, 3])) assert isinstance(self.x['b'], Array) assert not isinstance(self.x['b'], DataFrame) assert self.x['b'].equals(Array(['a', 'b', 'c'])) def test_invalid_str_indexing(self): with pytest.raises(KeyError): self.x['c'] with pytest.raises(KeyError): self.x[''] with pytest.raises(KeyError): self.x[' '] with pytest.raises(KeyError): self.x['invalid index']
class TestListSingleIndexing: ''' These should return dataframes and not underlying list objects ''' x = DataFrame({ 'a': [1, 2, 3], 'b': ['a', 'b', 'c'], 'c': [True, False, True] }) def test_valid_list_of_int_indexing(self): assert isinstance(self.x[[0]], DataFrame) assert not isinstance(self.x[[0]], list) assert not isinstance(self.x[[0]], Array) assert isinstance(self.x[[0]], DataFrame) assert not isinstance(self.x[[-1]], list) assert not isinstance(self.x[[-1]], Array) assert isinstance(self.x[[-2]], DataFrame) assert not isinstance(self.x[[-2]], list) assert not isinstance(self.x[[-2]], Array) assert isinstance(self.x[[0, 1, 2]], DataFrame) assert not isinstance(self.x[[0, 1, 2]], list) assert not isinstance(self.x[[0, 1, 2]], Array) def test_valid_list_of_str_indexing(self): assert isinstance(self.x[['a']], DataFrame) assert not isinstance(self.x[['a']], list) assert not isinstance(self.x[['a']], Array) assert isinstance(self.x[['a', 'b']], DataFrame) assert not isinstance(self.x[['a', 'b']], list) assert not isinstance(self.x[['a', 'b']], Array) assert isinstance(self.x[['a', 'b', 'c']], DataFrame) assert not isinstance(self.x[['a', 'b', 'c']], list) assert not isinstance(self.x[['a', 'b', 'c']], Array) def test_invalid_list_of_int_indexing(self): # Repeated columns cannot be returned because a dataframe # always has unique column names with pytest.raises(Exception): self.x[[0, 0]] with pytest.raises(Exception): self.x[[0, 0, 1]] with pytest.raises(Exception): self.x[[0, 0, 0]] with pytest.raises(Exception): self.x[[0, 0, 0]] with pytest.raises(Exception): self.x[[0, 0, 1, 1]] # Test out of range error with pytest.raises(IndexError): self.x[[3]] with pytest.raises(IndexError): self.x[[3, 4]] with pytest.raises(IndexError): self.x[[0, 1, 3]] with pytest.raises(IndexError): self.x[[0, 3]] with pytest.raises(IndexError): self.x[[-4]] with pytest.raises(IndexError): self.x[[-5]] def test_invalid_list_of_str_indexing(self): # Repeated columns cannot be returned because a dataframe # always has unique column names with pytest.raises(Exception): self.x[['a', 'a']] with pytest.raises(Exception): self.x[['a', 'a', 'b']] with pytest.raises(Exception): self.x[['a', 'a', 'a']] with pytest.raises(Exception): self.x[['a', 'a', 'b', 'b']] with pytest.raises(Exception): self.x[['a', 'invalid index']] # Test some common incorrect cases with pytest.raises(KeyError): self.x[['invalid column name']] with pytest.raises(KeyError): self.x[['']] with pytest.raises(KeyError): self.x[[' ']] def test_invalid_mixed_list_indexing(self): ''' Cannot mix int and str indexing ''' with pytest.raises(Exception): self.x[[0, 'a']] with pytest.raises(Exception): self.x[[0, 'b']] with pytest.raises(Exception): self.x[[0, 1, 'a']] with pytest.raises(Exception): self.x[[0, 1, 'c']] with pytest.raises(Exception): self.x[[0, '0']] with pytest.raises(Exception): self.x[[0, '-1']] with pytest.raises(Exception): self.x[[0, 'invalid index']] with pytest.raises(Exception): self.x[[-1, 'invalid index']] with pytest.raises(Exception): self.x[[0, -1, 'invalid index']]
class TestScalarScalarDualIndexing: # Define a dataframe that will be used for testing x = DataFrame({'a': [1, 2, 3], 'b': ['a', 'b', 'c']}) def test_valid_int_int(self): assert self.x[0, 0] == 1 assert self.x[0, 1] == 'a' assert self.x[1, 0] == 2 assert self.x[1, 1] == 'b' assert self.x[2, 0] == 3 assert self.x[2, 1] == 'c' assert self.x[0, -1] == 'a' assert self.x[1, -1] == 'b' assert self.x[2, -1] == 'c' assert self.x[0, -2] == 1 assert self.x[1, -2] == 2 assert self.x[2, -2] == 3 def test_invalid_int_int(self): with pytest.raises(IndexError): self.x[3, 0] with pytest.raises(IndexError): self.x[3, 1] with pytest.raises(IndexError): self.x[3, 2] with pytest.raises(IndexError): self.x[3, 3] with pytest.raises(IndexError): self.x[3, -1] with pytest.raises(IndexError): self.x[3, -2] with pytest.raises(IndexError): self.x[3, -3] with pytest.raises(IndexError): self.x[0, 2] with pytest.raises(IndexError): self.x[0, 3] with pytest.raises(IndexError): self.x[0, -3] with pytest.raises(IndexError): self.x[1, 2] with pytest.raises(IndexError): self.x[1, 3] with pytest.raises(IndexError): self.x[1, -3] with pytest.raises(IndexError): self.x[2, 2] with pytest.raises(IndexError): self.x[2, 3] with pytest.raises(IndexError): self.x[2, -3] with pytest.raises(IndexError): self.x[-4, 0] with pytest.raises(IndexError): self.x[-4, 1] with pytest.raises(IndexError): self.x[-4, 2] with pytest.raises(IndexError): self.x[-4, -3] with pytest.raises(IndexError): self.x[10, 1] with pytest.raises(IndexError): self.x[1, 10] with pytest.raises(IndexError): self.x[10, 10] def test_valid_int_str(self): assert self.x[0, 'a'] == 1 assert self.x[1, 'a'] == 2 assert self.x[2, 'a'] == 3 assert self.x[-1, 'a'] == 3 assert self.x[-2, 'a'] == 2 assert self.x[-3, 'a'] == 1 assert self.x[0, 'b'] == 'a' assert self.x[1, 'b'] == 'b' assert self.x[2, 'b'] == 'c' assert self.x[-1, 'b'] == 'c' assert self.x[-2, 'b'] == 'b' assert self.x[-3, 'b'] == 'a' def test_invalid_int_str(self): with pytest.raises(KeyError): self.x[0, 'c'] with pytest.raises(KeyError): self.x[0, 'invalid column'] with pytest.raises(KeyError): self.x[0, ' '] with pytest.raises(KeyError): self.x[0, ''] with pytest.raises(KeyError): self.x[1, 'c'] with pytest.raises(KeyError): self.x[1, 'invalid column'] with pytest.raises(KeyError): self.x[1, ' '] with pytest.raises(KeyError): self.x[1, ''] with pytest.raises(KeyError): self.x[2, 'c'] with pytest.raises(KeyError): self.x[2, 'invalid column'] with pytest.raises(KeyError): self.x[2, ' '] with pytest.raises(KeyError): self.x[2, ''] with pytest.raises(KeyError): self.x[3, 'c'] with pytest.raises(KeyError): self.x[3, 'invalid column'] with pytest.raises(KeyError): self.x[3, ' '] with pytest.raises(KeyError): self.x[3, ''] with pytest.raises(KeyError): self.x[-1, 'c'] with pytest.raises(KeyError): self.x[-1, 'invalid column'] with pytest.raises(KeyError): self.x[-1, ' '] with pytest.raises(KeyError): self.x[-1, ''] with pytest.raises(KeyError): self.x[-2, 'c'] with pytest.raises(KeyError): self.x[-2, 'invalid column'] with pytest.raises(KeyError): self.x[-2, ' '] with pytest.raises(KeyError): self.x[-2, ''] with pytest.raises(IndexError): self.x[3, 'a'] with pytest.raises(IndexError): self.x[4, 'a'] with pytest.raises(IndexError): self.x[-4, 'a'] with pytest.raises(IndexError): self.x[-5, 'a'] with pytest.raises(IndexError): self.x[3, 'b'] with pytest.raises(IndexError): self.x[4, 'b'] with pytest.raises(IndexError): self.x[-4, 'b'] with pytest.raises(IndexError): self.x[-5, 'b'] with pytest.raises(KeyError): self.x[3, 'invalid column'] with pytest.raises(KeyError): self.x[4, 'invalid column'] with pytest.raises(KeyError): self.x[-4, 'invalid column'] with pytest.raises(KeyError): self.x[-5, 'invalid column'] with pytest.raises(KeyError): self.x[3, ' '] with pytest.raises(KeyError): self.x[4, ' '] with pytest.raises(KeyError): self.x[-4, ' '] with pytest.raises(KeyError): self.x[-5, ' '] with pytest.raises(KeyError): self.x[3, ''] with pytest.raises(KeyError): self.x[4, ''] with pytest.raises(KeyError): self.x[-4, ''] with pytest.raises(KeyError): self.x[-5, ''] def test_valid_str_int(self): ''' Rows cannot be addressed by str ''' pass def test_invalid_str_int(self): ''' Rows cannot be addressed by str ''' with pytest.raises(TypeError): self.x['a', 0] with pytest.raises(TypeError): self.x['a', 1] with pytest.raises(IndexError): self.x['a', 2] with pytest.raises(IndexError): self.x['a', 3] with pytest.raises(TypeError): self.x['a', -1] with pytest.raises(TypeError): self.x['a', -2] with pytest.raises(IndexError): self.x['a', -3] with pytest.raises(TypeError): self.x['b', 0] with pytest.raises(TypeError): self.x['b', 1] with pytest.raises(IndexError): self.x['b', 2] with pytest.raises(IndexError): self.x['b', 3] with pytest.raises(TypeError): self.x['b', -1] with pytest.raises(TypeError): self.x['b', -2] with pytest.raises(IndexError): self.x['b', -3] with pytest.raises(TypeError): self.x['', 0] with pytest.raises(TypeError): self.x['', 1] with pytest.raises(IndexError): self.x['', 2] with pytest.raises(IndexError): self.x['', 3] with pytest.raises(TypeError): self.x['', -1] with pytest.raises(TypeError): self.x['', -2] with pytest.raises(IndexError): self.x['', -3] with pytest.raises(TypeError): self.x[' ', 0] with pytest.raises(TypeError): self.x[' ', 1] with pytest.raises(IndexError): self.x[' ', 2] with pytest.raises(IndexError): self.x[' ', 3] with pytest.raises(TypeError): self.x[' ', -1] with pytest.raises(TypeError): self.x[' ', -2] with pytest.raises(IndexError): self.x[' ', -3] with pytest.raises(TypeError): self.x['invalid column', 0] with pytest.raises(TypeError): self.x['invalid column', 1] with pytest.raises(IndexError): self.x['invalid column', 2] with pytest.raises(IndexError): self.x['invalid column', 3] with pytest.raises(TypeError): self.x['invalid column', -1] with pytest.raises(TypeError): self.x['invalid column', -2] with pytest.raises(IndexError): self.x['invalid column', -3] def test_valid_str_str(self): ''' Rows cannot be addressed by str ''' pass def test_invalid_str_str(self): ''' Rows cannot be addressed by str ''' with pytest.raises(TypeError): self.x['a', 'a'] with pytest.raises(TypeError): self.x['a', 'b'] with pytest.raises(KeyError): self.x['a', 'c'] with pytest.raises(KeyError): self.x['a', ''] with pytest.raises(KeyError): self.x['a', ' '] with pytest.raises(KeyError): self.x['a', 'invalid column'] with pytest.raises(TypeError): self.x['b', 'a'] with pytest.raises(TypeError): self.x['b', 'b'] with pytest.raises(KeyError): self.x['b', 'c'] with pytest.raises(KeyError): self.x['b', ''] with pytest.raises(KeyError): self.x['b', ' '] with pytest.raises(KeyError): self.x['b', 'invalid column'] with pytest.raises(TypeError): self.x['', 'a'] with pytest.raises(TypeError): self.x['', 'b'] with pytest.raises(KeyError): self.x['', 'c'] with pytest.raises(KeyError): self.x['', ''] with pytest.raises(KeyError): self.x['', ' '] with pytest.raises(KeyError): self.x['', 'invalid column'] with pytest.raises(TypeError): self.x[' ', 'a'] with pytest.raises(TypeError): self.x[' ', 'b'] with pytest.raises(KeyError): self.x[' ', 'c'] with pytest.raises(KeyError): self.x[' ', ''] with pytest.raises(KeyError): self.x[' ', ' '] with pytest.raises(KeyError): self.x[' ', 'invalid column'] with pytest.raises(TypeError): self.x['invalid column', 'a'] with pytest.raises(TypeError): self.x['invalid column', 'b'] with pytest.raises(KeyError): self.x['invalid column', 'c'] with pytest.raises(KeyError): self.x['invalid column', ''] with pytest.raises(KeyError): self.x['invalid column', ' '] with pytest.raises(KeyError): self.x['invalid column', 'invalid column']
def test_invalid_construction(self): with pytest.raises(ValueError): DataFrame.from_columns([], ['a']) with pytest.raises(ValueError): DataFrame.from_columns([], ['']) with pytest.raises(ValueError): DataFrame.from_columns(self.y) with pytest.raises(ValueError): DataFrame.from_columns(self.y, self.names) with pytest.raises(ValueError): DataFrame.from_columns(self.x, self.names[0:2]) with pytest.raises(ValueError): DataFrame.from_columns(self.y, self.names[0:2]) with pytest.raises(Exception): DataFrame.from_columns(1, self.names[0:2])
def test_invalid_construction(self): with pytest.raises(TypeError): DataFrame.from_shape() with pytest.raises(ValueError): DataFrame.from_shape((0, )) with pytest.raises(ValueError): DataFrame.from_shape(()) with pytest.raises(ValueError): DataFrame.from_shape((-1, 0)) with pytest.raises(ValueError): DataFrame.from_shape((0, -1)) with pytest.raises(ValueError): DataFrame.from_shape((-1, -3)) with pytest.raises(ValueError): DataFrame.from_shape((1.0, -3)) with pytest.raises(ValueError): DataFrame.from_shape((1.0, 1)) with pytest.raises(ValueError): DataFrame.from_shape((10, 1.0))
def test_invalid_construction(self): with pytest.raises(ValueError): DataFrame.from_pandas(pd.Series()) with pytest.raises(ValueError): DataFrame.from_pandas(pd.Series([1, 2, 3]))