Skip to main content

set_backend

set_backend(backend)

Choose the DataFrame library pyorbiter returns.

Sets the default kind of DataFrame for the functions that create one from a system: simulate_system and get_bodies. Both also take a backend argument that overrides the default for a single call. The setting lasts for the rest of the Python session.

Functions that are given a DataFrame (the analysis functions, continue_simulation) ignore this setting and return the same kind they were given. A polars LazyFrame is collected, and a polars DataFrame comes back.

Parameters

Name Type Description Default
backend str "pandas" or "polars". pyorbiter starts with "pandas". required

Returns

Name Type Description
None Called for its side effect.

Raises

Name Type Description
ValueError If backend is not "pandas" or "polars".
ImportError If backend is "polars" and polars is not installed. The default is left unchanged. Install it with pip install polars.

See Also

Examples

Switch to polars, simulate, and switch back.

import pyorbiter as orb

orb.set_backend("polars")
sim = orb.create_system().add_sun().add_planet("Earth", parent="Sun").simulate(
    time_step=orb.seconds_per_day, duration=30 * orb.seconds_per_day)

orb.set_backend("pandas")
sim.head()
shape: (5, 9)
id mass x y z vx vy vz time
str f64 f64 f64 f64 f64 f64 f64 f64
"Sun" 1.9890e30 0.0 0.0 0.0 0.0 0.0 0.0 0.0
"Earth" 5.9720e24 -3.2966e10 1.4336e11 0.0 -29520.187051 -6788.143346 0.0 0.0
"Sun" 1.9890e30 -15.407455 67.003734 0.0 -0.00037 0.001548 0.0 86400.0
"Earth" 5.9720e24 -3.5511e10 1.4275e11 0.0 -29396.816453 -7303.615723 0.0 86400.0
"Sun" 1.9890e30 -64.008909 267.444796 0.0 -0.000768 0.003089 0.0 172800.0