Python pandas.core.dtypes.common.is_integer_dtype() Examples
The following are 28
code examples of pandas.core.dtypes.common.is_integer_dtype().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pandas.core.dtypes.common
, or try the search function
.
Example #1
Source File: test_nanops.py From twitter-stock-recommendation with MIT License | 6 votes |
def test_returned_dtype(self): dtypes = [np.int16, np.int32, np.int64, np.float32, np.float64] if hasattr(np, 'float128'): dtypes.append(np.float128) for dtype in dtypes: s = Series(range(10), dtype=dtype) group_a = ['mean', 'std', 'var', 'skew', 'kurt'] group_b = ['min', 'max'] for method in group_a + group_b: result = getattr(s, method)() if is_integer_dtype(dtype) and method in group_a: assert result.dtype == np.float64 else: assert result.dtype == dtype
Example #2
Source File: test_indexing.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_setitem_dtype_upcast(self): # GH3216 df = DataFrame([{"a": 1}, {"a": 3, "b": 2}]) df['c'] = np.nan assert df['c'].dtype == np.float64 df.loc[0, 'c'] = 'foo' expected = DataFrame([{"a": 1, "c": 'foo'}, {"a": 3, "b": 2, "c": np.nan}]) tm.assert_frame_equal(df, expected) # GH10280 df = DataFrame(np.arange(6, dtype='int64').reshape(2, 3), index=list('ab'), columns=['foo', 'bar', 'baz']) for val in [3.14, 'wxyz']: left = df.copy() left.loc['a', 'bar'] = val right = DataFrame([[0, val, 2], [3, 4, 5]], index=list('ab'), columns=['foo', 'bar', 'baz']) tm.assert_frame_equal(left, right) assert is_integer_dtype(left['foo']) assert is_integer_dtype(left['baz']) left = DataFrame(np.arange(6, dtype='int64').reshape(2, 3) / 10.0, index=list('ab'), columns=['foo', 'bar', 'baz']) left.loc['a', 'bar'] = 'wxyz' right = DataFrame([[0, 'wxyz', .2], [.3, .4, .5]], index=list('ab'), columns=['foo', 'bar', 'baz']) tm.assert_frame_equal(left, right) assert is_float_dtype(left['foo']) assert is_float_dtype(left['baz'])
Example #3
Source File: test_common.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_is_integer_dtype(): assert not com.is_integer_dtype(str) assert not com.is_integer_dtype(float) assert not com.is_integer_dtype(np.datetime64) assert not com.is_integer_dtype(np.timedelta64) assert not com.is_integer_dtype(pd.Index([1, 2.])) assert not com.is_integer_dtype(np.array(['a', 'b'])) assert not com.is_integer_dtype(np.array([], dtype=np.timedelta64)) assert com.is_integer_dtype(int) assert com.is_integer_dtype(np.uint64) assert com.is_integer_dtype(pd.Series([1, 2]))
Example #4
Source File: test_constructors.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_constructor_list_of_lists(self): # GH #484 l = [[1, 'a'], [2, 'b']] df = DataFrame(data=l, columns=["num", "str"]) assert is_integer_dtype(df['num']) assert df['str'].dtype == np.object_ # GH 4851 # list of 0-dim ndarrays expected = DataFrame({0: np.arange(10)}) data = [np.array(x) for x in range(10)] result = DataFrame(data) tm.assert_frame_equal(result, expected)
Example #5
Source File: test_multilevel.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_delevel_infer_dtype(self): tuples = [tuple for tuple in cart_product( ['foo', 'bar'], [10, 20], [1.0, 1.1])] index = MultiIndex.from_tuples(tuples, names=['prm0', 'prm1', 'prm2']) df = DataFrame(np.random.randn(8, 3), columns=['A', 'B', 'C'], index=index) deleveled = df.reset_index() assert is_integer_dtype(deleveled['prm1']) assert is_float_dtype(deleveled['prm2'])
Example #6
Source File: test_multilevel.py From coffeegrindsize with MIT License | 5 votes |
def test_delevel_infer_dtype(self): tuples = [tuple for tuple in cart_product( ['foo', 'bar'], [10, 20], [1.0, 1.1])] index = MultiIndex.from_tuples(tuples, names=['prm0', 'prm1', 'prm2']) df = DataFrame(np.random.randn(8, 3), columns=['A', 'B', 'C'], index=index) deleveled = df.reset_index() assert is_integer_dtype(deleveled['prm1']) assert is_float_dtype(deleveled['prm2'])
Example #7
Source File: test_common.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_is_integer_dtype(): assert not com.is_integer_dtype(str) assert not com.is_integer_dtype(float) assert not com.is_integer_dtype(np.datetime64) assert not com.is_integer_dtype(np.timedelta64) assert not com.is_integer_dtype(pd.Index([1, 2.])) assert not com.is_integer_dtype(np.array(['a', 'b'])) assert not com.is_integer_dtype(np.array([], dtype=np.timedelta64)) assert com.is_integer_dtype(int) assert com.is_integer_dtype(np.uint64) assert com.is_integer_dtype(pd.Series([1, 2]))
Example #8
Source File: test_constructors.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_constructor_list_of_lists(self): # GH #484 l = [[1, 'a'], [2, 'b']] df = DataFrame(data=l, columns=["num", "str"]) assert is_integer_dtype(df['num']) assert df['str'].dtype == np.object_ # GH 4851 # list of 0-dim ndarrays expected = DataFrame({0: np.arange(10)}) data = [np.array(x) for x in range(10)] result = DataFrame(data) tm.assert_frame_equal(result, expected)
Example #9
Source File: test_nanops.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_returned_dtype(self): dtypes = [np.int16, np.int32, np.int64, np.float32, np.float64] if hasattr(np, 'float128'): dtypes.append(np.float128) for dtype in dtypes: s = Series(range(10), dtype=dtype) group_a = ['mean', 'std', 'var', 'skew', 'kurt'] group_b = ['min', 'max'] for method in group_a + group_b: result = getattr(s, method)() if is_integer_dtype(dtype) and method in group_a: assert result.dtype == np.float64 else: assert result.dtype == dtype
Example #10
Source File: test_multilevel.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_delevel_infer_dtype(self): tuples = [tuple for tuple in cart_product( ['foo', 'bar'], [10, 20], [1.0, 1.1])] index = MultiIndex.from_tuples(tuples, names=['prm0', 'prm1', 'prm2']) df = DataFrame(np.random.randn(8, 3), columns=['A', 'B', 'C'], index=index) deleveled = df.reset_index() assert is_integer_dtype(deleveled['prm1']) assert is_float_dtype(deleveled['prm2'])
Example #11
Source File: test_common.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_is_signed_integer_dtype(dtype): assert com.is_integer_dtype(dtype)
Example #12
Source File: test_common.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_is_not_integer_dtype(dtype): assert not com.is_integer_dtype(dtype)
Example #13
Source File: test_constructors.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_constructor_list_of_lists(self): # GH #484 df = DataFrame(data=[[1, 'a'], [2, 'b']], columns=["num", "str"]) assert is_integer_dtype(df['num']) assert df['str'].dtype == np.object_ # GH 4851 # list of 0-dim ndarrays expected = DataFrame({0: np.arange(10)}) data = [np.array(x) for x in range(10)] result = DataFrame(data) tm.assert_frame_equal(result, expected)
Example #14
Source File: test_multilevel.py From recruit with Apache License 2.0 | 5 votes |
def test_delevel_infer_dtype(self): tuples = [tuple for tuple in cart_product( ['foo', 'bar'], [10, 20], [1.0, 1.1])] index = MultiIndex.from_tuples(tuples, names=['prm0', 'prm1', 'prm2']) df = DataFrame(np.random.randn(8, 3), columns=['A', 'B', 'C'], index=index) deleveled = df.reset_index() assert is_integer_dtype(deleveled['prm1']) assert is_float_dtype(deleveled['prm2'])
Example #15
Source File: test_nanops.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_returned_dtype(self): dtypes = [np.int16, np.int32, np.int64, np.float32, np.float64] if hasattr(np, 'float128'): dtypes.append(np.float128) for dtype in dtypes: s = Series(range(10), dtype=dtype) group_a = ['mean', 'std', 'var', 'skew', 'kurt'] group_b = ['min', 'max'] for method in group_a + group_b: result = getattr(s, method)() if is_integer_dtype(dtype) and method in group_a: assert result.dtype == np.float64 else: assert result.dtype == dtype
Example #16
Source File: test_multilevel.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_delevel_infer_dtype(self): tuples = [tuple for tuple in cart_product( ['foo', 'bar'], [10, 20], [1.0, 1.1])] index = MultiIndex.from_tuples(tuples, names=['prm0', 'prm1', 'prm2']) df = DataFrame(np.random.randn(8, 3), columns=['A', 'B', 'C'], index=index) deleveled = df.reset_index() assert is_integer_dtype(deleveled['prm1']) assert is_float_dtype(deleveled['prm2'])
Example #17
Source File: test_common.py From vnpy_crypto with MIT License | 5 votes |
def test_is_integer_dtype(): assert not com.is_integer_dtype(str) assert not com.is_integer_dtype(float) assert not com.is_integer_dtype(np.datetime64) assert not com.is_integer_dtype(np.timedelta64) assert not com.is_integer_dtype(pd.Index([1, 2.])) assert not com.is_integer_dtype(np.array(['a', 'b'])) assert not com.is_integer_dtype(np.array([], dtype=np.timedelta64)) assert com.is_integer_dtype(int) assert com.is_integer_dtype(np.uint64) assert com.is_integer_dtype(pd.Series([1, 2]))
Example #18
Source File: test_constructors.py From vnpy_crypto with MIT License | 5 votes |
def test_constructor_list_of_lists(self): # GH #484 l = [[1, 'a'], [2, 'b']] df = DataFrame(data=l, columns=["num", "str"]) assert is_integer_dtype(df['num']) assert df['str'].dtype == np.object_ # GH 4851 # list of 0-dim ndarrays expected = DataFrame({0: np.arange(10)}) data = [np.array(x) for x in range(10)] result = DataFrame(data) tm.assert_frame_equal(result, expected)
Example #19
Source File: test_nanops.py From vnpy_crypto with MIT License | 5 votes |
def test_returned_dtype(self): dtypes = [np.int16, np.int32, np.int64, np.float32, np.float64] if hasattr(np, 'float128'): dtypes.append(np.float128) for dtype in dtypes: s = Series(range(10), dtype=dtype) group_a = ['mean', 'std', 'var', 'skew', 'kurt'] group_b = ['min', 'max'] for method in group_a + group_b: result = getattr(s, method)() if is_integer_dtype(dtype) and method in group_a: assert result.dtype == np.float64 else: assert result.dtype == dtype
Example #20
Source File: test_multilevel.py From vnpy_crypto with MIT License | 5 votes |
def test_delevel_infer_dtype(self): tuples = [tuple for tuple in cart_product( ['foo', 'bar'], [10, 20], [1.0, 1.1])] index = MultiIndex.from_tuples(tuples, names=['prm0', 'prm1', 'prm2']) df = DataFrame(np.random.randn(8, 3), columns=['A', 'B', 'C'], index=index) deleveled = df.reset_index() assert is_integer_dtype(deleveled['prm1']) assert is_float_dtype(deleveled['prm2'])
Example #21
Source File: test_common.py From recruit with Apache License 2.0 | 5 votes |
def test_is_signed_integer_dtype(dtype): assert com.is_integer_dtype(dtype)
Example #22
Source File: test_common.py From recruit with Apache License 2.0 | 5 votes |
def test_is_not_integer_dtype(dtype): assert not com.is_integer_dtype(dtype)
Example #23
Source File: test_constructors.py From recruit with Apache License 2.0 | 5 votes |
def test_constructor_list_of_lists(self): # GH #484 df = DataFrame(data=[[1, 'a'], [2, 'b']], columns=["num", "str"]) assert is_integer_dtype(df['num']) assert df['str'].dtype == np.object_ # GH 4851 # list of 0-dim ndarrays expected = DataFrame({0: np.arange(10)}) data = [np.array(x) for x in range(10)] result = DataFrame(data) tm.assert_frame_equal(result, expected)
Example #24
Source File: test_indexing.py From recruit with Apache License 2.0 | 5 votes |
def test_setitem_dtype_upcast(self): # GH3216 df = DataFrame([{"a": 1}, {"a": 3, "b": 2}]) df['c'] = np.nan assert df['c'].dtype == np.float64 df.loc[0, 'c'] = 'foo' expected = DataFrame([{"a": 1, "c": 'foo'}, {"a": 3, "b": 2, "c": np.nan}]) tm.assert_frame_equal(df, expected) # GH10280 df = DataFrame(np.arange(6, dtype='int64').reshape(2, 3), index=list('ab'), columns=['foo', 'bar', 'baz']) for val in [3.14, 'wxyz']: left = df.copy() left.loc['a', 'bar'] = val right = DataFrame([[0, val, 2], [3, 4, 5]], index=list('ab'), columns=['foo', 'bar', 'baz']) tm.assert_frame_equal(left, right) assert is_integer_dtype(left['foo']) assert is_integer_dtype(left['baz']) left = DataFrame(np.arange(6, dtype='int64').reshape(2, 3) / 10.0, index=list('ab'), columns=['foo', 'bar', 'baz']) left.loc['a', 'bar'] = 'wxyz' right = DataFrame([[0, 'wxyz', .2], [.3, .4, .5]], index=list('ab'), columns=['foo', 'bar', 'baz']) tm.assert_frame_equal(left, right) assert is_float_dtype(left['foo']) assert is_float_dtype(left['baz'])
Example #25
Source File: test_reshape.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 4 votes |
def test_basic_types(self, sparse, dtype): # GH 10531 s_list = list('abc') s_series = Series(s_list) s_df = DataFrame({'a': [0, 1, 0, 1, 2], 'b': ['A', 'A', 'B', 'C', 'C'], 'c': [2, 3, 3, 3, 2]}) expected = DataFrame({'a': [1, 0, 0], 'b': [0, 1, 0], 'c': [0, 0, 1]}, dtype=self.effective_dtype(dtype), columns=list('abc')) if sparse: if is_integer_dtype(dtype): fill_value = 0 elif dtype == bool: fill_value = False else: fill_value = 0.0 expected = expected.apply(SparseArray, fill_value=fill_value) result = get_dummies(s_list, sparse=sparse, dtype=dtype) tm.assert_frame_equal(result, expected) result = get_dummies(s_series, sparse=sparse, dtype=dtype) tm.assert_frame_equal(result, expected) result = get_dummies(s_df, columns=s_df.columns, sparse=sparse, dtype=dtype) if sparse: dtype_name = 'Sparse[{}, {}]'.format( self.effective_dtype(dtype).name, fill_value ) else: dtype_name = self.effective_dtype(dtype).name expected = Series({dtype_name: 8}) tm.assert_series_equal(result.get_dtype_counts(), expected) result = get_dummies(s_df, columns=['a'], sparse=sparse, dtype=dtype) expected_counts = {'int64': 1, 'object': 1} expected_counts[dtype_name] = 3 + expected_counts.get(dtype_name, 0) expected = Series(expected_counts).sort_index() tm.assert_series_equal(result.get_dtype_counts().sort_index(), expected)
Example #26
Source File: test_reshape.py From coffeegrindsize with MIT License | 4 votes |
def test_basic_types(self, sparse, dtype): # GH 10531 s_list = list('abc') s_series = Series(s_list) s_df = DataFrame({'a': [0, 1, 0, 1, 2], 'b': ['A', 'A', 'B', 'C', 'C'], 'c': [2, 3, 3, 3, 2]}) expected = DataFrame({'a': [1, 0, 0], 'b': [0, 1, 0], 'c': [0, 0, 1]}, dtype=self.effective_dtype(dtype), columns=list('abc')) if sparse: if is_integer_dtype(dtype): fill_value = 0 elif dtype == bool: fill_value = False else: fill_value = 0.0 expected = expected.apply(SparseArray, fill_value=fill_value) result = get_dummies(s_list, sparse=sparse, dtype=dtype) tm.assert_frame_equal(result, expected) result = get_dummies(s_series, sparse=sparse, dtype=dtype) tm.assert_frame_equal(result, expected) result = get_dummies(s_df, columns=s_df.columns, sparse=sparse, dtype=dtype) if sparse: dtype_name = 'Sparse[{}, {}]'.format( self.effective_dtype(dtype).name, fill_value ) else: dtype_name = self.effective_dtype(dtype).name expected = Series({dtype_name: 8}) tm.assert_series_equal(result.get_dtype_counts(), expected) result = get_dummies(s_df, columns=['a'], sparse=sparse, dtype=dtype) expected_counts = {'int64': 1, 'object': 1} expected_counts[dtype_name] = 3 + expected_counts.get(dtype_name, 0) expected = Series(expected_counts).sort_index() tm.assert_series_equal(result.get_dtype_counts().sort_index(), expected)
Example #27
Source File: test_nanops.py From recruit with Apache License 2.0 | 4 votes |
def test_returned_dtype(self): dtypes = [np.int16, np.int32, np.int64, np.float32, np.float64] if hasattr(np, 'float128'): dtypes.append(np.float128) for dtype in dtypes: s = Series(range(10), dtype=dtype) group_a = ['mean', 'std', 'var', 'skew', 'kurt'] group_b = ['min', 'max'] for method in group_a + group_b: result = getattr(s, method)() if is_integer_dtype(dtype) and method in group_a: assert result.dtype == np.float64 else: assert result.dtype == dtype
Example #28
Source File: test_reshape.py From recruit with Apache License 2.0 | 4 votes |
def test_basic_types(self, sparse, dtype): # GH 10531 s_list = list('abc') s_series = Series(s_list) s_df = DataFrame({'a': [0, 1, 0, 1, 2], 'b': ['A', 'A', 'B', 'C', 'C'], 'c': [2, 3, 3, 3, 2]}) expected = DataFrame({'a': [1, 0, 0], 'b': [0, 1, 0], 'c': [0, 0, 1]}, dtype=self.effective_dtype(dtype), columns=list('abc')) if sparse: if is_integer_dtype(dtype): fill_value = 0 elif dtype == bool: fill_value = False else: fill_value = 0.0 expected = expected.apply(SparseArray, fill_value=fill_value) result = get_dummies(s_list, sparse=sparse, dtype=dtype) tm.assert_frame_equal(result, expected) result = get_dummies(s_series, sparse=sparse, dtype=dtype) tm.assert_frame_equal(result, expected) result = get_dummies(s_df, columns=s_df.columns, sparse=sparse, dtype=dtype) if sparse: dtype_name = 'Sparse[{}, {}]'.format( self.effective_dtype(dtype).name, fill_value ) else: dtype_name = self.effective_dtype(dtype).name expected = Series({dtype_name: 8}) tm.assert_series_equal(result.get_dtype_counts(), expected) result = get_dummies(s_df, columns=['a'], sparse=sparse, dtype=dtype) expected_counts = {'int64': 1, 'object': 1} expected_counts[dtype_name] = 3 + expected_counts.get(dtype_name, 0) expected = Series(expected_counts).sort_index() tm.assert_series_equal(result.get_dtype_counts().sort_index(), expected)