本文整理汇总了Python中pandas.compat.PY36属性的典型用法代码示例。如果您正苦于以下问题:Python compat.PY36属性的具体用法?Python compat.PY36怎么用?Python compat.PY36使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pandas.compat
的用法示例。
在下文中一共展示了compat.PY36属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_module
# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import PY36 [as 别名]
def import_module(name):
# we *only* want to skip if the module is truly not available
# and NOT just an actual import error because of pandas changes
if PY36:
try:
return importlib.import_module(name)
except ModuleNotFoundError: # noqa
pytest.skip("skipping as {} not available".format(name))
else:
try:
return importlib.import_module(name)
except ImportError as e:
if "No module named" in str(e) and name in str(e):
pytest.skip("skipping as {} not available".format(name))
raise
示例2: test_assign_order
# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import PY36 [as 别名]
def test_assign_order(self):
# GH 9818
df = DataFrame([[1, 2], [3, 4]], columns=['A', 'B'])
result = df.assign(D=df.A + df.B, C=df.A - df.B)
if PY36:
expected = DataFrame([[1, 2, 3, -1], [3, 4, 7, -1]],
columns=list('ABDC'))
else:
expected = DataFrame([[1, 2, -1, 3], [3, 4, -1, 7]],
columns=list('ABCD'))
assert_frame_equal(result, expected)
result = df.assign(C=df.A - df.B, D=df.A + df.B)
expected = DataFrame([[1, 2, -1, 3], [3, 4, -1, 7]],
columns=list('ABCD'))
assert_frame_equal(result, expected)
示例3: _is_unorderable_exception
# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import PY36 [as 别名]
def _is_unorderable_exception(e):
"""
Check if the exception raised is an unorderable exception.
The error message differs for 3 <= PY <= 3.5 and PY >= 3.6, so
we need to condition based on Python version.
Parameters
----------
e : Exception or sub-class
The exception object to check.
Returns
-------
boolean : Whether or not the exception raised is an unorderable exception.
"""
if PY36:
return "'>' not supported between instances of" in str(e)
elif PY3:
return 'unorderable' in str(e)
return False
示例4: test_constructor_dict_order
# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import PY36 [as 别名]
def test_constructor_dict_order(self):
# GH19018
# initialization ordering: by insertion order if python>= 3.6, else
# order by value
d = {'b': 1, 'a': 0, 'c': 2}
result = SparseSeries(d)
if PY36:
expected = SparseSeries([1, 0, 2], index=list('bac'))
else:
expected = SparseSeries([0, 1, 2], index=list('abc'))
tm.assert_sp_series_equal(result, expected)
示例5: test_constructor_dict_order
# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import PY36 [as 别名]
def test_constructor_dict_order(self):
# GH19018
# initialization ordering: by insertion order if python>= 3.6, else
# order by value
d = {'b': [2, 3], 'a': [0, 1]}
frame = SparseDataFrame(data=d)
if compat.PY36:
expected = SparseDataFrame(data=d, columns=list('ba'))
else:
expected = SparseDataFrame(data=d, columns=list('ab'))
tm.assert_sp_frame_equal(frame, expected)
示例6: test_constructor_dict_order
# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import PY36 [as 别名]
def test_constructor_dict_order(self):
# GH19018
# initialization ordering: by insertion order if python>= 3.6, else
# order by value
d = {'b': 1, 'a': 0, 'c': 2}
result = Series(d)
if PY36:
expected = Series([1, 0, 2], index=list('bac'))
else:
expected = Series([0, 1, 2], index=list('abc'))
tm.assert_series_equal(result, expected)
示例7: dict_keys_to_ordered_list
# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import PY36 [as 别名]
def dict_keys_to_ordered_list(mapping):
# when pandas drops support for Python < 3.6, this function
# can be replaced by a simple list(mapping.keys())
if PY36 or isinstance(mapping, OrderedDict):
keys = list(mapping.keys())
else:
keys = try_sort(mapping)
return keys
示例8: _dict_keys_to_ordered_list
# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import PY36 [as 别名]
def _dict_keys_to_ordered_list(mapping):
# when pandas drops support for Python < 3.6, this function
# can be replaced by a simple list(mapping.keys())
if PY36 or isinstance(mapping, OrderedDict):
keys = list(mapping.keys())
else:
keys = _try_sort(mapping)
return keys
示例9: test_transactions
# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import PY36 [as 别名]
def test_transactions(self):
if PY36:
pytest.skip("not working on python > 3.5")
self._transaction_test()