Skip to content
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
10 changes: 5 additions & 5 deletions docs/user-guide/pandas.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ convert:
... {'name': 'Mikhail', 'age': 57},
... ])
>>> struct_arr.to_pandas()
age name
0 25 Joseph
1 31 Narendra
2 33 Angela
3 57 Mikhail
name age
0 Joseph 25
1 Narendra 31
2 Angela 33
3 Mikhail 57
```

{func}`~vortex.array` converts from a Pandas DataFrame into a Vortex array:
Expand Down
4 changes: 2 additions & 2 deletions docs/user-guide/pyarrow.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ Struct arrays convert to Arrow tables with {meth}`.Array.to_arrow_table`:
... ])
>>> struct_arr.to_arrow_table()
pyarrow.Table
age: int64
name: string
age: int64
----
age: [[25,31,33,57]]
name: [["Joseph","Narendra","Angela","Mikhail"]]
age: [[25,31,33,57]]
```
2 changes: 1 addition & 1 deletion docs/user-guide/vortex-python.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ A list of {class}`dict` produces a struct array. Missing values may appear at an
... None,
... ])
>>> arr.dtype
struct({"age": int(64, nullable=True), "name": utf8(nullable=True)}, nullable=True)
struct({"name": utf8(nullable=True), "age": int(64, nullable=True)}, nullable=True)
```

{func}`~vortex.array` also accepts {class}`pyarrow.Array`, {class}`pyarrow.Table`,
Expand Down
71 changes: 39 additions & 32 deletions uv.lock

Large diffs are not rendered by default.

44 changes: 22 additions & 22 deletions vortex-python/python/vortex/arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ def _Array_to_arrow_table(self: _arrays.Array) -> pyarrow.Table:
... ])
>>> array.to_arrow_table()
pyarrow.Table
age: int64
name: string
age: int64
----
age: [[25,31,33,57]]
name: [["Joseph","Narendra","Angela","Mikhail"]]
age: [[25,31,33,57]]

"""
array = self.to_arrow_array()
Expand Down Expand Up @@ -125,11 +125,11 @@ def _Array_to_pandas(self: _arrays.Array) -> pandas.DataFrame:
... {'name': 'Mikhail', 'age': 57},
... ])
>>> array.to_pandas()
age name
0 25 Joseph
1 31 Narendra
2 33 Angela
3 57 Mikhail
name age
0 Joseph 25
1 Narendra 31
2 Angela 33
3 Mikhail 57

"""
import pandas
Expand Down Expand Up @@ -172,16 +172,16 @@ def _Array_to_polars_dataframe(
... ])
>>> array.to_polars_dataframe()
shape: (4, 2)
┌───────────────┐
age ┆ name
│ --- ┆ ---
i64 ┆ str
╞═══════════════╡
25 ┆ Joseph
31 ┆ Narendra
33 ┆ Angela
57Mikhail
└───────────────┘
┌───────────────┐
name ┆ age
│ --- ┆ ---
str ┆ i64
╞═══════════════╡
Joseph ┆ 25
Narendra ┆ 31
Angela ┆ 33
Mikhail57
└───────────────┘

"""
import polars
Expand Down Expand Up @@ -245,10 +245,10 @@ def _Array_to_polars_series(self: _arrays.Array): # -> 'polars.Series': # brea
shape: (4,)
Series: '' [struct[2]]
[
{25,"Joseph"}
{31,"Narendra"}
{33,"Angela"}
{57,"Mikhail"}
{"Joseph",25}
{"Narendra",31}
{"Angela",33}
{"Mikhail",57}
]

"""
Expand Down Expand Up @@ -307,7 +307,7 @@ def _Array_to_pylist(self: _arrays.Array) -> list[Any]: # pyright: ignore[repor
... {'name': 'Angela', 'age': 33},
... ])
>>> array.to_pylist()
[{'age': 25, 'name': 'Joseph'}, {'age': 31, 'name': 'Narendra'}, {'age': 33, 'name': 'Angela'}]
[{'name': 'Joseph', 'age': 25}, {'name': 'Narendra', 'age': 31}, {'name': 'Angela', 'age': 33}]

"""
return self.to_arrow_table().to_pylist()
Expand Down
24 changes: 12 additions & 12 deletions vortex-python/python/vortex/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,20 @@ def scan(
>>> vxf.scan().read_all().to_arrow_array()
<pyarrow.lib.StructArray object at ...>
-- is_valid: all not null
-- child 0 type: int64
-- child 0 type: string_view
[
25,
31,
"Joseph",
null,
57,
"Angela",
"Mikhail",
null
]
-- child 1 type: string_view
-- child 1 type: int64
[
"Joseph",
25,
31,
null,
"Angela",
"Mikhail",
57,
null
]

Expand All @@ -158,13 +158,13 @@ def scan(
>>> vxf.scan(expr=ve.column("age") > 35).read_all().to_arrow_array()
<pyarrow.lib.StructArray object at ...>
-- is_valid: all not null
-- child 0 type: int64
-- child 0 type: string_view
[
57
"Mikhail"
]
-- child 1 type: string_view
-- child 1 type: int64
[
"Mikhail"
57
]
"""
return self._file.scan(projection, expr=expr, limit=limit, indices=indices, batch_size=batch_size)
Expand Down
12 changes: 6 additions & 6 deletions vortex-python/python/vortex/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ def execute(
>>> scan.execute(row_range=(1, 3)).read_all().to_arrow_array()
<pyarrow.lib.StructArray object at ...>
-- is_valid: all not null
-- child 0 type: int64
[
31,
null
]
-- child 1 type: string_view
-- child 0 type: string_view
[
null,
"Angela"
]
-- child 1 type: int64
[
31,
null
]
"""
if row_range is None:
start, stop = None, None
Expand Down
2 changes: 1 addition & 1 deletion vortex-python/src/arrays/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ impl PyArray {
/// ... {'name': 'Mikhail', 'age': 57},
/// ... ])
/// >>> array.scalar_at(2).as_py()
/// {'age': 33, 'name': 'Angela'}
/// {'name': 'Angela', 'age': 33}
/// ```
///
/// Retrieve a missing element from an array of structures:
Expand Down
10 changes: 5 additions & 5 deletions vortex-python/test/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ def ds(tmpdir_factory) -> vx.dataset.VortexDataset: # pyright: ignore[reportUnk

