Python pandas.core.common.standardize_mapping() Examples
The following are 8
code examples of pandas.core.common.standardize_mapping().
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.common
, or try the search function
.
Example #1
Source File: test_common.py From recruit with Apache License 2.0 | 6 votes |
def test_standardize_mapping(): # No uninitialized defaultdicts with pytest.raises(TypeError): com.standardize_mapping(collections.defaultdict) # No non-mapping subtypes, instance with pytest.raises(TypeError): com.standardize_mapping([]) # No non-mapping subtypes, class with pytest.raises(TypeError): com.standardize_mapping(list) fill = {'bad': 'data'} assert (com.standardize_mapping(fill) == dict) # Convert instance to type assert (com.standardize_mapping({}) == dict) dd = collections.defaultdict(list) assert isinstance(com.standardize_mapping(dd), partial)
Example #2
Source File: test_common.py From vnpy_crypto with MIT License | 6 votes |
def test_standardize_mapping(): # No uninitialized defaultdicts with pytest.raises(TypeError): com.standardize_mapping(collections.defaultdict) # No non-mapping subtypes, instance with pytest.raises(TypeError): com.standardize_mapping([]) # No non-mapping subtypes, class with pytest.raises(TypeError): com.standardize_mapping(list) fill = {'bad': 'data'} assert (com.standardize_mapping(fill) == dict) # Convert instance to type assert (com.standardize_mapping({}) == dict) dd = collections.defaultdict(list) assert isinstance(com.standardize_mapping(dd), partial)
Example #3
Source File: test_common.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_standardize_mapping(): # No uninitialized defaultdicts with pytest.raises(TypeError): com.standardize_mapping(collections.defaultdict) # No non-mapping subtypes, instance with pytest.raises(TypeError): com.standardize_mapping([]) # No non-mapping subtypes, class with pytest.raises(TypeError): com.standardize_mapping(list) fill = {'bad': 'data'} assert (com.standardize_mapping(fill) == dict) # Convert instance to type assert (com.standardize_mapping({}) == dict) dd = collections.defaultdict(list) assert isinstance(com.standardize_mapping(dd), partial)
Example #4
Source File: test_common.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def test_standardize_mapping(): # No uninitialized defaultdicts with pytest.raises(TypeError): com.standardize_mapping(collections.defaultdict) # No non-mapping subtypes, instance with pytest.raises(TypeError): com.standardize_mapping([]) # No non-mapping subtypes, class with pytest.raises(TypeError): com.standardize_mapping(list) fill = {'bad': 'data'} assert (com.standardize_mapping(fill) == dict) # Convert instance to type assert (com.standardize_mapping({}) == dict) dd = collections.defaultdict(list) assert isinstance(com.standardize_mapping(dd), partial)
Example #5
Source File: test_common.py From twitter-stock-recommendation with MIT License | 6 votes |
def test_standardize_mapping(): # No uninitialized defaultdicts with pytest.raises(TypeError): com.standardize_mapping(collections.defaultdict) # No non-mapping subtypes, instance with pytest.raises(TypeError): com.standardize_mapping([]) # No non-mapping subtypes, class with pytest.raises(TypeError): com.standardize_mapping(list) fill = {'bad': 'data'} assert (com.standardize_mapping(fill) == dict) # Convert instance to type assert (com.standardize_mapping({}) == dict) dd = collections.defaultdict(list) assert isinstance(com.standardize_mapping(dd), partial)
Example #6
Source File: series.py From recruit with Apache License 2.0 | 5 votes |
def to_dict(self, into=dict): """ Convert Series to {label -> value} dict or dict-like object. Parameters ---------- into : class, default dict The collections.Mapping subclass to use as the return object. Can be the actual class or an empty instance of the mapping type you want. If you want a collections.defaultdict, you must pass it initialized. .. versionadded:: 0.21.0 Returns ------- value_dict : collections.Mapping Examples -------- >>> s = pd.Series([1, 2, 3, 4]) >>> s.to_dict() {0: 1, 1: 2, 2: 3, 3: 4} >>> from collections import OrderedDict, defaultdict >>> s.to_dict(OrderedDict) OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)]) >>> dd = defaultdict(list) >>> s.to_dict(dd) defaultdict(<type 'list'>, {0: 1, 1: 2, 2: 3, 3: 4}) """ # GH16122 into_c = com.standardize_mapping(into) return into_c(compat.iteritems(self))
Example #7
Source File: series.py From vnpy_crypto with MIT License | 5 votes |
def to_dict(self, into=dict): """ Convert Series to {label -> value} dict or dict-like object. Parameters ---------- into : class, default dict The collections.Mapping subclass to use as the return object. Can be the actual class or an empty instance of the mapping type you want. If you want a collections.defaultdict, you must pass it initialized. .. versionadded:: 0.21.0 Returns ------- value_dict : collections.Mapping Examples -------- >>> s = pd.Series([1, 2, 3, 4]) >>> s.to_dict() {0: 1, 1: 2, 2: 3, 3: 4} >>> from collections import OrderedDict, defaultdict >>> s.to_dict(OrderedDict) OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)]) >>> dd = defaultdict(list) >>> s.to_dict(dd) defaultdict(<type 'list'>, {0: 1, 1: 2, 2: 3, 3: 4}) """ # GH16122 into_c = com.standardize_mapping(into) return into_c(compat.iteritems(self))
Example #8
Source File: series.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def to_dict(self, into=dict): """ Convert Series to {label -> value} dict or dict-like object. Parameters ---------- into : class, default dict The collections.Mapping subclass to use as the return object. Can be the actual class or an empty instance of the mapping type you want. If you want a collections.defaultdict, you must pass it initialized. .. versionadded:: 0.21.0 Returns ------- value_dict : collections.Mapping Examples -------- >>> s = pd.Series([1, 2, 3, 4]) >>> s.to_dict() {0: 1, 1: 2, 2: 3, 3: 4} >>> from collections import OrderedDict, defaultdict >>> s.to_dict(OrderedDict) OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)]) >>> dd = defaultdict(list) >>> s.to_dict(dd) defaultdict(<type 'list'>, {0: 1, 1: 2, 2: 3, 3: 4}) """ # GH16122 into_c = com.standardize_mapping(into) return into_c(compat.iteritems(self))