+25
-21
lines changedFilter options
+25
-21
lines changed Original file line number Diff line number Diff line change
@@ -274,7 +274,7 @@ def box_expected(expected, box_cls, transpose: bool = True):
274
274
else:
275
275
expected = pd.array(expected, copy=False)
276
276
elif box_cls is Index:
277
-
expected = Index._with_infer(expected)
277
+
expected = Index(expected)
278
278
elif box_cls is Series:
279
279
expected = Series(expected)
280
280
elif box_cls is DataFrame:
Original file line number Diff line number Diff line change
@@ -894,7 +894,7 @@ def value_counts(
894
894
895
895
# For backwards compatibility, we let Index do its normal type
896
896
# inference, _except_ for if if infers from object to bool.
897
-
idx = Index._with_infer(keys)
897
+
idx = Index(keys)
898
898
if idx.dtype == bool and keys.dtype == object:
899
899
idx = idx.astype(object)
900
900
Original file line number Diff line number Diff line change
@@ -2678,6 +2678,7 @@ def fillna(self, value=None, downcast=None):
2678
2678
if downcast is None:
2679
2679
# no need to care metadata other than name
2680
2680
# because it can't have freq if it has NaTs
2681
+
# _with_infer needed for test_fillna_categorical
2681
2682
return Index._with_infer(result, name=self.name)
2682
2683
raise NotImplementedError(
2683
2684
f"{type(self).__name__}.fillna does not support 'downcast' "
@@ -4230,10 +4231,10 @@ def _reindex_non_unique(
4230
4231
new_indexer = np.arange(len(self.take(indexer)), dtype=np.intp)
4231
4232
new_indexer[~check] = -1
4232
4233
4233
-
if isinstance(self, ABCMultiIndex):
4234
-
new_index = type(self).from_tuples(new_labels, names=self.names)
4234
+
if not isinstance(self, ABCMultiIndex):
4235
+
new_index = Index(new_labels, name=self.name)
4235
4236
else:
4236
-
new_index = Index._with_infer(new_labels, name=self.name)
4237
+
new_index = type(self).from_tuples(new_labels, names=self.names)
4237
4238
return new_index, indexer, new_indexer
4238
4239
4239
4240
# --------------------------------------------------------------------
@@ -6477,7 +6478,7 @@ def insert(self, loc: int, item) -> Index:
6477
6478
if self._typ == "numericindex":
6478
6479
# Use self._constructor instead of Index to retain NumericIndex GH#43921
6479
6480
# TODO(2.0) can use Index instead of self._constructor
6480
-
return self._constructor._with_infer(new_values, name=self.name)
6481
+
return self._constructor(new_values, name=self.name)
6481
6482
else:
6482
6483
return Index._with_infer(new_values, name=self.name)
6483
6484
@@ -6850,7 +6851,7 @@ def ensure_index_from_sequences(sequences, names=None) -> Index:
6850
6851
if len(sequences) == 1:
6851
6852
if names is not None:
6852
6853
names = names[0]
6853
-
return Index._with_infer(sequences[0], name=names)
6854
+
return Index(sequences[0], name=names)
6854
6855
else:
6855
6856
return MultiIndex.from_arrays(sequences, names=names)
6856
6857
@@ -6893,7 +6894,7 @@ def ensure_index(index_like: Axes, copy: bool = False) -> Index:
6893
6894
6894
6895
if isinstance(index_like, ABCSeries):
6895
6896
name = index_like.name
6896
-
return Index._with_infer(index_like, name=name, copy=copy)
6897
+
return Index(index_like, name=name, copy=copy)
6897
6898
6898
6899
if is_iterator(index_like):
6899
6900
index_like = list(index_like)
@@ -6909,9 +6910,9 @@ def ensure_index(index_like: Axes, copy: bool = False) -> Index:
6909
6910
6910
6911
return MultiIndex.from_arrays(index_like)
6911
6912
else:
6912
-
return Index._with_infer(index_like, copy=copy, tupleize_cols=False)
6913
+
return Index(index_like, copy=copy, tupleize_cols=False)
6913
6914
else:
6914
-
return Index._with_infer(index_like, copy=copy)
6915
+
return Index(index_like, copy=copy)
6915
6916
6916
6917
6917
6918
def ensure_has_len(seq):
Original file line number Diff line number Diff line change
@@ -2112,7 +2112,7 @@ def append(self, other):
2112
2112
# setting names to None automatically
2113
2113
return MultiIndex.from_tuples(new_tuples)
2114
2114
except (TypeError, IndexError):
2115
-
return Index._with_infer(new_tuples)
2115
+
return Index(new_tuples)
2116
2116
2117
2117
def argsort(self, *args, **kwargs) -> npt.NDArray[np.intp]:
2118
2118
if len(args) == 0 and len(kwargs) == 0:
Original file line number Diff line number Diff line change
@@ -319,7 +319,7 @@ def cons_row(x):
319
319
out = out.get_level_values(0)
320
320
return out
321
321
else:
322
-
return Index._with_infer(result, name=name)
322
+
return Index(result, name=name)
323
323
else:
324
324
index = self._orig.index
325
325
# This is a mess.
Original file line number Diff line number Diff line change
@@ -344,9 +344,7 @@ def _hash_ndarray(
344
344
)
345
345
346
346
codes, categories = factorize(vals, sort=False)
347
-
cat = Categorical(
348
-
codes, Index._with_infer(categories), ordered=False, fastpath=True
349
-
)
347
+
cat = Categorical(codes, Index(categories), ordered=False, fastpath=True)
350
348
return _hash_categorical(cat, encoding, hash_key)
351
349
352
350
try:
Original file line number Diff line number Diff line change
@@ -1147,6 +1147,9 @@ def test_numarr_with_dtype_add_nan(self, dtype, box_with_array):
1147
1147
1148
1148
ser = tm.box_expected(ser, box)
1149
1149
expected = tm.box_expected(expected, box)
1150
+
if box is Index and dtype is object:
1151
+
# TODO: avoid this; match behavior with Series
1152
+
expected = expected.astype(np.float64)
1150
1153
1151
1154
result = np.nan + ser
1152
1155
tm.assert_equal(result, expected)
@@ -1162,6 +1165,9 @@ def test_numarr_with_dtype_add_int(self, dtype, box_with_array):
1162
1165
1163
1166
ser = tm.box_expected(ser, box)
1164
1167
expected = tm.box_expected(expected, box)
1168
+
if box is Index and dtype is object:
1169
+
# TODO: avoid this; match behavior with Series
1170
+
expected = expected.astype(np.int64)
1165
1171
1166
1172
result = 1 + ser
1167
1173
tm.assert_equal(result, expected)
Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@ def test_astype_index(all_data, dropna):
89
89
other = all_data
90
90
91
91
dtype = all_data.dtype
92
-
idx = pd.Index._with_infer(np.array(other))
92
+
idx = pd.Index(np.array(other))
93
93
assert isinstance(idx, ABCIndex)
94
94
95
95
result = idx.astype(dtype)
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ def test_groupby_extension_agg(self, as_index, data_for_grouping):
33
33
_, uniques = pd.factorize(data_for_grouping, sort=True)
34
34
35
35
if as_index:
36
-
index = pd.Index._with_infer(uniques, name="B")
36
+
index = pd.Index(uniques, name="B")
37
37
expected = pd.Series([3.0, 1.0, 4.0], index=index, name="A")
38
38
self.assert_series_equal(result, expected)
39
39
else:
@@ -61,7 +61,7 @@ def test_groupby_extension_no_sort(self, data_for_grouping):
61
61
result = df.groupby("B", sort=False).A.mean()
62
62
_, index = pd.factorize(data_for_grouping, sort=False)
63
63
64
-
index = pd.Index._with_infer(index, name="B")
64
+
index = pd.Index(index, name="B")
65
65
expected = pd.Series([1.0, 3.0, 4.0], index=index, name="A")
66
66
self.assert_series_equal(result, expected)
67
67
Original file line number Diff line number Diff line change
@@ -391,7 +391,7 @@ def test_groupby_extension_agg(self, as_index, data_for_grouping):
391
391
_, uniques = pd.factorize(data_for_grouping, sort=True)
392
392
393
393
if as_index:
394
-
index = pd.Index._with_infer(uniques, name="B")
394
+
index = pd.Index(uniques, name="B")
395
395
expected = pd.Series([3.0, 1.0, 4.0], index=index, name="A")
396
396
self.assert_series_equal(result, expected)
397
397
else:
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4