Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for multi-indexed column names #124

Merged
merged 6 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 7 additions & 25 deletions hatchet/query/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@


class AbstractQuery(ABC):

"""Base class for all 'old-style' queries."""

@abstractmethod
Expand Down Expand Up @@ -87,7 +86,6 @@ def _get_new_query(self):


class NaryQuery(AbstractQuery):

"""Base class for all compound queries that act on
and merged N separate subqueries."""

Expand Down Expand Up @@ -149,7 +147,6 @@ def _convert_to_new_query(self, subqueries):


class AndQuery(NaryQuery):

"""Compound query that returns the intersection of the results
of the subqueries."""

Expand All @@ -160,8 +157,7 @@ def __init__(self, *args):
*args (AbstractQuery, str, or list): the subqueries to be performed
"""
warnings.warn(
"Old-style queries are deprecated as of Hatchet 2023.1.0 and will be removed in the \
future. Please use new-style queries (e.g., hatchet.query.ConjunctionQuery) instead.",
"Old-style queries are deprecated as of Hatchet 2023.1.0 and will be removed in the future. Please use new-style queries (e.g., hatchet.query.ConjunctionQuery) instead.",
DeprecationWarning,
stacklevel=2,
)
Expand All @@ -181,7 +177,6 @@ def _convert_to_new_query(self, subqueries):


class OrQuery(NaryQuery):

"""Compound query that returns the union of the results
of the subqueries"""

Expand All @@ -192,8 +187,7 @@ def __init__(self, *args):
*args (AbstractQuery, str, or list): the subqueries to be performed
"""
warnings.warn(
"Old-style queries are deprecated as of Hatchet 2023.1.0 and will be removed in the \
future. Please use new-style queries (e.g., hatchet.query.DisjunctionQuery) instead.",
"Old-style queries are deprecated as of Hatchet 2023.1.0 and will be removed in the future. Please use new-style queries (e.g., hatchet.query.DisjunctionQuery) instead.",
DeprecationWarning,
stacklevel=2,
)
Expand All @@ -213,7 +207,6 @@ def _convert_to_new_query(self, subqueries):


class XorQuery(NaryQuery):

"""Compound query that returns the symmetric difference
(i.e., set-based XOR) of the results of the subqueries"""

Expand All @@ -224,8 +217,7 @@ def __init__(self, *args):
*args (AbstractQuery, str, or list): the subqueries to be performed
"""
warnings.warn(
"Old-style queries are deprecated as of Hatchet 2023.1.0 and will be removed in the \
future. Please use new-style queries (e.g., hatchet.query.ExclusiveDisjunctionQuery) instead.",
"Old-style queries are deprecated as of Hatchet 2023.1.0 and will be removed in the future. Please use new-style queries (e.g., hatchet.query.ExclusiveDisjunctionQuery) instead.",
DeprecationWarning,
stacklevel=2,
)
Expand All @@ -245,7 +237,6 @@ def _convert_to_new_query(self, subqueries):


class NotQuery(NaryQuery):

"""Compound query that returns all nodes in the GraphFrame that
are not returned from the subquery."""

Expand All @@ -256,8 +247,7 @@ def __init__(self, *args):
*args (AbstractQuery, str, or list): the subquery to be performed
"""
warnings.warn(
"Old-style queries are deprecated as of Hatchet 2023.1.0 and will be removed in the \
future. Please use new-style queries (e.g., hatchet.query.NegationQuery) instead.",
"Old-style queries are deprecated as of Hatchet 2023.1.0 and will be removed in the future. Please use new-style queries (e.g., hatchet.query.NegationQuery) instead.",
DeprecationWarning,
stacklevel=2,
)
Expand All @@ -273,7 +263,6 @@ def _convert_to_new_query(self, subqueries):


class QueryMatcher(AbstractQuery):

"""Processes and applies base syntax queries and Object-based queries to GraphFrames."""

