σμimplied vol · KKmax(S−K,0)udβρᵢⱼfat tailsPnL · drawdownyield · TdSₜ = μSₜ dt + σSₜ dWₜC = S·N(d₁) − K·e⁻ʳᵀ·N(d₂)σₚ² = wᵀΣwd₁ = [ln(S/K) + (r + σ²⁄2)T] ⁄ σ√T∂V/∂t + ½σ²S²·∂²V/∂S² + rS·∂V/∂S − rV = 0Sharpe = (Rₚ − R_f) ⁄ σₚVaR₉₉ = μ − 2.33σρ = Cov(X,Y) ⁄ σₓσᵧE[Rₚ] = Σ wᵢ·E[Rᵢ]φ(x) = e^(−x²/2) ⁄ √2πE[Rᵢ] = R_f + βᵢ(E[Rₘ] − R_f)dXₜ = θ(μ − Xₜ)dt + σ dWₜσ²ₜ = ω + α·ε²ₜ₋₁ + β·σ²ₜ₋₁C − P = S − K·e⁻ʳᵀΔ = ∂V/∂S Γ = ∂²V/∂S²p = (e^(rΔt) − d) ⁄ (u − d)rₜ = ln(Pₜ ⁄ Pₜ₋₁)E[Xₜ₊₁ | ℱₜ] = Xₜf* = (bp − q) ⁄ bz = (x − μ) ⁄ σP(N=k) = λᵏe^(−λ) ⁄ k!Θ = −∂V/∂Tν = S·φ(d₁)·√Tmin wᵀΣw s.t. wᵀμ = μ*∫Σ∂∞λ
uantCraft AcademyRoadmapsSkills
Ctrl K
AO
+1.2k Learners
LoginJoin ↗
RoadmapsSkills
AO
+1.2k Learners
Login
  • English
  • Français
  • Español
  • العربية
  • Português
  • Deutsch
  • 日本語
  • 中文
σμimplied vol · KKmax(S−K,0)udβρᵢⱼfat tailsPnL · drawdownyield · TdSₜ = μSₜ dt + σSₜ dWₜC = S·N(d₁) − K·e⁻ʳᵀ·N(d₂)σₚ² = wᵀΣwd₁ = [ln(S/K) + (r + σ²⁄2)T] ⁄ σ√T∂V/∂t + ½σ²S²·∂²V/∂S² + rS·∂V/∂S − rV = 0Sharpe = (Rₚ − R_f) ⁄ σₚVaR₉₉ = μ − 2.33σρ = Cov(X,Y) ⁄ σₓσᵧE[Rₚ] = Σ wᵢ·E[Rᵢ]φ(x) = e^(−x²/2) ⁄ √2πE[Rᵢ] = R_f + βᵢ(E[Rₘ] − R_f)dXₜ = θ(μ − Xₜ)dt + σ dWₜσ²ₜ = ω + α·ε²ₜ₋₁ + β·σ²ₜ₋₁C − P = S − K·e⁻ʳᵀΔ = ∂V/∂S Γ = ∂²V/∂S²p = (e^(rΔt) − d) ⁄ (u − d)rₜ = ln(Pₜ ⁄ Pₜ₋₁)E[Xₜ₊₁ | ℱₜ] = Xₜf* = (bp − q) ⁄ bz = (x − μ) ⁄ σP(N=k) = λᵏe^(−λ) ⁄ k!Θ = −∂V/∂Tν = S·φ(d₁)·√Tmin wᵀΣw s.t. wᵀμ = μ*∫Σ∂∞λ
uantCraft AcademyRoadmapsSkills
Ctrl K
AO
+1.2k Learners
LoginJoin ↗
RoadmapsSkills
AO
+1.2k Learners
Login
  • English
  • Français
  • Español
  • العربية
  • Português
  • Deutsch
  • 日本語
  • 中文
Apache Arrow skill›Module 1 · Arrays, tables and kernels›Topic 1.1·~45 minIntermediate

The columnar in-memory format

Skill positionModule 1 of 3 · Topic 1 of 3
1.1 The columnar in-memory format
—Lab score— / 100Total XP—Streak—
Lecture0% read

3 min readCode examples: 2

  1. 01The idea in plain words
  2. 02A table is columns
  3. 03Weigh the arrays
  4. 04What the tasks ask

