1414
1515from __future__ import annotations
1616
17- from typing import cast , Hashable , Iterable , Sequence
17+ from typing import cast , Hashable , Iterable , Optional , Sequence , TYPE_CHECKING
1818
1919import bigframes_vendored .pandas .core .indexes .multi as vendored_pandas_multindex
2020import pandas
2121
2222from bigframes .core .indexes .base import Index
2323
24+ if TYPE_CHECKING :
25+ import bigframes .session
26+
2427
2528class MultiIndex (Index , vendored_pandas_multindex .MultiIndex ):
2629 __doc__ = vendored_pandas_multindex .MultiIndex .__doc__
@@ -31,18 +34,50 @@ def from_tuples(
3134 tuples : Iterable [tuple [Hashable , ...]],
3235 sortorder : int | None = None ,
3336 names : Sequence [Hashable ] | Hashable | None = None ,
37+ * ,
38+ session : Optional [bigframes .session .Session ] = None ,
3439 ) -> MultiIndex :
3540 pd_index = pandas .MultiIndex .from_tuples (tuples , sortorder , names )
3641 # Index.__new__ should detect multiple levels and properly create a multiindex
37- return cast (MultiIndex , Index (pd_index ))
42+ return cast (MultiIndex , Index (pd_index , session = session ))
3843
3944 @classmethod
4045 def from_arrays (
4146 cls ,
4247 arrays ,
4348 sortorder : int | None = None ,
4449 names = None ,
50+ * ,
51+ session : Optional [bigframes .session .Session ] = None ,
4552 ) -> MultiIndex :
4653 pd_index = pandas .MultiIndex .from_arrays (arrays , sortorder , names )
4754 # Index.__new__ should detect multiple levels and properly create a multiindex
48- return cast (MultiIndex , Index (pd_index ))
55+ return cast (MultiIndex , Index (pd_index , session = session ))
56+
57+
58+ class MultiIndexAccessor :
59+ """Proxy to MultiIndex constructors to allow a session to be passed in."""
60+
61+ def __init__ (self , session : bigframes .session .Session ):
62+ self ._session = session
63+
64+ def __call__ (self , * args , ** kwargs ) -> MultiIndex :
65+ """Construct a MultiIndex using the associated Session.
66+
67+ See :class:`bigframes.pandas.MultiIndex`.
68+ """
69+ return MultiIndex (* args , session = self ._session , ** kwargs )
70+
71+ def from_arrays (self , * args , ** kwargs ) -> MultiIndex :
72+ """Construct a MultiIndex using the associated Session.
73+
74+ See :func:`bigframes.pandas.MultiIndex.from_arrays`.
75+ """
76+ return MultiIndex .from_arrays (* args , session = self ._session , ** kwargs )
77+
78+ def from_tuples (self , * args , ** kwargs ) -> MultiIndex :
79+ """Construct a MultiIndex using the associated Session.
80+
81+ See :func:`bigframes.pandas.MultiIndex.from_tuples`.
82+ """
83+ return MultiIndex .from_tuples (* args , session = self ._session , ** kwargs )
0 commit comments