Skip to content

Commit d9912dc

Browse files
committed
undo unwanted changes
1 parent b6154f4 commit d9912dc

File tree

2 files changed

+113
-98
lines changed

2 files changed

+113
-98
lines changed

pandas/__init__.py

Lines changed: 104 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,6 @@
1818
)
1919
del hard_dependencies, dependency, missing_dependencies
2020

21-
from pandas._config import (
22-
describe_option,
23-
get_option,
24-
option_context,
25-
options,
26-
reset_option,
27-
set_option,
28-
)
29-
3021
# numpy compat
3122
from pandas.compat.numpy import (
3223
_np_version_under1p14,
@@ -35,144 +26,161 @@
3526
_np_version_under1p17,
3627
_np_version_under1p18,
3728
)
38-
from pandas.util._print_versions import show_versions
39-
from pandas.util._tester import test
29+
30+
try:
31+
from pandas._libs import hashtable as _hashtable, lib as _lib, tslib as _tslib
32+
except ImportError as e: # pragma: no cover
33+
# hack but overkill to use re
34+
module = str(e).replace("cannot import name ", "")
35+
raise ImportError(
36+
f"C extension: {module} not built. If you want to import "
37+
"pandas from the source directory, you may need to run "
38+
"'python setup.py build_ext --inplace --force' to build the C extensions first."
39+
)
40+
41+
from pandas._config import (
42+
get_option,
43+
set_option,
44+
reset_option,
45+
describe_option,
46+
option_context,
47+
options,
48+
)
4049

4150
# let init-time option registration happen
42-
import pandas.api
43-
import pandas.arrays
44-
from pandas.core.api import ( # dtype; missing; indexes; tseries; conversion; misc
45-
NA,
46-
BooleanDtype,
47-
Categorical,
48-
CategoricalDtype,
49-
CategoricalIndex,
50-
DataFrame,
51-
DateOffset,
52-
DatetimeIndex,
53-
DatetimeTZDtype,
54-
Float64Index,
55-
Grouper,
56-
Index,
57-
IndexSlice,
51+
import pandas.core.config_init
52+
53+
from pandas.core.api import (
54+
# dtype
5855
Int8Dtype,
5956
Int16Dtype,
6057
Int32Dtype,
6158
Int64Dtype,
62-
Int64Index,
63-
Interval,
64-
IntervalDtype,
65-
IntervalIndex,
66-
MultiIndex,
67-
NamedAgg,
68-
NaT,
69-
Period,
70-
PeriodDtype,
71-
PeriodIndex,
72-
RangeIndex,
73-
Series,
74-
StringDtype,
75-
Timedelta,
76-
TimedeltaIndex,
77-
Timestamp,
7859
UInt8Dtype,
7960
UInt16Dtype,
8061
UInt32Dtype,
8162
UInt64Dtype,
82-
UInt64Index,
83-
array,
84-
bdate_range,
85-
date_range,
86-
factorize,
87-
interval_range,
63+
CategoricalDtype,
64+
PeriodDtype,
65+
IntervalDtype,
66+
DatetimeTZDtype,
67+
StringDtype,
68+
BooleanDtype,
69+
# missing
70+
NA,
8871
isna,
8972
isnull,
9073
notna,
9174
notnull,
75+
# indexes
76+
Index,
77+
CategoricalIndex,
78+
Int64Index,
79+
UInt64Index,
80+
RangeIndex,
81+
Float64Index,
82+
MultiIndex,
83+
IntervalIndex,
84+
TimedeltaIndex,
85+
DatetimeIndex,
86+
PeriodIndex,
87+
IndexSlice,
88+
# tseries
89+
NaT,
90+
Period,
9291
period_range,
93-
set_eng_float_format,
92+
Timedelta,
9493
timedelta_range,
95-
to_datetime,
94+
Timestamp,
95+
date_range,
96+
bdate_range,
97+
Interval,
98+
interval_range,
99+
DateOffset,
100+
# conversion
96101
to_numeric,
102+
to_datetime,
97103
to_timedelta,
104+
# misc
105+
Grouper,
106+
factorize,
98107
unique,
99108
value_counts,
109+
NamedAgg,
110+
array,
111+
Categorical,
112+
set_eng_float_format,
113+
Series,
114+
DataFrame,
100115
)
116+
101117
from pandas.core.arrays.sparse import SparseDtype
118+
119+
from pandas.tseries.api import infer_freq
120+
from pandas.tseries import offsets
121+
102122
from pandas.core.computation.api import eval
103-
import pandas.core.config_init
123+
104124
from pandas.core.reshape.api import (
105125
concat,
106-
crosstab,
107-
cut,
108-
get_dummies,
109126
lreshape,
110127
melt,
128+
wide_to_long,
111129
merge,
112130
merge_asof,
113131
merge_ordered,
132+
crosstab,
114133
pivot,
115134
pivot_table,
135+
get_dummies,
136+
cut,
116137
qcut,
117-
wide_to_long,
118138
)
119-
import pandas.testing
120139

121-
from pandas.io.api import ( # excel; parsers; pickle; pytables; sql; misc
140+
import pandas.api
141+
from pandas.util._print_versions import show_versions
142+
143+
from pandas.io.api import (
144+
# excel
122145
ExcelFile,
123146
ExcelWriter,
147+
read_excel,
148+
# parsers
149+
read_csv,
150+
read_fwf,
151+
read_table,
152+
# pickle
153+
read_pickle,
154+
to_pickle,
155+
# pytables
124156
HDFStore,
157+
read_hdf,
158+
# sql
159+
read_sql,
160+
read_sql_query,
161+
read_sql_table,
162+
# misc
125163
read_clipboard,
126-
read_csv,
127-
read_excel,
164+
read_parquet,
165+
read_orc,
128166
read_feather,
129-
read_fwf,
130167
read_gbq,
131-
read_hdf,
132168
read_html,
133169
read_json,
134-
read_orc,
135-
read_parquet,
136-
read_pickle,
170+
read_stata,
137171
read_sas,
138172
read_spss,
139-
read_sql,
140-
read_sql_query,
141-
read_sql_table,
142-
read_stata,
143-
read_table,
144-
to_pickle,
145173
)
174+
146175
from pandas.io.json import _json_normalize as json_normalize
147-
from pandas.tseries import offsets
148-
from pandas.tseries.api import infer_freq
176+
177+
from pandas.util._tester import test
178+
import pandas.testing
179+
import pandas.arrays
149180

150181
# use the closest tagged version if possible
151182
from ._version import get_versions
152183

153-
try:
154-
from pandas._libs import hashtable as _hashtable, lib as _lib, tslib as _tslib
155-
except ImportError as e: # pragma: no cover
156-
# hack but overkill to use re
157-
module = str(e).replace("cannot import name ", "")
158-
raise ImportError(
159-
f"C extension: {module} not built. If you want to import "
160-
"pandas from the source directory, you may need to run "
161-
"'python setup.py build_ext --inplace --force' to build the C extensions first."
162-
)
163-
164-
165-
166-
167-
168-
169-
170-
171-
172-
173-
174-
175-
176184
v = get_versions()
177185
__version__ = v.get("closest-tag", v["version"])
178186
__git_version__ = v.get("full-revisionid")

pandas/core/arrays/categorical.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,6 +2412,9 @@ def isin(self, values):
24122412
code_values = code_values[null_mask | (code_values >= 0)]
24132413
return algorithms.isin(self.codes, code_values)
24142414

2415+
def replace_list(self, to_replace, value, inplace: bool = False):
2416+
return self.replace(to_replace, value, inplace)
2417+
24152418
def replace(self, to_replace, value, inplace: bool = False):
24162419
"""
24172420
Replaces all instances of one value with another
@@ -2442,8 +2445,12 @@ def replace(self, to_replace, value, inplace: bool = False):
24422445
inplace = validate_bool_kwarg(inplace, "inplace")
24432446
cat = self if inplace else self.copy()
24442447
if is_list_like(to_replace):
2445-
# if value was also list-like, it would've been handled in generic.py
2446-
replace_dict = {replace_value: value for replace_value in to_replace}
2448+
if is_list_like(value):
2449+
if len(to_replace) != len(value):
2450+
raise ValueError("to_replace and value must be same length!")
2451+
replace_dict = dict(zip(to_replace, value))
2452+
else:
2453+
replace_dict = {replace_value: value for replace_value in to_replace}
24472454
else:
24482455
replace_dict = {to_replace: value}
24492456
for replace_value, new_value in replace_dict.items():

0 commit comments

Comments
 (0)