/
__init__.py
308 lines (292 loc) · 7.34 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
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
# TODO: In the future `set_option` or similar needs to run on every node
# in order to keep all pandas instances across nodes consistent
import pandas
__pandas_version__ = "0.24.2"
if pandas.__version__ != __pandas_version__:
raise ImportError(
"The pandas version installed does not match the required pandas "
"version in Modin. Please install pandas {} to use "
"Modin.".format(__pandas_version__)
)
from pandas import (
eval,
unique,
value_counts,
cut,
to_numeric,
factorize,
test,
qcut,
Panel,
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,
CategoricalDtype,
DatetimeTZDtype,
IntervalDtype,
PeriodDtype,
RangeIndex,
Int64Index,
UInt64Index,
Float64Index,
TimedeltaIndex,
IntervalIndex,
IndexSlice,
TimeGrouper,
Grouper,
array,
Period,
show_versions,
DateOffset,
timedelta_range,
infer_freq,
interval_range,
ExcelWriter,
SparseArray,
SparseSeries,
SparseDataFrame,
datetime,
)
import threading
import os
import ray
import types
from .. import __version__
from .concat import concat
from .dataframe import DataFrame
from .datetimes import to_datetime
from .io import (
read_csv,
read_parquet,
read_json,
read_html,
read_clipboard,
read_excel,
read_hdf,
read_feather,
read_msgpack,
read_stata,
read_sas,
read_pickle,
read_sql,
read_gbq,
read_table,
read_fwf,
read_sql_table,
read_sql_query,
ExcelFile,
to_pickle,
HDFStore,
)
from .reshape import get_dummies, melt, crosstab, lreshape, wide_to_long
from .series import Series
from .general import (
isna,
isnull,
merge,
merge_asof,
merge_ordered,
pivot_table,
notnull,
notna,
pivot,
)
from .plotting import Plotting as plotting
from .. import __execution_engine__ as execution_engine
# Set this so that Pandas doesn't try to multithread by itself
os.environ["OMP_NUM_THREADS"] = "1"
num_cpus = 1
def initialize_ray():
"""Initializes ray based on environment variables and internal defaults."""
if threading.current_thread().name == "MainThread":
plasma_directory = None
cluster = os.environ.get("MODIN_RAY_CLUSTER", None)
redis_address = os.environ.get("MODIN_REDIS_ADDRESS", None)
if cluster == "True" and redis_address is not None:
# We only start ray in a cluster setting for the head node.
ray.init(
include_webui=False,
ignore_reinit_error=True,
redis_address=redis_address,
logging_level=100,
)
elif cluster is None:
object_store_memory = os.environ.get("MODIN_MEMORY", None)
if os.environ.get("MODIN_OUT_OF_CORE", "False").title() == "True":
from tempfile import gettempdir
plasma_directory = gettempdir()
# We may have already set the memory from the environment variable, we don't
# want to overwrite that value if we have.
if object_store_memory is None:
# Round down to the nearest Gigabyte.
mem_bytes = ray.utils.get_system_memory() // 10 ** 9 * 10 ** 9
# Default to 8x memory for out of core
object_store_memory = 8 * mem_bytes
# In case anything failed above, we can still improve the memory for Modin.
if object_store_memory is None:
# Round down to the nearest Gigabyte.
object_store_memory = int(
0.6 * ray.utils.get_system_memory() // 10 ** 9 * 10 ** 9
)
# If the memory pool is smaller than 2GB, just use the default in ray.
if object_store_memory == 0:
object_store_memory = None
else:
object_store_memory = int(object_store_memory)
ray.init(
include_webui=False,
ignore_reinit_error=True,
plasma_directory=plasma_directory,
object_store_memory=object_store_memory,
redis_address=redis_address,
logging_level=100,
)
# Register custom serializer for method objects to avoid warning message.
# We serialize `MethodType` objects when we use AxisPartition operations.
ray.register_custom_serializer(types.MethodType, use_pickle=True)
if execution_engine == "Ray":
initialize_ray()
num_cpus = ray.cluster_resources()["CPU"]
elif execution_engine == "Dask": # pragma: no cover
from distributed.client import _get_global_client
if threading.current_thread().name == "MainThread":
# initialize the dask client
client = _get_global_client()
if client is None:
from distributed import Client
client = Client()
num_cpus = sum(client.ncores().values())
elif execution_engine != "Python":
raise ImportError("Unrecognized execution engine: {}.".format(execution_engine))
DEFAULT_NPARTITIONS = max(4, int(num_cpus))
__all__ = [
"DataFrame",
"Series",
"read_csv",
"read_parquet",
"read_json",
"read_html",
"read_clipboard",
"read_excel",
"read_hdf",
"read_feather",
"read_msgpack",
"read_stata",
"read_sas",
"read_pickle",
"read_sql",
"read_gbq",
"read_table",
"concat",
"eval",
"unique",
"value_counts",
"cut",
"to_numeric",
"factorize",
"test",
"qcut",
"to_datetime",
"get_dummies",
"isna",
"isnull",
"merge",
"pivot_table",
"Panel",
"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",
"RangeIndex",
"Int64Index",
"UInt64Index",
"Float64Index",
"TimedeltaIndex",
"IntervalIndex",
"IndexSlice",
"TimeGrouper",
"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",
"SparseArray",
"SparseSeries",
"SparseDataFrame",
"datetime",
]
del pandas