|
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, |
@@ -71,12 +72,15 @@ def test_union_same_types(index): |
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 |
77 | 79 |
|
78 | | - # Ειδική μεταχείριση για mixed-int-string |
79 | | - if idx1.equals(pd.Index([0, "a", 1, "b", 2, "c"])) or idx2.equals(pd.Index([0, "a", 1, "b", 2, "c"])): |
| 80 | + # mixed int string |
| 81 | + if idx1.equals(pd.Index([0, "a", 1, "b", 2, "c"])) or idx2.equals( |
| 82 | + pd.Index([0, "a", 1, "b", 2, "c"]) |
| 83 | + ): |
80 | 84 | idx1 = idx1.astype(str) |
81 | 85 | idx2 = idx2.astype(str) |
82 | 86 |
|
@@ -129,6 +133,7 @@ def test_union_different_types(index_flat, index_flat2, request): |
129 | 133 | assert res1.dtype == common_dtype |
130 | 134 | assert res2.dtype == common_dtype |
131 | 135 |
|
| 136 | + |
132 | 137 | @pytest.mark.parametrize( |
133 | 138 | "idx1,idx2", |
134 | 139 | [ |
@@ -233,7 +238,6 @@ def test_intersection_base(self, index): |
233 | 238 |
|
234 | 239 | @pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning") |
235 | 240 | def test_union_base(self, index): |
236 | | - |
237 | 241 | if index.inferred_type in ["mixed", "mixed-integer"]: |
238 | 242 | pytest.skip("Mixed-type Index not orderable; union fails") |
239 | 243 |
|
@@ -295,7 +299,6 @@ def test_difference_base(self, sort, index): |
295 | 299 |
|
296 | 300 | @pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning") |
297 | 301 | def test_symmetric_difference(self, index, using_infer_string, request): |
298 | | - |
299 | 302 | if ( |
300 | 303 | using_infer_string |
301 | 304 | and index.dtype == "object" |
@@ -392,7 +395,7 @@ def test_union_unequal(self, index_flat, fname, sname, expected_name): |
392 | 395 | else: |
393 | 396 | index = index_flat |
394 | 397 |
|
395 | | - if index.dtype == 'object': |
| 398 | + if index.dtype == "object": |
396 | 399 | index = index.astype(str) |
397 | 400 |
|
398 | 401 | # test copy.union(subset) - need sort for unicode and string |
@@ -464,7 +467,7 @@ def test_intersect_unequal(self, index_flat, fname, sname, expected_name): |
464 | 467 | else: |
465 | 468 | index = index_flat |
466 | 469 |
|
467 | | - if index.dtype == 'object': |
| 470 | + if index.dtype == "object": |
468 | 471 | index = index.astype(str) |
469 | 472 | # test copy.intersection(subset) - need sort for unicode and string |
470 | 473 | first = index.copy().set_names(fname) |
@@ -919,12 +922,16 @@ def test_symmetric_difference_mi(self, sort): |
919 | 922 | index2 = MultiIndex.from_tuples([("foo", 1), ("bar", 3)]) |
920 | 923 |
|
921 | 924 | def has_mixed_types(level): |
922 | | - return any(isinstance(x, str) for x in level) and any(isinstance(x, int) for x in level) |
| 925 | + return any(isinstance(x, str) for x in level) and any( |
| 926 | + isinstance(x, int) for x in level |
| 927 | + ) |
923 | 928 |
|
924 | 929 | for idx in [index1, index2]: |
925 | 930 | for lvl in range(idx.nlevels): |
926 | 931 | if has_mixed_types(idx.get_level_values(lvl)): |
927 | | - pytest.skip(f"Mixed types in MultiIndex level {lvl} are not orderable") |
| 932 | + pytest.skip( |
| 933 | + f"Mixed types in MultiIndex level {lvl} are not orderable" |
| 934 | + ) |
928 | 935 |
|
929 | 936 | result = index1.symmetric_difference(index2, sort=sort) |
930 | 937 | expected = MultiIndex.from_tuples([("bar", 2), ("baz", 3), ("bar", 3)]) |
|
0 commit comments