Skip to main content

Operations research on tidy dataframes — a backend-agnostic dataframe façade over Google OR-Tools.

Project description

ortidy

CI PyPI Python Docs Binder License Code style: ruff

OR (operations research) on tidy dataframes — a backend-agnostic dataframe façade over Google OR-Tools.

ortidy is the revival of pandas-or, rebuilt around Narwhals so it works natively with pandas, Polars, and more — pandas in, pandas out; Polars in, Polars out. pandas-or users: see Migrating.

The thesis: bridge operations research and the data ecosystem so solver outputs come back as tidy dataframes ready for analysis, plotting, and dashboards.

Installation

pip install ortidy

ortidy brings its own OR-Tools. Bring your own dataframe backend (pandas, polars, …) — install whichever you already use.

Quickstart

Every solver accepts a native frame, returns the same backend, and hands back a SolveResult carrying the result frame, a status, the objective, and solve metadata.

import pandas as pd
import ortidy

items = pd.DataFrame({"value": [60, 100, 120], "weight": [10, 20, 30]})

result = ortidy.knapsack(items, capacity=50)
print(result.status)        # SolveStatus.OPTIMAL
print(result.objective)     # 220
print(result.frame)         # items + an `isIncluded` boolean column

Every solver is a plain function — pass a native frame (pandas, Polars, …) and get a SolveResult back in the same backend.

Result contract

Three result shapes cover every solver:

Shape Solvers Result
assignment-matrix knapsack, multi_knapsack, bin_packing rows mapped to bins/resources
edge-flow solve_routing (more in progress) values on an edge list
interval-schedule scheduling (roadmap) intervals on a timeline

Every solver returns a SolveResult:

result.frame       # native dataframe, same backend as the input
result.status      # OPTIMAL / FEASIBLE / INFEASIBLE / UNBOUNDED / MODEL_INVALID
result.objective   # objective value (None when no solution)
result.metadata    # solver name, wall time, bounds, …
bool(result)       # True when OPTIMAL or FEASIBLE — a FEASIBLE solution is a success

Solvers

Shape Function Problem
assignment-matrix knapsack 0/1 & multidimensional knapsack
assignment-matrix multi_knapsack multiple knapsack
assignment-matrix bin_packing bin packing (minimize bins)
assignment-matrix assignment linear assignment
assignment-matrix generalized_assignment GAP (capacity-limited agents)
assignment-matrix facility_location uncapacitated facility location
assignment-matrix set_cover set cover / partition
edge-flow max_flow / min_cost_flow / shortest_path network flow
edge-flow transportation transportation problem
edge-flow solve_routing (+ distance_matrix) vehicle routing (TSP/VRP/CVRP/VRPTW/pickups)
interval-schedule shift_scheduling employee rostering
interval-schedule job_shop job-shop scheduling

See the docs for a worked example of each.

Sample datasets ship with the package:

from ortidy import data
items = data.items_knapsack()            # pandas by default
items = data.items_knapsack("polars")    # or Polars

Examples

Runnable notebooks live in examples/ — knapsack/bin-packing, a haversine world-tour TSP, and capacitated vehicle routing, each plotted with Plotly. Try them in your browser with no install: Binder

Migrating from pandas-or

ortidy is pandas-or renamed and rebuilt. Install ortidy and import ortidy (the old pandas-or 0.1.3 on PyPI is unmaintained). The key changes:

  • Solvers return a SolveResult object, not a bare frame / None.
  • Rows are identified by explicit id columns, never a positional index.
  • The backend is whatever you pass in (pandas, Polars, …), not just pandas.

License

Apache-2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ortidy-0.3.0.tar.gz (235.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ortidy-0.3.0-py3-none-any.whl (43.1 kB view details)

Uploaded Python 3

File details

Details for the file ortidy-0.3.0.tar.gz.

File metadata

  • Download URL: ortidy-0.3.0.tar.gz
  • Upload date:
  • Size: 235.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for ortidy-0.3.0.tar.gz
Algorithm Hash digest
SHA256 659fd2c96b6bb694b3ce318973254e79c1e45b3e8f1f37762e07cac33a8f0f03
MD5 86b3aded06ca460f3cf1a5bc24e439f1
BLAKE2b-256 0b217ad04e6f9e8686b4416233fcbeddae85b072d22c4f602781385e876c08cb

See more details on using hashes here.

File details

Details for the file ortidy-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: ortidy-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 43.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for ortidy-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fc751dcec800b0c30f76a87d851b7ac96e0d86beb79a77683a22383f5f4f36d1
MD5 bb0a78ffe0f08f688582f9dc79e91c76
BLAKE2b-256 9b6e67687fe686300a54e22810e81602d2a776ba928b6f08ee7487715e50f294

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page