1111# ANY KIND, either express or implied. See the License for the specific language
1212# governing permissions and limitations under the License.
1313
14- import os
1514import warnings
16- from packaging import version
17- import collections
1815
1916from ._version import get_versions
2017
@@ -35,95 +32,6 @@ def custom_formatwarning(msg, category, *args, **kwargs):
3532)
3633
3734
38- def get_execution_engine ():
39- # In the future, when there are multiple engines and different ways of
40- # backing the DataFrame, there will have to be some changed logic here to
41- # decide these things. In the meantime, we will use the currently supported
42- # execution engine + backing (Pandas + Ray).
43- if "MODIN_ENGINE" in os .environ :
44- # .title allows variants like ray, RAY, Ray
45- return os .environ ["MODIN_ENGINE" ].title ()
46- else :
47- if "MODIN_DEBUG" in os .environ :
48- return "Python"
49- else :
50- try :
51- import ray
52-
53- except ImportError :
54- pass
55- else :
56- if version .parse (ray .__version__ ) < version .parse ("1.0.0" ):
57- raise ImportError (
58- "Please `pip install modin[ray]` to install compatible Ray version."
59- )
60- return "Ray"
61- try :
62- import dask
63- import distributed
64-
65- except ImportError :
66- raise ImportError (
67- "Please `pip install modin[ray]` or `modin[dask]` to install an engine"
68- )
69- else :
70- if version .parse (dask .__version__ ) < version .parse (
71- "2.1.0"
72- ) or version .parse (distributed .__version__ ) < version .parse ("2.3.2" ):
73- raise ImportError (
74- "Please `pip install modin[dask]` to install compatible Dask version."
75- )
76- return "Dask"
77-
78-
79- def get_partition_format ():
80- # See note above about engine + backing.
81- return os .environ .get ("MODIN_BACKEND" , "Pandas" ).title ()
82-
83-
84- class Publisher (object ):
85- def __init__ (self , name , value ):
86- self .name = name
87- self .__value = value .title ()
88- self .__subs = []
89- self .__once = collections .defaultdict (list )
90-
91- def subscribe (self , callback ):
92- self .__subs .append (callback )
93- callback (self )
94-
95- def once (self , onvalue , callback ):
96- onvalue = onvalue .title ()
97- if onvalue == self .__value :
98- callback (self )
99- else :
100- self .__once [onvalue ].append (callback )
101-
102- def get (self ):
103- return self .__value
104-
105- def _put_nocallback (self , value ):
106- value = value .title () # normalize the value
107- oldvalue , self .__value = self .__value , value
108- return oldvalue
109-
110- def _check_callbacks (self , oldvalue ):
111- if oldvalue == self .__value :
112- return
113- for callback in self .__subs :
114- callback (self )
115- once = self .__once .pop (self .__value , ())
116- for callback in once :
117- callback (self )
118-
119- def put (self , value ):
120- self ._check_callbacks (self ._put_nocallback (value ))
121-
122-
123- execution_engine = Publisher (name = "execution_engine" , value = get_execution_engine ())
124- partition_format = Publisher (name = "partition_format" , value = get_partition_format ())
125-
126-
12735def set_backends (engine = None , partition = None ):
12836 """
12937 Method to set the _pair_ of execution engine and partition format simultaneously.
@@ -132,24 +40,22 @@ def set_backends(engine=None, partition=None):
13240
13341 The method returns pair of old values, so it is easy to return back.
13442 """
43+ from .config import Engine , Backend
44+
13545 old_engine , old_partition = None , None
13646 # defer callbacks until both entities are set
13747 if engine is not None :
138- old_engine = execution_engine ._put_nocallback (engine )
48+ old_engine = Engine ._put_nocallback (engine )
13949 if partition is not None :
140- old_partition = partition_format ._put_nocallback (partition )
50+ old_partition = Backend ._put_nocallback (partition )
14151 # execute callbacks if something was changed
14252 if old_engine is not None :
143- execution_engine ._check_callbacks (old_engine )
53+ Engine ._check_callbacks (old_engine )
14454 if old_partition is not None :
145- partition_format ._check_callbacks (old_partition )
55+ Backend ._check_callbacks (old_partition )
14656
14757 return old_engine , old_partition
14858
14959
150- # We don't want these used outside of this file.
151- del get_execution_engine
152- del get_partition_format
153-
15460__version__ = get_versions ()["version" ]
15561del get_versions
0 commit comments