Skip to content

Commit

Permalink
REFACTOR-modin-project#6845: Fix import issues found by CodeQL
Browse files Browse the repository at this point in the history
Signed-off-by: Anatoly Myachev <anatoly.myachev@intel.com>
  • Loading branch information
anmyachev committed Jan 4, 2024
1 parent 7ef544f commit 59459ca
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
3 changes: 1 addition & 2 deletions modin/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def _saving_make_api_url(token, _make_api_url=modin.utils._make_api_url):
make_default_file,
teardown_test_files,
)
from modin.utils import get_current_execution # noqa: E402


def pytest_addoption(parser):
Expand Down Expand Up @@ -275,7 +274,7 @@ def pytest_runtest_call(item):
if not isinstance(executions, list):
executions = [executions]

current_execution = get_current_execution()
current_execution = modin.utils.get_current_execution()
reason = marker.kwargs.pop("reason", "")

item.add_marker(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1887,7 +1887,7 @@ def filter(self, key):
)

if self is base:
exprs = OrderedDict()
exprs = dict()
for col in filtered_base._table_cols:
exprs[col] = filtered_base.ref(col)
else:
Expand All @@ -1899,7 +1899,8 @@ def filter(self, key):
if base._index_cols is None:
idx_name = mangle_index_names([None])[0]
exprs[idx_name] = filtered_base.ref(idx_name)
exprs.move_to_end(idx_name, last=False)
# `idx_name` should be first
exprs = {idx_name: filtered_base.ref(idx_name)} | exprs

return self.__constructor__(
columns=self.columns,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@
"""Utilities for internal use by the ``HdkOnNativeDataframe``."""

import re
import typing
from collections import OrderedDict
from functools import lru_cache
from typing import Any, List, Tuple, Union
from typing import Any, Dict, List, Tuple, Union

import numpy as np
import pandas
import pyarrow as pa
from pandas import Timestamp
from pandas.core.arrays.arrow.extension_types import ArrowIntervalType
from pandas.core.dtypes.common import _get_dtype, is_string_dtype
from pyarrow.types import is_dictionary
Expand All @@ -40,7 +37,7 @@ class ColNameCodec:

_IDX_NAME_PATTERN = re.compile(f"{IDX_COL_NAME}\\d+_(.*)")
_RESERVED_NAMES = (MODIN_UNNAMED_SERIES_LABEL, ROWID_COL_NAME)
_COL_TYPES = Union[str, int, float, Timestamp, None]
_COL_TYPES = Union[str, int, float, pandas.Timestamp, None]
_COL_NAME_TYPE = Union[_COL_TYPES, Tuple[_COL_TYPES, ...]]

def _encode_tuple(values: Tuple[_COL_TYPES, ...]) -> str: # noqa: GL08
Expand Down Expand Up @@ -73,7 +70,7 @@ def _decode_tuple(encoded: str) -> Tuple[_COL_TYPES, ...]: # noqa: GL08
str: lambda v: "_E" if len(v) == 0 else "_S" + v[1:] if v[0] == "_" else v,
int: lambda v: f"_I{v}",
float: lambda v: f"_F{v}",
Timestamp: lambda v: f"_D{v.timestamp()}_{v.tz}",
pandas.Timestamp: lambda v: f"_D{v.timestamp()}_{v.tz}",
}

_DECODERS = {
Expand All @@ -83,7 +80,7 @@ def _decode_tuple(encoded: str) -> Tuple[_COL_TYPES, ...]: # noqa: GL08
"S": lambda v: "_" + v[2:],
"I": lambda v: int(v[2:]),
"F": lambda v: float(v[2:]),
"D": lambda v: Timestamp.fromtimestamp(
"D": lambda v: pandas.Timestamp.fromtimestamp(
float(v[2 : (idx := v.index("_", 2))]), tz=v[idx + 1 :]
),
}
Expand Down Expand Up @@ -225,7 +222,7 @@ def demangle_index_name(col: str) -> _COL_NAME_TYPE:
return col

@staticmethod
def concat_index_names(frames) -> typing.OrderedDict[str, Any]:
def concat_index_names(frames) -> Dict[str, Any]:
"""
Calculate the index names and dtypes.
Expand All @@ -238,10 +235,10 @@ def concat_index_names(frames) -> typing.OrderedDict[str, Any]:
Returns
-------
typing.OrderedDict[str, Any]
Dict[str, Any]
"""
first = frames[0]
names = OrderedDict()
names = {}
if first._index_width() > 1:
# When we're dealing with a MultiIndex case the resulting index
# inherits the levels from the first frame in concatenation.
Expand Down Expand Up @@ -413,7 +410,7 @@ def to_empty_pandas_df(df):
return pandas.DataFrame(columns=df.columns, index=idx)

new_dtypes = []
exprs = OrderedDict()
exprs = {}
merged = to_empty_pandas_df(left).merge(
to_empty_pandas_df(right),
how=how,
Expand Down Expand Up @@ -586,8 +583,7 @@ class _CategoricalDtypeMapper: # noqa: GL08
@staticmethod
def __from_arrow__(arr): # noqa: GL08
values = []
# Using OrderedDict as an ordered set to preserve the categories order
categories = OrderedDict()
categories = {}
chunks = arr.chunks if isinstance(arr, pa.ChunkedArray) else (arr,)
for chunk in chunks:
assert isinstance(chunk, pa.DictionaryArray)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
"""Module provides classes for lazy DataFrame algebra operations."""

import abc
import typing
from collections import OrderedDict
from typing import TYPE_CHECKING, Dict, List, Union

import numpy as np
Expand Down Expand Up @@ -971,7 +969,7 @@ def execute_arrow(self, tables: Union[pa.Table, List[pa.Table]]) -> pa.Table:
except pa.lib.ArrowInvalid:
# Probably, some tables have different column types.
# Trying to find a common type and cast the columns.
fields: typing.OrderedDict[str, pa.Field] = OrderedDict()
fields: Dict[str, pa.Field] = {}
for table in tables:
for col_name in table.column_names:
field = table.field(col_name)
Expand Down Expand Up @@ -1178,7 +1176,7 @@ def translate_exprs_to_base(exprs, base):
new_frames.discard(base)
frames = new_frames

res = OrderedDict()
res = {}
for col in exprs.keys():
res[col] = new_exprs[col]
return res
Expand All @@ -1205,7 +1203,7 @@ def replace_frame_in_exprs(exprs, old_frame, new_frame):
mapper = InputMapper()
mapper.add_mapper(old_frame, FrameMapper(new_frame))

res = OrderedDict()
res = {}
for col in exprs.keys():
res[col] = exprs[col].translate_input(mapper)
return res

0 comments on commit 59459ca

Please sign in to comment.