def __init__(self, query=None):
Expand All @@ -284,10 +273,7 @@ def __init__(self, query=None):
into its internal representation
"""
warnings.warn(
"Old-style queries are deprecated as of Hatchet 2023.1.0 and will be removed in the \
future. Please use new-style queries instead. For QueryMatcher, the equivalent \
new-style queries are hatchet.query.Query for base-syntax queries and \
hatchet.query.ObjectQuery for the object-dialect.",
"Old-style queries are deprecated as of Hatchet 2023.1.0 and will be removed in the future. Please use new-style queries instead. For QueryMatcher, the equivalent new-style queries are hatchet.query.Query for base-syntax queries and hatchet.query.ObjectQuery for the object-dialect.",
DeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -348,7 +334,6 @@ def _get_new_query(self):


class CypherQuery(QueryMatcher):

"""Processes and applies Strinb-based queries to GraphFrames."""

def __init__(self, cypher_query):
Expand All @@ -358,9 +343,7 @@ def __init__(self, cypher_query):
cypher_query (str): the String-based query
"""
warnings.warn(
"Old-style queries are deprecated as of Hatchet 2023.1.0 and will be removed in the \
future. Please use new-style queries instead. For CypherQuery, the equivalent \
new-style query is hatchet.query.StringQuery.",
"Old-style queries are deprecated as of Hatchet 2023.1.0 and will be removed in the future. Please use new-style queries instead. For CypherQuery, the equivalent new-style query is hatchet.query.StringQuery.",
DeprecationWarning,
stacklevel=2,
)
Expand All @@ -386,8 +369,7 @@ def parse_cypher_query(cypher_query):
(CypherQuery): a Hatchet query for this String-based query
"""
warnings.warn(
"Old-style queries are deprecated as of Hatchet 2023.1.0 and will be removed in the \
future. Please use new-style queries (e.g., hatchet.query.parse_string_dialect) instead.",
"Old-style queries are deprecated as of Hatchet 2023.1.0 and will be removed in the future. Please use new-style queries (e.g., hatchet.query.parse_string_dialect) instead.",
DeprecationWarning,
stacklevel=2,
)
Expand Down
17 changes: 12 additions & 5 deletions hatchet/query/object_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ def filter_single_series(df_row, key, single_value):

matches = True
for k, v in attr_filter.items():
metric_name = k
if isinstance(k, (tuple, list)) and len(k) == 1:
metric_name = k[0]
try:
_ = iter(v)
# Manually raise TypeError if v is a string so that
Expand All @@ -114,10 +117,12 @@ def filter_single_series(df_row, key, single_value):
raise TypeError
# Runs if v is not iterable (e.g., list, tuple, etc.)
except TypeError:
matches = matches and filter_single_series(df_row, k, v)
matches = matches and filter_single_series(df_row, metric_name, v)
else:
for single_value in v:
matches = matches and filter_single_series(df_row, k, single_value)
matches = matches and filter_single_series(
df_row, metric_name, single_value
)
return matches

def filter_dframe(df_row):
Expand Down Expand Up @@ -186,16 +191,19 @@ def filter_single_dframe(node, df_row, key, single_value):
matches = True
node = df_row.name.to_frame().index[0][0]
for k, v in attr_filter.items():
metric_name = k
if isinstance(k, (tuple, list)) and len(k) == 1:
metric_name = k[0]
try:
_ = iter(v)
if isinstance(v, str):
raise TypeError
except TypeError:
matches = matches and filter_single_dframe(node, df_row, k, v)
matches = matches and filter_single_dframe(node, df_row, metric_name, v)
else:
for single_value in v:
matches = matches and filter_single_dframe(
node, df_row, k, single_value
node, df_row, metric_name, single_value
)
return matches

Expand All @@ -208,7 +216,6 @@ def filter_choice(df_row):


class ObjectQuery(Query):

"""Class for representing and parsing queries using the Object-based dialect."""

def __init__(self, query, multi_index_mode="off"):
Expand Down
Loading
Loading