|
5 | 5 |
|
6 | 6 | from datetime import datetime |
7 | 7 | import operator |
8 | | -import pandas as pd |
| 8 | + |
9 | 9 | import numpy as np |
10 | 10 | import pytest |
11 | 11 |
|
12 | 12 | from pandas._libs import lib |
13 | 13 |
|
14 | 14 | from pandas.core.dtypes.cast import find_common_type |
15 | 15 |
|
| 16 | +import pandas as pd |
16 | 17 | from pandas import ( |
17 | 18 | CategoricalDtype, |
18 | 19 | CategoricalIndex, |
@@ -64,13 +65,14 @@ def index_flat2(index_flat): |
64 | 65 |
|
65 | 66 | def test_union_same_types(index): |
66 | 67 | # mixed int string |
67 | | - if index.equals(pd.Index([0, "a", 1, "b", 2, "c"])): |
| 68 | + if index.equals(Index([0, "a", 1, "b", 2, "c"])): |
68 | 69 | index = index.astype(str) |
69 | 70 |
|
70 | 71 | idx1 = index.sort_values() |
71 | 72 | idx2 = index.sort_values() |
72 | 73 | assert idx1.union(idx2, sort=False).dtype == idx1.dtype |
73 | 74 |
|
| 75 | + |
74 | 76 | def test_union_different_types(index_flat, index_flat2, request): |
75 | 77 | idx1 = index_flat |
76 | 78 | idx2 = index_flat2 |
@@ -129,6 +131,7 @@ def test_union_different_types(index_flat, index_flat2, request): |
129 | 131 | assert res1.dtype == common_dtype |
130 | 132 | assert res2.dtype == common_dtype |
131 | 133 |
|
| 134 | + |
132 | 135 | @pytest.mark.parametrize( |
133 | 136 | "idx1,idx2", |
134 | 137 | [ |
@@ -233,7 +236,6 @@ def test_intersection_base(self, index): |
233 | 236 |
|
234 | 237 | @pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning") |
235 | 238 | def test_union_base(self, index): |
236 | | - |
237 | 239 | if index.inferred_type in ["mixed", "mixed-integer"]: |
238 | 240 | pytest.skip("Mixed-type Index not orderable; union fails") |
239 | 241 |
|
@@ -295,7 +297,6 @@ def test_difference_base(self, sort, index): |
295 | 297 |
|
296 | 298 | @pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning") |
297 | 299 | def test_symmetric_difference(self, index, using_infer_string, request): |
298 | | - |
299 | 300 | if ( |
300 | 301 | using_infer_string |
301 | 302 | and index.dtype == "object" |
@@ -392,7 +393,7 @@ def test_union_unequal(self, index_flat, fname, sname, expected_name): |
392 | 393 | else: |
393 | 394 | index = index_flat |
394 | 395 |
|
395 | | - if index.dtype == 'object': |
| 396 | + if index.dtype == "object": |
396 | 397 | index = index.astype(str) |
397 | 398 |
|
398 | 399 | # test copy.union(subset) - need sort for unicode and string |
@@ -464,7 +465,7 @@ def test_intersect_unequal(self, index_flat, fname, sname, expected_name): |
464 | 465 | else: |
465 | 466 | index = index_flat |
466 | 467 |
|
467 | | - if index.dtype == 'object': |
| 468 | + if index.dtype == "object": |
468 | 469 | index = index.astype(str) |
469 | 470 | # test copy.intersection(subset) - need sort for unicode and string |
470 | 471 | first = index.copy().set_names(fname) |
@@ -919,16 +920,16 @@ def test_symmetric_difference_mi(self, sort): |
919 | 920 | index2 = MultiIndex.from_tuples([("foo", 1), ("bar", 3)]) |
920 | 921 |
|
921 | 922 | def has_mixed_types(level): |
922 | | - return ( |
923 | | - any(isinstance(x, str) for x in level) |
924 | | - and any(isinstance(x, int) for x in level) |
| 923 | + return any(isinstance(x, str) for x in level) and any( |
| 924 | + isinstance(x, int) for x in level |
925 | 925 | ) |
926 | 926 |
|
927 | 927 | for idx in [index1, index2]: |
928 | 928 | for lvl in range(idx.nlevels): |
929 | 929 | if has_mixed_types(idx.get_level_values(lvl)): |
930 | | - pytest.skip(f"Mixed types in MultiIndex level {lvl}" |
931 | | - " are not orderable") |
| 930 | + pytest.skip( |
| 931 | + f"Mixed types in MultiIndex level {lvl} are not orderable" |
| 932 | + ) |
932 | 933 |
|
933 | 934 | result = index1.symmetric_difference(index2, sort=sort) |
934 | 935 | expected = MultiIndex.from_tuples([("bar", 2), ("baz", 3), ("bar", 3)]) |
|
0 commit comments