Skip to content

Commit

Permalink
Adding test for virtual column plus typo.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlenkaF committed Aug 12, 2021
1 parent a4c1835 commit 8c52ceb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
12 changes: 6 additions & 6 deletions packages/vaex-core/vaex/dataframe_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class _DtypeKind(enum.IntEnum):
DATETIME = 22
CATEGORICAL = 23

def convert_column_to_ndarray(col):
def convert_column_to_ndarray(col) -> np.ndarray:
"""
Convert an int, uint, float or bool column to a numpy array
"""
Expand Down Expand Up @@ -111,7 +111,7 @@ def buffer_to_ndarray(_buffer, _dtype) -> np.ndarray:

return x

def convert_categorical_column(col):
def convert_categorical_column(col) -> Tuple[np.ndarray, np.ndarray]:
"""
Convert a categorical column to a numpy array of codes, values and categories/labels
"""
Expand All @@ -136,7 +136,7 @@ class _VaexBuffer:
Data in the buffer is guaranteed to be contiguous in memory.
"""

def __init__(self, x):
def __init__(self, x) -> None:
"""
Handle only regular columns (= numpy arrays) for now.
"""
Expand Down Expand Up @@ -191,7 +191,7 @@ class _VaexColumn:
doesn't need its own version or ``__column__`` protocol.
"""

def __init__(self, column, metadata : dict = {}):
def __init__(self, column, metadata : dict = {}) -> None:
"""
Note: assuming column is an expression.
"""
Expand Down Expand Up @@ -440,7 +440,7 @@ def __init__(self, df, nan_as_null : bool = False) -> None:
self._nan_as_null = nan_as_null

@property
def metadata(self):
def metadata(self) -> Dict[str, Any]:
is_category = {}
labels = {}
for i in self._df.get_names():
Expand Down Expand Up @@ -486,4 +486,4 @@ def get_chunks(self, n_chunks : Optional[int] = None) -> Iterable['_VaexDataFram
"""
Return an iterator yielding the chunks.
"""
return {} # TODO
return {} # TODO
15 changes: 13 additions & 2 deletions tests/dataframe_protocol_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ def test_categorical():
assert df2['year'].tolist() == df['year'].tolist()
assert df2['weekday'].tolist() == df['weekday'].tolist()

def test_mixed_intfloatbool():
df = vaex.from_arrays(
x=np.array([True, True, False]),
y=np.array([1, 2, 0]),
z=np.array([9.2, 10.5, 11.8]))
df.add_virtual_column("r", "sqrt(y**2 + z**2)")
df2 = from_dataframe_to_vaex(df)
assert df2.x.tolist() == df.x.tolist()
assert df2.y.tolist() == df.y.tolist()
assert df2.z.tolist() == df.z.tolist()
assert df2.r.tolist() == df.r.tolist()

def test_arrow_dictionary():
# ERRORS!
indices = pa.array([0, 1, 0, 1, 2, 0, None, 2])
Expand All @@ -52,5 +64,4 @@ def test_arrow_dictionary():
assert col.describe_categorical == (False, True, {0: 'foo', 1: 'bar', 2: 'baz'})

df2 = from_dataframe_to_vaex(df)
assert df2.x.tolist() == df.x.tolist()

assert df2.x.tolist() == df.x.tolist()

0 comments on commit 8c52ceb

Please sign in to comment.