pandas, Polars, DuckDB, Spark and PyArrow all store tables differently inside, and every time data crosses from one to another it is converted. Arrow is an agreement about one layout that all of them can use, so a table built by one can be read by another with no conversion at all. This topic looks at that layout itself.

01

The idea in plain words

Where we are. The first topic of the Arrow skill. The Parquet skill covered the file format on disk; Arrow is the matching format in memory, and PyArrow is what reads Parquet into it. The next topics build on this one: tables and batches, computing on columns, the buffers underneath, and sharing the memory between libraries.

DefinitionArrow array

A block of values of one type stored back to back in memory, with a count of nulls. A table is a set of named arrays of equal length, so a row is not an object but the same position read from every column.

02

A table is columns

column_info reads the schema: each column's name, type and null count. Every value in a column has the same type, so Arrow can store the values of a double column as raw 8-byte numbers in a row. rows_head shows the price of that design: to see row 1 it reads position 1 of every column and glues the pieces together, the opposite of a row store.

main.pyPython
# The schema of the bars table, and the first two rows read across the columnsfor name, type_text, nulls in column_info(table):    print(f"{name:7} {type_text:12} nulls: {nulls}")print(rows_head(table, 2))
symbol  string       nulls: 0
date    date32[day]  nulls: 0
open    double       nulls: 0
high    double       nulls: 0
low     double       nulls: 0
close   double       nulls: 0
volume  int64        nulls: 0
[('AAPL', datetime.date(2000, 1, 3), 0.785568, 0.842382, 0.761624, 0.83826, 638640787), ('AAPL', datetime.date(2000, 1, 4), 0.810884, 0.828742, 0.758094, 0.76771, 610726329)]
main.pyPython
# One column is an array: ask for a slice of the closes, then count its bytesprint(column_slice(table, "close", 0, 5))sizes = column_nbytes(table)print(sizes)print("close:", table.num_rows, "values x 8 bytes =", table.num_rows * 8, "bytes; arrays say", sizes["close"])
[0.83826, 0.76771, 0.778895, 0.711585, 0.745631]
{'symbol': 234451, 'date': 133972, 'open': 267944, 'high': 267944, 'low': 267944, 'close': 267944, 'volume': 267944}
close: 33493 values x 8 bytes = 267944 bytes; arrays say 267944
03

Weigh the arrays

Because the layout is so plain you can predict the size. 33,493 doubles at 8 bytes each are 267,944 bytes, exactly what the close array occupies. A date32 takes 4 bytes. A string column needs more than its text: an offsets array that says where each string starts, covered in topic 4. A column with nulls adds a validity bitmap, one bit per value.

Think in columns

Reaching for rows, for row in table, is the habit that makes Arrow code slow: it undoes the layout one value at a time. Ask for the whole column and let a kernel work on it (topic 3). Use rows_head-style row reads only for small displays and tests.

04

What the tasks ask

  1. 1
    `column_info`Loop table.schema; for each field return (field.name, str(field.type), table[field.name].null_count).
  2. 2
    `rows_head` and `column_slice`table[name].slice(offset, length).to_pylist(); for rows, zip the per-column lists.
  3. 3
    `column_nbytes`{name: table[name].nbytes for name in table.column_names}.

Key takeaways

  • Columns, not rows A table is arrays of one type each; a row is a position read across them.
  • Sizes are predictable Values times width, plus offsets for strings and a bitmap for nulls.
  • Agree on the layout, skip the conversion That agreement is Arrow's purpose. Next: tables and record batches.
Quick check
Why can Arrow predict that 33,493 double values take 267,944 bytes?
Pick an answer.

Lab · what's graded

4 tasks · 100 pts
  • Describe the columns: column_info25 pts
  • Read across the columns: rows_head25 pts
  • Slice one column: column_slice25 pts
  • Weigh the columns: column_nbytes25 pts
Explorer · lab-1-1
▾ lab-1-1
▾ data
…
bash · in-browser
learner@quantcraft:~/lab-1-1$
Python not loaded yetPythonLn 1, Col 1Spaces: 4UTF-8

Reset this topic?

Everything in lab-1-1 goes back to the starter files and the terminal is cleared. Your current solution will be lost — this can't be undone.

Will be reset
  • main.py → starter code
  • Terminal history and test output
  • Unsubmitted changes
Will be kept
  • Best lab score
  • Your XP and streak
  • Lecture progress and notes