{"id":16924850,"url":"https://github.com/apcamargo/polars-pairing","last_synced_at":"2025-09-05T23:42:29.173Z","repository":{"id":249214249,"uuid":"830396603","full_name":"apcamargo/polars-pairing","owner":"apcamargo","description":"Plugin that provides pairing functions to the Polars library","archived":false,"fork":false,"pushed_at":"2024-08-03T03:00:23.000Z","size":619,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-30T08:32:00.858Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://apcamargo.github.io/polars-pairing","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apcamargo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-18T07:37:48.000Z","updated_at":"2024-11-22T13:13:44.000Z","dependencies_parsed_at":"2024-10-28T13:17:14.657Z","dependency_job_id":"06d36419-c593-4aa9-bb6b-e9a2fc47a06e","html_url":"https://github.com/apcamargo/polars-pairing","commit_stats":null,"previous_names":["apcamargo/polars-pairing"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apcamargo%2Fpolars-pairing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apcamargo%2Fpolars-pairing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apcamargo%2Fpolars-pairing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apcamargo%2Fpolars-pairing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apcamargo","download_url":"https://codeload.github.com/apcamargo/polars-pairing/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232761418,"owners_count":18572742,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T20:07:13.926Z","updated_at":"2025-01-06T17:44:29.915Z","avatar_url":"https://github.com/apcamargo.png","language":"Python","funding_links":[],"categories":["Libraries/Packages/Scripts"],"sub_categories":["Polars plugins"],"readme":"# polars-pairing\n\nThis plugin provides pairing functions to Polars. These functions encode a pair of natural numbers into a single natural number.\n\n## Installation\n\n```bash\npip install polars-pairing\n```\n\n## Functionality and usage\n\nThis plugin implements three pairing functions (Hagen[^1], Szudzik[^2], and Cantor[^3]), along with their corresponding unpairing functions, as Polars expressions. The pairing functions take two integer columns as input and produce a single column containing the encoded pair. Conversely, the unpairing functions accept a single column as input and generate a struct column containing the values of the original pair.\n\n```python\n\u003e\u003e\u003e import polars as pl\n\u003e\u003e\u003e import polars_pairing as plp\n\n\u003e\u003e\u003e df = pl.DataFrame({\n...     \"a\": [1, 2, 38, 4],\n...     \"b\": [5, 6, 77, 80]\n... })\n\u003e\u003e\u003e df.select(plp.col(\"a\").pairing.pair(plp.col(\"b\")).alias(\"pair\"))\nshape: (4, 1)\n┌──────┐\n│ pair │\n│ ---  │\n│ u64  │\n╞══════╡\n│ 28   │\n│ 40   │\n│ 6006 │\n│ 6408 │\n└──────┘\n\n# By default, the Hagen pairing function is used, but you can specify alternative functions:\n\u003e\u003e\u003e df.select(\n...     plp.col(\"a\").pairing.pair(plp.col(\"b\"), method=\"hagen\").alias(\"hagen_pair\"),\n...     plp.col(\"a\").pairing.pair(plp.col(\"b\"), method=\"szudzik\").alias(\"szudzik_pair\"),\n...     plp.col(\"a\").pairing.pair(plp.col(\"b\"), method=\"cantor\").alias(\"cantor_pair\")\n... )\nshape: (4, 3)\n┌────────────┬──────────────┬─────────────┐\n│ hagen_pair ┆ szudzik_pair ┆ cantor_pair │\n│ ---        ┆ ---          ┆ ---         │\n│ u64        ┆ u64          ┆ u64         │\n╞════════════╪══════════════╪═════════════╡\n│ 28         ┆ 26           ┆ 26          │\n│ 40         ┆ 38           ┆ 42          │\n│ 6006       ┆ 5967         ┆ 6747        │\n│ 6408       ┆ 6404         ┆ 3650        │\n└────────────┴──────────────┴─────────────┘\n\n# The corresponding unpairing functions are also available:\n\u003e\u003e\u003e df = pl.DataFrame({\"p\": [28, 40, 6006, 6408]})\n\u003e\u003e\u003e df.select(plp.col(\"p\").pairing.unpair().alias(\"unpair\"))\nshape: (4, 1)\n┌───────────┐\n│ unpair    │\n│ ---       │\n│ struct[2] │\n╞═══════════╡\n│ {1,5}     │\n│ {2,6}     │\n│ {38,77}   │\n│ {4,80}    │\n└───────────┘\n\n\u003e\u003e\u003e df = pl.DataFrame({\"p\": [26, 38, 5967, 6404]})\n\u003e\u003e\u003e df.select(\n...     plp.col(\"p\").pairing.unpair(method=\"szudzik\").alias(\"unpair\")\n... ).unnest(\"unpair\")\nshape: (4, 2)\n┌──────┬───────┐\n│ Left ┆ Right │\n│ ---  ┆ ---   │\n│ u64  ┆ u64   │\n╞══════╪═══════╡\n│ 1    ┆ 5     │\n│ 2    ┆ 6     │\n│ 38   ┆ 77    │\n│ 4    ┆ 80    │\n└──────┴───────┘\n```\n\n[^1]: Hagen, D. R. Superior Pairing Function. \u003chttps://drhagen.com/blog/superior-pairing-function/\u003e (2018).\n[^2]: Szudzik, Matthew. \"An elegant pairing function.\" *Wolfram Research (ed.) Special NKS 2006 Wolfram Science Conference*. 2006.\n[^3]: Cantor, G. Ein Beitrag zur Mannigfaltigkeitslehre. *Journal für die reine und angewandte Mathematik* **1878**, 242–258 (1878).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapcamargo%2Fpolars-pairing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapcamargo%2Fpolars-pairing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapcamargo%2Fpolars-pairing/lists"}