/
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_explode.py
(5294B)
import numpy as np import pytest import pandas as pd import pandas._testing as tm def test_error(): df = pd.DataFrame( {"A": pd.Series([[0, 1, 2], np.nan, [], (3, 4)], index=list("abcd")), "B": 1} ) with pytest.raises(ValueError, match="column must be a scalar"): df.explode(list("AA")) df.columns = list("AA") with pytest.raises(ValueError, match="columns must be unique"): df.explode("A") def test_basic(): df = pd.DataFrame( {"A": pd.Series([[0, 1, 2], np.nan, [], (3, 4)], index=list("abcd")), "B": 1} ) result = df.explode("A") expected = pd.DataFrame( { "A": pd.Series( [0, 1, 2, np.nan, np.nan, 3, 4], index=list("aaabcdd"), dtype=object ), "B": 1, } ) tm.assert_frame_equal(result, expected) def test_multi_index_rows(): df = pd.DataFrame( {"A": np.array([[0, 1, 2], np.nan, [], (3, 4)], dtype=object), "B": 1}, index=pd.MultiIndex.from_tuples([("a", 1), ("a", 2), ("b", 1), ("b", 2)]), ) result = df.explode("A") expected = pd.DataFrame( { "A": pd.Series( [0, 1, 2, np.nan, np.nan, 3, 4], index=pd.MultiIndex.from_tuples( [ ("a", 1), ("a", 1), ("a", 1), ("a", 2), ("b", 1), ("b", 2), ("b", 2), ] ), dtype=object, ), "B": 1, } ) tm.assert_frame_equal(result, expected) def test_multi_index_columns(): df = pd.DataFrame( {("A", 1): np.array([[0, 1, 2], np.nan, [], (3, 4)], dtype=object), ("A", 2): 1} ) result = df.explode(("A", 1)) expected = pd.DataFrame( { ("A", 1): pd.Series( [0, 1, 2, np.nan, np.nan, 3, 4], index=pd.Index([0, 0, 0, 1, 2, 3, 3]), dtype=object, ), ("A", 2): 1, } ) tm.assert_frame_equal(result, expected) def test_usecase(): # explode a single column # gh-10511 df = pd.DataFrame( [[11, range(5), 10], [22, range(3), 20]], columns=list("ABC") ).set_index("C") result = df.explode("B") expected = pd.DataFrame( { "A": [11, 11, 11, 11, 11, 22, 22, 22], "B": np.array([0, 1, 2, 3, 4, 0, 1, 2], dtype=object), "C": [10, 10, 10, 10, 10, 20, 20, 20], }, columns=list("ABC"), ).set_index("C") tm.assert_frame_equal(result, expected) # gh-8517 df = pd.DataFrame( [["2014-01-01", "Alice", "A B"], ["2014-01-02", "Bob", "C D"]], columns=["dt", "name", "text"], ) result = df.assign(text=df.text.str.split(" ")).explode("text") expected = pd.DataFrame( [ ["2014-01-01", "Alice", "A"], ["2014-01-01", "Alice", "B"], ["2014-01-02", "Bob", "C"], ["2014-01-02", "Bob", "D"], ], columns=["dt", "name", "text"], index=[0, 0, 1, 1], ) tm.assert_frame_equal(result, expected) @pytest.mark.parametrize( "input_dict, input_index, expected_dict, expected_index", [ ( {"col1": [[1, 2], [3, 4]], "col2": ["foo", "bar"]}, [0, 0], {"col1": [1, 2, 3, 4], "col2": ["foo", "foo", "bar", "bar"]}, [0, 0, 0, 0], ), ( {"col1": [[1, 2], [3, 4]], "col2": ["foo", "bar"]}, pd.Index([0, 0], name="my_index"), {"col1": [1, 2, 3, 4], "col2": ["foo", "foo", "bar", "bar"]}, pd.Index([0, 0, 0, 0], name="my_index"), ), ( {"col1": [[1, 2], [3, 4]], "col2": ["foo", "bar"]}, pd.MultiIndex.from_arrays( [[0, 0], [1, 1]], names=["my_first_index", "my_second_index"] ), {"col1": [1, 2, 3, 4], "col2": ["foo", "foo", "bar", "bar"]}, pd.MultiIndex.from_arrays( [[0, 0, 0, 0], [1, 1, 1, 1]], names=["my_first_index", "my_second_index"], ), ), ( {"col1": [[1, 2], [3, 4]], "col2": ["foo", "bar"]}, pd.MultiIndex.from_arrays([[0, 0], [1, 1]], names=["my_index", None]), {"col1": [1, 2, 3, 4], "col2": ["foo", "foo", "bar", "bar"]}, pd.MultiIndex.from_arrays( [[0, 0, 0, 0], [1, 1, 1, 1]], names=["my_index", None] ), ), ], ) def test_duplicate_index(input_dict, input_index, expected_dict, expected_index): # GH 28005 df = pd.DataFrame(input_dict, index=input_index) result = df.explode("col1") expected = pd.DataFrame(expected_dict, index=expected_index, dtype=object) tm.assert_frame_equal(result, expected) def test_ignore_index(): # GH 34932 df = pd.DataFrame({"id": range(0, 20, 10), "values": [list("ab"), list("cd")]}) result = df.explode("values", ignore_index=True) expected = pd.DataFrame( {"id": [0, 0, 10, 10], "values": list("abcd")}, index=[0, 1, 2, 3] ) tm.assert_frame_equal(result, expected)
Save
cmd:
run