def test_schema(ds: pd.Dataset):
assert ds.schema == pa.schema(
[("bool", pa.bool_()), ("float", pa.float64()), ("index", pa.int64()), ("string", pa.string_view())]
[("index", pa.int64()), ("string", pa.string_view()), ("bool", pa.bool_()), ("float", pa.float64())]
)


def test_scanner_schema(ds: vx.dataset.VortexDataset):
scanner = vx.dataset.VortexScanner(ds)
assert scanner.schema == pa.schema(
[("bool", pa.bool_()), ("float", pa.float64()), ("index", pa.int64()), ("string", pa.string_view())]
[("index", pa.int64()), ("string", pa.string_view()), ("bool", pa.bool_()), ("float", pa.float64())]
)


Expand Down Expand Up @@ -197,13 +197,13 @@ def test_duckdb(ds: vx.dataset.VortexDataset):
tbl = duckdb.execute("select * from ds where string >= '950000' and float < 975.0").arrow().read_all()
assert len(tbl) == 6176
assert tbl.schema == pa.schema(
[("bool", pa.bool_()), ("float", pa.float64()), ("index", pa.int64()), ("string", pa.utf8())]
[("index", pa.int64()), ("string", pa.utf8()), ("bool", pa.bool_()), ("float", pa.float64())]
)

tbl = duckdb.execute("select * from ds").arrow().read_all()
assert len(tbl) == 1_000_000
assert tbl.schema == pa.schema(
[("bool", pa.bool_()), ("float", pa.float64()), ("index", pa.int64()), ("string", pa.utf8())]
[("index", pa.int64()), ("string", pa.utf8()), ("bool", pa.bool_()), ("float", pa.float64())]
)
assert tbl.take([0]).to_pylist()[0] == record(0)
assert tbl.take([950_000]).to_pylist()[0] == record(950_000)
Expand All @@ -217,7 +217,7 @@ def test_fragment_schema(ds: vx.dataset.VortexDataset):
fragments = ds.get_fragments()
for i, f in enumerate(fragments):
assert f.physical_schema == pa.schema(
[("bool", pa.bool_()), ("float", pa.float64()), ("index", pa.int64()), ("string", pa.string_view())]
[("index", pa.int64()), ("string", pa.string_view()), ("bool", pa.bool_()), ("float", pa.float64())]
), (f, i)

assert ds.head(1).to_pylist() == [{"index": 0, "string": "0", "bool": True, "float": 0.0}]
Expand Down
2 changes: 1 addition & 1 deletion vortex-python/test/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def vxf(tmpdir_factory) -> vx.VortexFile: # pyright: ignore[reportUnknownParame

def test_dtype(vxf: VortexFile):
assert vxf.dtype.to_arrow_schema() == pa.schema(
[("bool", pa.bool_()), ("float", pa.float64()), ("index", pa.int64()), ("string", pa.string_view())]
[("index", pa.int64()), ("string", pa.string_view()), ("bool", pa.bool_()), ("float", pa.float64())]
)


Expand Down
2 changes: 1 addition & 1 deletion vortex-python/test/test_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ def test_scanner_property_projected(vxfile: vx.VortexFile):

def test_scanner_property_dataset_schema(vxfile: vx.VortexFile):
assert vxfile.to_dataset().scanner().dataset_schema == pa.schema(
[("bool", pa.bool_()), ("float", pa.float64()), ("index", pa.int64()), ("string", pa.string_view())]
[("index", pa.int64()), ("string", pa.string_view()), ("bool", pa.bool_()), ("float", pa.float64())]
)
Loading