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

Fix: value counts on added/concatenated strings #908

Merged
merged 2 commits into from
Sep 24, 2020
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
2 changes: 1 addition & 1 deletion .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
uses: actions/cache@v2
with:
path: packages/vaex-core/build
key: ${{ runner.OS }}-${{ matrix.python-version }}-${{ hashFiles('packages/vaex-core/src/*') }}-v1
key: ${{ runner.OS }}-${{ matrix.python-version }}-${{ hashFiles('packages/vaex-core/src/*') }}-v2
- name: Fix cache timestamp
if: steps.cache-compiled-binaries.outputs.cache-hit == 'true' && matrix.os != 'windows-latest'
shell: bash
Expand Down
6 changes: 3 additions & 3 deletions packages/vaex-core/vaex/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ def value_counts(self, dropna=False, dropnan=False, dropmissing=False, ascending
:returns: Pandas series containing the counts
"""
from pandas import Series
dtype = self.dtype
data_type = self.data_type()

transient = self.transient or self.ds.filtered or self.ds.is_masked(self.expression)
if self.is_string() and not transient:
Expand All @@ -608,12 +608,12 @@ def value_counts(self, dropna=False, dropnan=False, dropmissing=False, ascending
if not isinstance(ar, ColumnString):
transient = True

counter_type = counter_type_from_dtype(self.dtype, transient)
counter_type = counter_type_from_dtype(data_type, transient)
counters = [None] * self.ds.executor.thread_pool.nthreads
def map(thread_index, i1, i2, ar):
if counters[thread_index] is None:
counters[thread_index] = counter_type()
if vaex.array_types.is_string_type(dtype):
if vaex.array_types.is_string_type(data_type):
previous_ar = ar
ar = _to_string_sequence(ar)
if not transient:
Expand Down
2 changes: 2 additions & 0 deletions packages/vaex-core/vaex/hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def counter_type_from_dtype(dtype, transient=True):
postfix = str(dtype)
if postfix == '>f8':
postfix = 'float64'
if postfix == 'double': # arrow
postfix = 'float64'
name = 'counter_' + postfix
return globals()[name]

Expand Down
11 changes: 11 additions & 0 deletions tests/value_counts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,14 @@ def test_value_counts_masked_str():
assert value_counts['A'] == 2
assert value_counts['B'] == 1
assert value_counts[''] == 2


def test_value_counts_add_strings():
x = ['car', 'car', 'boat']
y = ['red', 'red', 'blue']
df = vaex.from_arrays(x=x, y=y)
df['z'] = df.x + '-' + df.y

value_counts = df.z.value_counts()
assert list(value_counts.index) == ['car-red', 'boat-blue']
assert value_counts.values.tolist() == [2, 1]