-
Notifications
You must be signed in to change notification settings - Fork 647
/
__init__.py
340 lines (308 loc) · 7.77 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# Licensed to Modin Development Team under one or more contributor license agreements.
# See the NOTICE file distributed with this work for additional information regarding
# copyright ownership. The Modin Development Team licenses this file to you under the
# Apache License, Version 2.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.
import pandas
__pandas_version__ = "1.1.5"
if pandas.__version__ != __pandas_version__:
import warnings
warnings.warn(
"The pandas version installed {} does not match the supported pandas version in"
" Modin {}. This may cause undesired side effects!".format(
pandas.__version__, __pandas_version__
)
)
from pandas import (
eval,
cut,
factorize,
test,
qcut,
date_range,
period_range,
Index,
MultiIndex,
CategoricalIndex,
bdate_range,
DatetimeIndex,
Timedelta,
Timestamp,
to_timedelta,
set_eng_float_format,
options,
set_option,
NaT,
PeriodIndex,
Categorical,
Interval,
UInt8Dtype,
UInt16Dtype,
UInt32Dtype,
UInt64Dtype,
SparseDtype,
Int8Dtype,
Int16Dtype,
Int32Dtype,
Int64Dtype,
StringDtype,
BooleanDtype,
CategoricalDtype,
DatetimeTZDtype,
IntervalDtype,
PeriodDtype,
RangeIndex,
Int64Index,
UInt64Index,
Float64Index,
TimedeltaIndex,
IntervalIndex,
IndexSlice,
Grouper,
array,
Period,
show_versions,
DateOffset,
timedelta_range,
infer_freq,
interval_range,
ExcelWriter,
datetime,
NamedAgg,
NA,
)
import threading
import os
import multiprocessing
from modin.config import Engine, Parameter
# Set this so that Pandas doesn't try to multithread by itself
os.environ["OMP_NUM_THREADS"] = "1"
DEFAULT_NPARTITIONS = 4
num_cpus = 1
_is_first_update = {}
dask_client = None
_NOINIT_ENGINES = {
"Python",
} # engines that don't require initialization, useful for unit tests
def _update_engine(publisher: Parameter):
global DEFAULT_NPARTITIONS, dask_client, num_cpus
from modin.config import Backend, CpuCount
if publisher.get() == "Ray":
import ray
from modin.engines.ray.utils import initialize_ray
# With OmniSci backend there is only a single worker per node
# and we allow it to work on all cores.
if Backend.get() == "Omnisci":
CpuCount.put(1)
os.environ["OMP_NUM_THREADS"] = str(multiprocessing.cpu_count())
if _is_first_update.get("Ray", True):
initialize_ray()
num_cpus = ray.cluster_resources()["CPU"]
elif publisher.get() == "Dask": # pragma: no cover
from distributed.client import get_client
if threading.current_thread().name == "MainThread" and _is_first_update.get(
"Dask", True
):
import warnings
warnings.warn("The Dask Engine for Modin is experimental.")
try:
dask_client = get_client()
except ValueError:
from distributed import Client
dask_client = Client(n_workers=CpuCount.get())
num_cpus = len(dask_client.ncores())
elif publisher.get() == "Cloudray":
from modin.experimental.cloud import get_connection
conn = get_connection()
remote_ray = conn.modules["ray"]
if _is_first_update.get("Cloudray", True):
@conn.teleport
def init_remote_ray(partition):
from ray import ray_constants
import modin
from modin.engines.ray.utils import initialize_ray
modin.set_backends("Ray", partition)
initialize_ray(
override_is_cluster=True,
override_redis_address=f"localhost:{ray_constants.DEFAULT_PORT}",
override_redis_password=ray_constants.REDIS_DEFAULT_PASSWORD,
)
init_remote_ray(Backend.get())
# import EngineDispatcher here to initialize IO class
# so it doesn't skew read_csv() timings later on
import modin.data_management.factories.dispatcher # noqa: F401
else:
get_connection().modules["modin"].set_backends("Ray", Backend.get())
num_cpus = remote_ray.cluster_resources()["CPU"]
elif publisher.get() == "Cloudpython":
from modin.experimental.cloud import get_connection
get_connection().modules["modin"].set_backends("Python")
elif publisher.get() not in _NOINIT_ENGINES:
raise ImportError("Unrecognized execution engine: {}.".format(publisher.get()))
_is_first_update[publisher.get()] = False
DEFAULT_NPARTITIONS = max(4, int(num_cpus))
Engine.subscribe(_update_engine)
from .. import __version__
from .dataframe import DataFrame
from .io import (
read_csv,
read_parquet,
read_json,
read_html,
read_clipboard,
read_excel,
read_hdf,
read_feather,
read_stata,
read_sas,
read_pickle,
read_sql,
read_gbq,
read_table,
read_fwf,
read_sql_table,
read_sql_query,
read_spss,
ExcelFile,
to_pickle,
HDFStore,
json_normalize,
read_orc,
)
from .series import Series
from .general import (
concat,
isna,
isnull,
merge,
merge_asof,
merge_ordered,
pivot_table,
notnull,
notna,
pivot,
to_numeric,
to_datetime,
unique,
value_counts,
get_dummies,
melt,
crosstab,
lreshape,
wide_to_long,
)
from .plotting import Plotting as plotting
__all__ = [
"DataFrame",
"Series",
"read_csv",
"read_parquet",
"read_json",
"read_html",
"read_clipboard",
"read_excel",
"read_hdf",
"read_feather",
"read_stata",
"read_sas",
"read_pickle",
"read_sql",
"read_gbq",
"read_table",
"read_spss",
"read_orc",
"json_normalize",
"concat",
"eval",
"cut",
"factorize",
"test",
"qcut",
"to_datetime",
"get_dummies",
"isna",
"isnull",
"merge",
"pivot_table",
"date_range",
"Index",
"MultiIndex",
"Series",
"bdate_range",
"period_range",
"DatetimeIndex",
"to_timedelta",
"set_eng_float_format",
"options",
"set_option",
"CategoricalIndex",
"Timedelta",
"Timestamp",
"NaT",
"PeriodIndex",
"Categorical",
"__version__",
"melt",
"crosstab",
"plotting",
"Interval",
"UInt8Dtype",
"UInt16Dtype",
"UInt32Dtype",
"UInt64Dtype",
"SparseDtype",
"Int8Dtype",
"Int16Dtype",
"Int32Dtype",
"Int64Dtype",
"CategoricalDtype",
"DatetimeTZDtype",
"IntervalDtype",
"PeriodDtype",
"BooleanDtype",
"StringDtype",
"NA",
"RangeIndex",
"Int64Index",
"UInt64Index",
"Float64Index",
"TimedeltaIndex",
"IntervalIndex",
"IndexSlice",
"Grouper",
"array",
"Period",
"show_versions",
"DateOffset",
"timedelta_range",
"infer_freq",
"interval_range",
"ExcelWriter",
"read_fwf",
"read_sql_table",
"read_sql_query",
"ExcelFile",
"to_pickle",
"HDFStore",
"lreshape",
"wide_to_long",
"merge_asof",
"merge_ordered",
"notnull",
"notna",
"pivot",
"to_numeric",
"unique",
"value_counts",
"datetime",
"NamedAgg",
"DEFAULT_NPARTITIONS",
]
del pandas, Engine, Parameter