/
usr
/
local
/
lib64
/
python3.6
/
site-packages
/
pandas
/
tests
/
frame
/
methods
/
/usr/local/lib64/python3.6/site-packages/pandas/tests/frame/methods
mkdir
upload
Name
Size
Mode
Actions
__pycache__/
-
0755
rm
test_align.py
10339
0644
edit
dl
rm
test_append.py
7399
0644
edit
dl
rm
test_asfreq.py
1970
0644
edit
dl
rm
test_asof.py
5767
0644
edit
dl
rm
test_assign.py
2982
0644
edit
dl
rm
test_astype.py
21027
0644
edit
dl
rm
test_at_time.py
3205
0644
edit
dl
rm
test_between_time.py
3675
0644
edit
dl
rm
test_clip.py
6028
0644
edit
dl
rm
test_combine.py
1359
0644
edit
dl
rm
test_combine_first.py
12748
0644
edit
dl
rm
test_compare.py
6158
0644
edit
dl
rm
test_count.py
1068
0644
edit
dl
rm
test_cov_corr.py
11888
0644
edit
dl
rm
test_describe.py
12492
0644
edit
dl
rm
test_diff.py
7374
0644
edit
dl
rm
test_drop.py
15662
0644
edit
dl
rm
test_droplevel.py
855
0644
edit
dl
rm
test_drop_duplicates.py
13387
0644
edit
dl
rm
test_duplicated.py
3191
0644
edit
dl
rm
test_explode.py
5294
0644
edit
dl
rm
test_filter.py
4933
0644
edit
dl
rm
test_first_and_last.py
1803
0644
edit
dl
rm
test_head_tail.py
1194
0644
edit
dl
rm
test_interpolate.py
11816
0644
edit
dl
rm
test_isin.py
7324
0644
edit
dl
rm
test_nlargest.py
6731
0644
edit
dl
rm
test_pct_change.py
3436
0644
edit
dl
rm
test_pop.py
1226
0644
edit
dl
rm
test_quantile.py
18028
0644
edit
dl
rm
test_rank.py
11377
0644
edit
dl
rm
test_reindex_like.py
1187
0644
edit
dl
rm
test_rename.py
12543
0644
edit
dl
rm
test_rename_axis.py
4074
0644
edit
dl
rm
test_replace.py
59230
0644
edit
dl
rm
test_reset_index.py
12506
0644
edit
dl
rm
test_round.py
7916
0644
edit
dl
rm
test_select_dtypes.py
12104
0644
edit
dl
rm
test_set_index.py
19571
0644
edit
dl
rm
test_shift.py
10324
0644
edit
dl
rm
test_sort_index.py
25678
0644
edit
dl
rm
test_sort_values.py
25358
0644
edit
dl
rm
test_to_dict.py
9989
0644
edit
dl
rm
test_to_period.py
984
0644
edit
dl
rm
test_to_records.py
13981
0644
edit
dl
rm
test_to_timestamp.py
4020
0644
edit
dl
rm
test_transpose.py
2426
0644
edit
dl
rm
test_truncate.py
4180
0644
edit
dl
rm
test_tz_convert.py
3415
0644
edit
dl
rm
test_tz_localize.py
666
0644
edit
dl
rm
test_update.py
4259
0644
edit
dl
rm
test_value_counts.py
2631
0644
edit
dl
rm
__init__.py
229
0644
edit
dl
rm
Edit:
/usr/local/lib64/python3.6/site-packages/pandas/tests/frame/methods/test_compare.py
(6158B)
import numpy as np import pytest import pandas as pd import pandas._testing as tm @pytest.mark.parametrize("align_axis", [0, 1, "index", "columns"]) def test_compare_axis(align_axis): # GH#30429 df = pd.DataFrame( {"col1": ["a", "b", "c"], "col2": [1.0, 2.0, np.nan], "col3": [1.0, 2.0, 3.0]}, columns=["col1", "col2", "col3"], ) df2 = df.copy() df2.loc[0, "col1"] = "c" df2.loc[2, "col3"] = 4.0 result = df.compare(df2, align_axis=align_axis) if align_axis in (1, "columns"): indices = pd.Index([0, 2]) columns = pd.MultiIndex.from_product([["col1", "col3"], ["self", "other"]]) expected = pd.DataFrame( [["a", "c", np.nan, np.nan], [np.nan, np.nan, 3.0, 4.0]], index=indices, columns=columns, ) else: indices = pd.MultiIndex.from_product([[0, 2], ["self", "other"]]) columns = pd.Index(["col1", "col3"]) expected = pd.DataFrame( [["a", np.nan], ["c", np.nan], [np.nan, 3.0], [np.nan, 4.0]], index=indices, columns=columns, ) tm.assert_frame_equal(result, expected) @pytest.mark.parametrize( "keep_shape, keep_equal", [ (True, False), (False, True), (True, True), # False, False case is already covered in test_compare_axis ], ) def test_compare_various_formats(keep_shape, keep_equal): df = pd.DataFrame( {"col1": ["a", "b", "c"], "col2": [1.0, 2.0, np.nan], "col3": [1.0, 2.0, 3.0]}, columns=["col1", "col2", "col3"], ) df2 = df.copy() df2.loc[0, "col1"] = "c" df2.loc[2, "col3"] = 4.0 result = df.compare(df2, keep_shape=keep_shape, keep_equal=keep_equal) if keep_shape: indices = pd.Index([0, 1, 2]) columns = pd.MultiIndex.from_product( [["col1", "col2", "col3"], ["self", "other"]] ) if keep_equal: expected = pd.DataFrame( [ ["a", "c", 1.0, 1.0, 1.0, 1.0], ["b", "b", 2.0, 2.0, 2.0, 2.0], ["c", "c", np.nan, np.nan, 3.0, 4.0], ], index=indices, columns=columns, ) else: expected = pd.DataFrame( [ ["a", "c", np.nan, np.nan, np.nan, np.nan], [np.nan, np.nan, np.nan, np.nan, np.nan, np.nan], [np.nan, np.nan, np.nan, np.nan, 3.0, 4.0], ], index=indices, columns=columns, ) else: indices = pd.Index([0, 2]) columns = pd.MultiIndex.from_product([["col1", "col3"], ["self", "other"]]) expected = pd.DataFrame( [["a", "c", 1.0, 1.0], ["c", "c", 3.0, 4.0]], index=indices, columns=columns ) tm.assert_frame_equal(result, expected) def test_compare_with_equal_nulls(): # We want to make sure two NaNs are considered the same # and dropped where applicable df = pd.DataFrame( {"col1": ["a", "b", "c"], "col2": [1.0, 2.0, np.nan], "col3": [1.0, 2.0, 3.0]}, columns=["col1", "col2", "col3"], ) df2 = df.copy() df2.loc[0, "col1"] = "c" result = df.compare(df2) indices = pd.Index([0]) columns = pd.MultiIndex.from_product([["col1"], ["self", "other"]]) expected = pd.DataFrame([["a", "c"]], index=indices, columns=columns) tm.assert_frame_equal(result, expected) def test_compare_with_non_equal_nulls(): # We want to make sure the relevant NaNs do not get dropped # even if the entire row or column are NaNs df = pd.DataFrame( {"col1": ["a", "b", "c"], "col2": [1.0, 2.0, np.nan], "col3": [1.0, 2.0, 3.0]}, columns=["col1", "col2", "col3"], ) df2 = df.copy() df2.loc[0, "col1"] = "c" df2.loc[2, "col3"] = np.nan result = df.compare(df2) indices = pd.Index([0, 2]) columns = pd.MultiIndex.from_product([["col1", "col3"], ["self", "other"]]) expected = pd.DataFrame( [["a", "c", np.nan, np.nan], [np.nan, np.nan, 3.0, np.nan]], index=indices, columns=columns, ) tm.assert_frame_equal(result, expected) @pytest.mark.parametrize("align_axis", [0, 1]) def test_compare_multi_index(align_axis): df = pd.DataFrame( {"col1": ["a", "b", "c"], "col2": [1.0, 2.0, np.nan], "col3": [1.0, 2.0, 3.0]} ) df.columns = pd.MultiIndex.from_arrays([["a", "a", "b"], ["col1", "col2", "col3"]]) df.index = pd.MultiIndex.from_arrays([["x", "x", "y"], [0, 1, 2]]) df2 = df.copy() df2.iloc[0, 0] = "c" df2.iloc[2, 2] = 4.0 result = df.compare(df2, align_axis=align_axis) if align_axis == 0: indices = pd.MultiIndex.from_arrays( [["x", "x", "y", "y"], [0, 0, 2, 2], ["self", "other", "self", "other"]] ) columns = pd.MultiIndex.from_arrays([["a", "b"], ["col1", "col3"]]) data = [["a", np.nan], ["c", np.nan], [np.nan, 3.0], [np.nan, 4.0]] else: indices = pd.MultiIndex.from_arrays([["x", "y"], [0, 2]]) columns = pd.MultiIndex.from_arrays( [ ["a", "a", "b", "b"], ["col1", "col1", "col3", "col3"], ["self", "other", "self", "other"], ] ) data = [["a", "c", np.nan, np.nan], [np.nan, np.nan, 3.0, 4.0]] expected = pd.DataFrame(data=data, index=indices, columns=columns) tm.assert_frame_equal(result, expected) def test_compare_unaligned_objects(): # test DataFrames with different indices msg = "Can only compare identically-labeled DataFrame objects" with pytest.raises(ValueError, match=msg): df1 = pd.DataFrame([1, 2, 3], index=["a", "b", "c"]) df2 = pd.DataFrame([1, 2, 3], index=["a", "b", "d"]) df1.compare(df2) # test DataFrames with different shapes msg = "Can only compare identically-labeled DataFrame objects" with pytest.raises(ValueError, match=msg): df1 = pd.DataFrame(np.ones((3, 3))) df2 = pd.DataFrame(np.zeros((2, 1))) df1.compare(df2)
Save
cmd:
run