本文整理汇总了Python中pandas.testing.assert_frame_equal方法的典型用法代码示例。如果您正苦于以下问题:Python testing.assert_frame_equal方法的具体用法?Python testing.assert_frame_equal怎么用?Python testing.assert_frame_equal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.testing
的用法示例。
在下文中一共展示了testing.assert_frame_equal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_iterative
# 需要导入模块: from pandas import testing [as 别名]
# 或者: from pandas.testing import assert_frame_equal [as 别名]
def test_iterative(self):
"""Test the iterative behaviour."""
# SINGLE STEP
index_class = Full()
pairs = index_class.index((self.a, self.b))
pairs = pd.DataFrame(index=pairs).sort_index()
# MULTI STEP
index_class = Full()
pairs1 = index_class.index((self.a[0:50], self.b))
pairs2 = index_class.index((self.a[50:100], self.b))
pairs_split = pairs1.append(pairs2)
pairs_split = pd.DataFrame(index=pairs_split).sort_index()
pdt.assert_frame_equal(pairs, pairs_split)
# note possible to sort MultiIndex, so made a frame out of it.
示例2: test_compare_custom_instance_type
# 需要导入模块: from pandas import testing [as 别名]
# 或者: from pandas.testing import assert_frame_equal [as 别名]
def test_compare_custom_instance_type(self):
A = DataFrame({'col': ['abc', 'abc', 'abc', 'abc', 'abc']})
B = DataFrame({'col': ['abc', 'abd', 'abc', 'abc', '123']})
ix = MultiIndex.from_arrays([A.index.values, B.index.values])
def call(s1, s2):
# this should raise on incorrect types
assert isinstance(s1, np.ndarray)
assert isinstance(s2, np.ndarray)
return np.ones(len(s1), dtype=np.int)
comp = recordlinkage.Compare()
comp.compare_vectorized(lambda s1, s2: np.ones(len(s1), dtype=np.int),
'col', 'col')
result = comp.compute(ix, A, B)
expected = DataFrame([1, 1, 1, 1, 1], index=ix)
pdt.assert_frame_equal(result, expected)
示例3: test_compare_custom_vectorized_dedup
# 需要导入模块: from pandas import testing [as 别名]
# 或者: from pandas.testing import assert_frame_equal [as 别名]
def test_compare_custom_vectorized_dedup(self):
A = DataFrame({'col': ['abc', 'abc', 'abc', 'abc', 'abc']})
ix = MultiIndex.from_arrays([[0, 1, 2, 3, 4], [1, 2, 3, 4, 0]])
# test without label
comp = recordlinkage.Compare()
comp.compare_vectorized(lambda s1, s2: np.ones(len(s1), dtype=np.int),
'col', 'col')
result = comp.compute(ix, A)
expected = DataFrame([1, 1, 1, 1, 1], index=ix)
pdt.assert_frame_equal(result, expected)
# test with label
comp = recordlinkage.Compare()
comp.compare_vectorized(
lambda s1, s2: np.ones(len(s1), dtype=np.int),
'col',
'col',
label='test')
result = comp.compute(ix, A)
expected = DataFrame([1, 1, 1, 1, 1], index=ix, columns=['test'])
pdt.assert_frame_equal(result, expected)
示例4: test_parallel_comparing_api
# 需要导入模块: from pandas import testing [as 别名]
# 或者: from pandas.testing import assert_frame_equal [as 别名]
def test_parallel_comparing_api(self):
# use single job
comp = recordlinkage.Compare(n_jobs=1)
comp.exact('given_name', 'given_name', label='my_feature_label')
result_single = comp.compute(self.index_AB, self.A, self.B)
result_single.sort_index(inplace=True)
# use two jobs
comp = recordlinkage.Compare(n_jobs=2)
comp.exact('given_name', 'given_name', label='my_feature_label')
result_2processes = comp.compute(self.index_AB, self.A, self.B)
result_2processes.sort_index(inplace=True)
# compare results
pdt.assert_frame_equal(result_single, result_2processes)
示例5: test_parallel_comparing
# 需要导入模块: from pandas import testing [as 别名]
# 或者: from pandas.testing import assert_frame_equal [as 别名]
def test_parallel_comparing(self):
# use single job
comp = recordlinkage.Compare(n_jobs=1)
comp.exact('given_name', 'given_name', label='my_feature_label')
result_single = comp.compute(self.index_AB, self.A, self.B)
result_single.sort_index(inplace=True)
# use two jobs
comp = recordlinkage.Compare(n_jobs=2)
comp.exact('given_name', 'given_name', label='my_feature_label')
result_2processes = comp.compute(self.index_AB, self.A, self.B)
result_2processes.sort_index(inplace=True)
# use two jobs
comp = recordlinkage.Compare(n_jobs=4)
comp.exact('given_name', 'given_name', label='my_feature_label')
result_4processes = comp.compute(self.index_AB, self.A, self.B)
result_4processes.sort_index(inplace=True)
# compare results
pdt.assert_frame_equal(result_single, result_2processes)
pdt.assert_frame_equal(result_single, result_4processes)
示例6: test_indexing_types
# 需要导入模块: from pandas import testing [as 别名]
# 或者: from pandas.testing import assert_frame_equal [as 别名]
def test_indexing_types(self):
# test the two types of indexing
# this test needs improvement
A = DataFrame({'col': ['abc', 'abc', 'abc', 'abc', 'abc']})
B = DataFrame({'col': ['abc', 'abc', 'abc', 'abc', 'abc']})
B_reversed = B[::-1].copy()
ix = MultiIndex.from_arrays([np.arange(5), np.arange(5)])
# test with label indexing type
comp_label = recordlinkage.Compare(indexing_type='label')
comp_label.exact('col', 'col')
result_label = comp_label.compute(ix, A, B_reversed)
# test with position indexing type
comp_position = recordlinkage.Compare(indexing_type='position')
comp_position.exact('col', 'col')
result_position = comp_position.compute(ix, A, B_reversed)
assert (result_position.values == 1).all(axis=0)
pdt.assert_frame_equal(result_label, result_position)
示例7: test_freq_nan
# 需要导入模块: from pandas import testing [as 别名]
# 或者: from pandas.testing import assert_frame_equal [as 别名]
def test_freq_nan(self, missing_value):
# data
array_repeated = np.repeat(np.arange(10, dtype=np.float64), 10)
array_repeated[90:] = np.nan
array_tiled = np.tile(np.arange(20, dtype=np.float64), 5)
# convert to pandas data
A = DataFrame({'col': array_repeated})
B = DataFrame({'col': array_tiled})
ix = MultiIndex.from_arrays([A.index.values, B.index.values])
# the part to test
from recordlinkage.compare import Frequency
comp = recordlinkage.Compare()
comp.add(Frequency(left_on='col', missing_value=missing_value))
result = comp.compute(ix, A, B)
expected_np = np.ones((100, )) / 10
expected_np[90:] = missing_value
expected = DataFrame(expected_np, index=ix)
pdt.assert_frame_equal(result, expected)
示例8: test_comparison_plot_inputs
# 需要导入模块: from pandas import testing [as 别名]
# 或者: from pandas.testing import assert_frame_equal [as 别名]
def test_comparison_plot_inputs(input_results, expected_source_dfs, expected_plot_info):
x_padding = 0.0
num_bins = 10
res_source_dfs, res_plot_info = test_module.comparison_plot_inputs(
results=input_results[0],
x_padding=x_padding,
num_bins=num_bins,
color_dict=None,
fig_height=None,
)
assert res_plot_info == expected_plot_info
assert res_source_dfs.keys() == expected_source_dfs.keys()
for group, res_dict in res_source_dfs.items():
for param, res_df in res_dict.items():
exp_df = expected_source_dfs[group][param]
pdt.assert_frame_equal(res_df, exp_df, check_like=True)
示例9: test_get
# 需要导入模块: from pandas import testing [as 别名]
# 或者: from pandas.testing import assert_frame_equal [as 别名]
def test_get(mock):
api_call_result = {'query_0': [{'balance': 212664.33000000002,
'datetime': '2019-05-23T00:00:00Z'},
{'balance': 212664.33000000002,
'datetime': '2019-05-24T00:00:00Z'},
{'balance': 212664.33000000002,
'datetime': '2019-05-25T00:00:00Z'}]}
mock.return_value = TestResponse(
status_code=200, data=deepcopy(api_call_result))
res = san.get(
"historical_balance/santiment",
address="0x1f3df0b8390bb8e9e322972c5e75583e87608ec2",
from_date="2019-05-23",
to_date="2019-05-26",
interval="1d"
)
expected_df = convert_to_datetime_idx_df(api_call_result['query_0'])
pdt.assert_frame_equal(res, expected_df, check_dtype=False)
示例10: test_get_without_transform
# 需要导入模块: from pandas import testing [as 别名]
# 或者: from pandas.testing import assert_frame_equal [as 别名]
def test_get_without_transform(mock):
api_call_result = {'query_0': [{'balance': 212664.33000000002,
'datetime': '2019-05-23T00:00:00Z'},
{'balance': 212664.33000000002,
'datetime': '2019-05-24T00:00:00Z'},
{'balance': 212664.33000000002,
'datetime': '2019-05-25T00:00:00Z'}]}
# The value is passed by refference, that's why deepcopy is used for
# expected
mock.return_value = TestResponse(
status_code=200, data=deepcopy(api_call_result))
res = san.get(
"historical_balance/santiment",
address="0x1f3df0b8390bb8e9e322972c5e75583e87608ec2",
from_date="2019-05-23",
to_date="2019-05-26",
interval="1d"
)
expected_df = convert_to_datetime_idx_df(api_call_result['query_0'])
pdt.assert_frame_equal(res, expected_df, check_dtype=False)
示例11: test_pandas_from_arrow
# 需要导入模块: from pandas import testing [as 别名]
# 或者: from pandas.testing import assert_frame_equal [as 别名]
def test_pandas_from_arrow():
arr = pa.array(["a", "b", "c"], pa.string())
expected_series_woutname = pd.Series(fr.FletcherChunkedArray(arr))
pdt.assert_series_equal(expected_series_woutname, fr.pandas_from_arrow(arr))
expected_series_woutname = pd.Series(fr.FletcherContinuousArray(arr))
pdt.assert_series_equal(
expected_series_woutname, fr.pandas_from_arrow(arr, continuous=True)
)
rb = pa.RecordBatch.from_arrays([arr], ["column"])
expected_df = pd.DataFrame({"column": fr.FletcherChunkedArray(arr)})
table = pa.Table.from_arrays([arr], ["column"])
pdt.assert_frame_equal(expected_df, fr.pandas_from_arrow(rb))
pdt.assert_frame_equal(expected_df, fr.pandas_from_arrow(table))
expected_df = pd.DataFrame({"column": fr.FletcherContinuousArray(arr)})
table = pa.Table.from_arrays([arr], ["column"])
pdt.assert_frame_equal(expected_df, fr.pandas_from_arrow(rb, continuous=True))
pdt.assert_frame_equal(expected_df, fr.pandas_from_arrow(table, continuous=True))
示例12: is_same_as
# 需要导入模块: from pandas import testing [as 别名]
# 或者: from pandas.testing import assert_frame_equal [as 别名]
def is_same_as(df, df_to_compare, **kwargs):
"""Asserts that two pd.DataFrames are equal.
Args:
df (pd.DataFrame): Any pd.DataFrame.
df_to_compare (pd.DataFrame): A second pd.DataFrame.
**kwargs (dict): Keyword arguments passed through to pandas' ``assert_frame_equal``.
Returns:
Original `df`.
"""
try:
tm.assert_frame_equal(df, df_to_compare, **kwargs)
except AssertionError as exc:
raise AssertionError("DataFrames are not equal") from exc
return df
示例13: test_has_set_within_vals
# 需要导入模块: from pandas import testing [as 别名]
# 或者: from pandas.testing import assert_frame_equal [as 别名]
def test_has_set_within_vals():
df = pd.DataFrame({'A': [1, 2, 3], 'B': ['a', 'b', 'c']})
items = {'A': [1, 2, 3], 'B': ['a', 'b', 'c']}
tm.assert_frame_equal(df, ck.has_set_within_vals(df, items))
tm.assert_frame_equal(df, dc.HasSetWithinVals(items=items)(_noop)(df))
items = {'A': [1, 2], 'B': ['a', 'b']}
tm.assert_frame_equal(df, ck.has_set_within_vals(df, items))
tm.assert_frame_equal(df, dc.HasSetWithinVals(items=items)(_noop)(df))
items = {'A': [1, 2, 4], 'B': ['a', 'b', 'd']}
with pytest.raises(AssertionError):
ck.has_set_within_vals(df, items)
with pytest.raises(AssertionError):
dc.HasSetWithinVals(items=items)(_noop)(df)
示例14: test_monotonic_increasing_lax
# 需要导入模块: from pandas import testing [as 别名]
# 或者: from pandas.testing import assert_frame_equal [as 别名]
def test_monotonic_increasing_lax():
df = pd.DataFrame([1, 2, 2])
tm.assert_frame_equal(df, ck.is_monotonic(df, increasing=True))
result = dc.IsMonotonic(increasing=True)(_add_n)(df)
tm.assert_frame_equal(result, df + 1)
df = pd.DataFrame([1, 2, 1])
with pytest.raises(AssertionError):
ck.is_monotonic(df, increasing=True)
with pytest.raises(AssertionError):
dc.IsMonotonic(increasing=True)(_add_n)(df)
df = pd.DataFrame([3, 2, 1])
with pytest.raises(AssertionError):
ck.is_monotonic(df, increasing=True)
with pytest.raises(AssertionError):
dc.IsMonotonic(increasing=True)(_add_n)(df)
示例15: test_monotonic_increasing_strict
# 需要导入模块: from pandas import testing [as 别名]
# 或者: from pandas.testing import assert_frame_equal [as 别名]
def test_monotonic_increasing_strict():
df = pd.DataFrame([1, 2, 3])
tm.assert_frame_equal(df, ck.is_monotonic(df, increasing=True, strict=True))
result = dc.IsMonotonic(increasing=True, strict=True)(_add_n)(df)
tm.assert_frame_equal(result, df + 1)
df = pd.DataFrame([1, 2, 2])
with pytest.raises(AssertionError):
ck.is_monotonic(df, increasing=True, strict=True)
with pytest.raises(AssertionError):
dc.IsMonotonic(increasing=True, strict=True)(_add_n)(df)
df = pd.DataFrame([3, 2, 1])
with pytest.raises(AssertionError):
ck.is_monotonic(df, increasing=True, strict=True)
with pytest.raises(AssertionError):
dc.IsMonotonic(increasing=True, strict=True)(_add_n)(df)