• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

georgia-tech-db / eva / #850

08 Nov 2023 08:36PM UTC coverage: 0.0% (-77.0%) from 76.982%
#850

push

circleci

americast
fix metrics logic

0 of 1 new or added line in 1 file covered. (0.0%)

9789 existing lines in 252 files now uncovered.

0 of 12428 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/evadb/functions/ndarray/array_count.py
1
# coding=utf-8
2
# Copyright 2018-2023 EvaDB
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
UNCOV
15
import numpy as np
×
UNCOV
16
import pandas as pd
×
17

UNCOV
18
from evadb.functions.abstract.abstract_function import AbstractFunction
×
19

20

UNCOV
21
class ArrayCount(AbstractFunction):
×
UNCOV
22
    @property
×
UNCOV
23
    def name(self) -> str:
×
24
        return "ArrayCount"
×
25

UNCOV
26
    def setup(self):
×
UNCOV
27
        pass
×
28

UNCOV
29
    def forward(self, frames: pd.DataFrame) -> pd.DataFrame:
×
30
        """
31
        It will return a count of search element for each tuple.
32
        The idea is to flatten the input array along the first dimension and
33
        count the search element in this flattened array.
34
        For example,
35
        a tuple of shape (3,4,5) will be flattened into three (4,5) elements.
36
        And the search key is expected to be of shape (4,5),
37
        else we throw an error.
38

39
        frames: DataFrame
40
            col1        col2
41
        0   ndarray1    search_key
42
        1   ndarray2    search_key
43

44
        out: DataFrame
45
            count
46
        0   int
47
        1   int
48

49
        """
50
        # sanity check
51
        if len(frames.columns) != 2:
×
52
            raise ValueError("input contains more than one column")
53

54
        search_element = frames[frames.columns[-1]][0]
×
55
        values = pd.DataFrame(frames[frames.columns[0]])
×
56

57
        count_result = values.apply(
×
58
            lambda x: self.count_in_row(x[0], search_element), axis=1
59
        )
60

61
        return pd.DataFrame({"key_count": count_result.values})
×
62

UNCOV
63
    def count_in_row(self, row_val, search_element):
×
64
        # change the row and search element to numpy array
65
        row_val = np.array(row_val)
×
66
        search_element = np.array(search_element)
×
67

68
        # checks if dimension diff is one between
69
        # row_val and search_element
70
        if row_val.ndim - search_element.ndim != 1:
×
71
            raise ValueError("inconsistent dimensions for row value and search element")
72

73
        result = row_val == search_element
×
74
        # reshape along the first dimension and then
75
        # check how many time search element exists
76
        return result.reshape(result.shape[0], -1).all(axis=1).sum()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc