ashlr-plugin 1.36.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/plugins/marketplace.json +20 -0
- package/.claude-plugin/marketplace.json +39 -0
- package/.claude-plugin/plugin.json +36 -0
- package/.codex/agents/README.md +9 -0
- package/.codex/agents/ashlr-explorer.md +36 -0
- package/.codex/agents/ashlr-worker.md +38 -0
- package/.codex-plugin/plugin.json +45 -0
- package/.mcp.json +14 -0
- package/LICENSE +21 -0
- package/README.md +311 -0
- package/agents/ashlr-code.md +69 -0
- package/agents/ashlr-explore.md +44 -0
- package/agents/ashlr-plan.md +54 -0
- package/bench/fixtures/notebook-large.ipynb +660 -0
- package/bench/fixtures/notebook-small.ipynb +39 -0
- package/bench/fixtures/tasklist-closed.json +62 -0
- package/bench/fixtures/tasklist-large-mixed.json +27 -0
- package/bench/fixtures/tasklist-sprint-open.json +79 -0
- package/bench/fixtures/websearch-bun-runtime.json +32 -0
- package/bench/fixtures/websearch-react-hooks-patterns.json +32 -0
- package/bench/fixtures/websearch-typescript-generics.json +38 -0
- package/bench/refs/node-sdk/.refrev +1 -0
- package/bench/refs/node-sdk/README.md +17 -0
- package/bench/refs/node-sdk/src/agent/agent.ts +163 -0
- package/bench/refs/node-sdk/src/agent/create-agent-ui-stream.ts +83 -0
- package/bench/refs/node-sdk/src/agent/tool-loop-agent.ts +238 -0
- package/bench/refs/node-sdk/src/embed/embed-many.ts +409 -0
- package/bench/refs/node-sdk/src/embed/embed-result.ts +50 -0
- package/bench/refs/node-sdk/src/embed/embed.ts +257 -0
- package/bench/refs/node-sdk/src/error/invalid-argument-error.ts +34 -0
- package/bench/refs/node-sdk/src/error/invalid-tool-input-error.ts +33 -0
- package/bench/refs/node-sdk/src/error/no-object-generated-error.ts +70 -0
- package/bench/refs/node-sdk/src/generate-image/generate-image-result.ts +42 -0
- package/bench/refs/node-sdk/src/generate-image/generate-image.ts +362 -0
- package/bench/refs/node-sdk/src/generate-object/generate-object-result.ts +67 -0
- package/bench/refs/node-sdk/src/generate-object/generate-object.ts +501 -0
- package/bench/refs/node-sdk/src/generate-object/inject-json-instruction.ts +30 -0
- package/bench/refs/node-sdk/src/generate-object/output-strategy.ts +415 -0
- package/bench/refs/node-sdk/src/generate-object/repair-text.ts +12 -0
- package/bench/refs/node-sdk/src/generate-object/stream-object.ts +960 -0
- package/bench/refs/node-sdk/src/generate-speech/generate-speech.ts +191 -0
- package/bench/refs/node-sdk/src/generate-text/generate-text.ts +1484 -0
- package/bench/refs/node-sdk/src/generate-text/stream-text.ts +2708 -0
- package/bench/refs/node-sdk/src/generate-text/tool-call.ts +59 -0
- package/bench/refs/node-sdk/src/generate-text/tool-result.ts +36 -0
- package/bench/refs/node-sdk/src/telemetry/create-telemetry-dispatcher.ts +146 -0
- package/bench/refs/node-sdk/src/telemetry/telemetry-registry.ts +15 -0
- package/bench/refs/node-sdk/src/telemetry/telemetry.ts +223 -0
- package/bench/refs/node-sdk/src/util/async-iterable-stream.ts +94 -0
- package/bench/refs/node-sdk/src/util/consume-stream.ts +31 -0
- package/bench/refs/node-sdk/src/util/create-stitchable-stream.ts +112 -0
- package/bench/refs/node-sdk/src/util/download/download.ts +74 -0
- package/bench/refs/node-sdk/src/util/error-handler.ts +1 -0
- package/bench/refs/node-sdk/src/util/fix-json.ts +401 -0
- package/bench/refs/node-sdk/src/util/merge-objects.ts +79 -0
- package/bench/refs/python-lib/.refrev +1 -0
- package/bench/refs/python-lib/README.md +18 -0
- package/bench/refs/python-lib/pandas/core/_numba/executor.py +249 -0
- package/bench/refs/python-lib/pandas/core/_numba/extensions.py +586 -0
- package/bench/refs/python-lib/pandas/core/_numba/kernels/mean_.py +198 -0
- package/bench/refs/python-lib/pandas/core/_numba/kernels/min_max_.py +178 -0
- package/bench/refs/python-lib/pandas/core/_numba/kernels/sum_.py +255 -0
- package/bench/refs/python-lib/pandas/core/_numba/kernels/var_.py +251 -0
- package/bench/refs/python-lib/pandas/core/accessor.py +520 -0
- package/bench/refs/python-lib/pandas/core/api.py +138 -0
- package/bench/refs/python-lib/pandas/core/array_algos/masked_accumulations.py +97 -0
- package/bench/refs/python-lib/pandas/core/array_algos/masked_reductions.py +252 -0
- package/bench/refs/python-lib/pandas/core/array_algos/putmask.py +150 -0
- package/bench/refs/python-lib/pandas/core/array_algos/quantile.py +232 -0
- package/bench/refs/python-lib/pandas/core/array_algos/replace.py +159 -0
- package/bench/refs/python-lib/pandas/core/array_algos/take.py +609 -0
- package/bench/refs/python-lib/pandas/core/arraylike.py +534 -0
- package/bench/refs/python-lib/pandas/core/arrays/_arrow_string_mixins.py +434 -0
- package/bench/refs/python-lib/pandas/core/arrays/_mixins.py +630 -0
- package/bench/refs/python-lib/pandas/core/arrays/_ranges.py +276 -0
- package/bench/refs/python-lib/pandas/core/arrays/_utils.py +77 -0
- package/bench/refs/python-lib/pandas/core/arrays/arrow/accessors.py +521 -0
- package/bench/refs/python-lib/pandas/core/arrays/arrow/extension_types.py +174 -0
- package/bench/refs/python-lib/pandas/core/arrays/boolean.py +454 -0
- package/bench/refs/python-lib/pandas/core/arrays/floating.py +192 -0
- package/bench/refs/python-lib/pandas/core/arrays/integer.py +296 -0
- package/bench/refs/python-lib/pandas/core/arrays/masked.py +2140 -0
- package/bench/refs/python-lib/pandas/core/arrays/numeric.py +305 -0
- package/bench/refs/python-lib/pandas/core/arrays/numpy_.py +701 -0
- package/bench/refs/python-lib/pandas/core/arrays/period.py +1586 -0
- package/bench/refs/python-lib/pandas/core/arrays/sparse/accessor.py +505 -0
- package/bench/refs/python-lib/pandas/core/arrays/sparse/scipy_sparse.py +208 -0
- package/bench/refs/rust-project/.refrev +1 -0
- package/bench/refs/rust-project/README.md +17 -0
- package/bench/refs/rust-project/tokio/src/doc/os.rs +68 -0
- package/bench/refs/rust-project/tokio/src/fs/dir_builder.rs +129 -0
- package/bench/refs/rust-project/tokio/src/fs/file.rs +1113 -0
- package/bench/refs/rust-project/tokio/src/fs/mocks.rs +176 -0
- package/bench/refs/rust-project/tokio/src/fs/mod.rs +324 -0
- package/bench/refs/rust-project/tokio/src/fs/open_options.rs +856 -0
- package/bench/refs/rust-project/tokio/src/fs/read.rs +80 -0
- package/bench/refs/rust-project/tokio/src/fs/read_dir.rs +357 -0
- package/bench/refs/rust-project/tokio/src/fs/write.rs +99 -0
- package/bench/refs/rust-project/tokio/src/future/maybe_done.rs +123 -0
- package/bench/refs/rust-project/tokio/src/future/try_join.rs +82 -0
- package/bench/refs/rust-project/tokio/src/io/async_buf_read.rs +117 -0
- package/bench/refs/rust-project/tokio/src/io/async_read.rs +133 -0
- package/bench/refs/rust-project/tokio/src/io/async_seek.rs +96 -0
- package/bench/refs/rust-project/tokio/src/io/async_write.rs +402 -0
- package/bench/refs/rust-project/tokio/src/io/blocking.rs +339 -0
- package/bench/refs/rust-project/tokio/src/io/interest.rs +345 -0
- package/bench/refs/rust-project/tokio/src/io/join.rs +130 -0
- package/bench/refs/rust-project/tokio/src/io/mod.rs +308 -0
- package/bench/refs/rust-project/tokio/src/io/poll_evented.rs +319 -0
- package/bench/refs/rust-project/tokio/src/io/read_buf.rs +344 -0
- package/bench/refs/rust-project/tokio/src/io/ready.rs +322 -0
- package/bench/refs/rust-project/tokio/src/io/split.rs +166 -0
- package/bench/refs/rust-project/tokio/src/io/stderr.rs +148 -0
- package/bench/refs/rust-project/tokio/src/io/stdin.rs +98 -0
- package/bench/refs/rust-project/tokio/src/io/stdio_common.rs +222 -0
- package/bench/refs/rust-project/tokio/src/io/stdout.rs +197 -0
- package/bench/refs/rust-project/tokio/src/io/util/buf_reader.rs +311 -0
- package/bench/refs/rust-project/tokio/src/io/util/buf_stream.rs +207 -0
- package/bench/refs/rust-project/tokio/src/io/util/buf_writer.rs +310 -0
- package/bench/refs/rust-project/tokio/src/io/util/chain.rs +144 -0
- package/commands/_spawn-patterns.json +32 -0
- package/commands/ashlr-allow.md +21 -0
- package/commands/ashlr-benchmark.md +53 -0
- package/commands/ashlr-brief.md +97 -0
- package/commands/ashlr-budget.md +76 -0
- package/commands/ashlr-compact.md +54 -0
- package/commands/ashlr-dashboard.md +37 -0
- package/commands/ashlr-doctor.md +56 -0
- package/commands/ashlr-eco-mode.md +92 -0
- package/commands/ashlr-genome-init.md +24 -0
- package/commands/ashlr-genome-keygen.md +36 -0
- package/commands/ashlr-genome-loop.md +118 -0
- package/commands/ashlr-genome-push.md +36 -0
- package/commands/ashlr-genome-rewrap.md +48 -0
- package/commands/ashlr-genome-team-init.md +67 -0
- package/commands/ashlr-handoff.md +23 -0
- package/commands/ashlr-help.md +86 -0
- package/commands/ashlr-hook-timings.md +30 -0
- package/commands/ashlr-leaderboard.md +50 -0
- package/commands/ashlr-ollama-setup.md +39 -0
- package/commands/ashlr-orchestrate-status.md +72 -0
- package/commands/ashlr-orchestrate.md +83 -0
- package/commands/ashlr-parallelize.md +63 -0
- package/commands/ashlr-report-crash.md +33 -0
- package/commands/ashlr-resume.md +72 -0
- package/commands/ashlr-savings.md +24 -0
- package/commands/ashlr-settings.md +50 -0
- package/commands/ashlr-spawn.md +61 -0
- package/commands/ashlr-start.md +60 -0
- package/commands/ashlr-status.md +64 -0
- package/commands/ashlr-team-invite.md +47 -0
- package/commands/ashlr-tier.md +122 -0
- package/commands/ashlr-tour.md +60 -0
- package/commands/ashlr-update.md +155 -0
- package/commands/ashlr-upgrade.md +96 -0
- package/commands/goal.md +58 -0
- package/commands/loop.md +40 -0
- package/docs/CNAME +1 -0
- package/docs/PRO_TIER.md +104 -0
- package/docs/README.md +21 -0
- package/docs/architecture.md +415 -0
- package/docs/ashlr-pipe.md +161 -0
- package/docs/assets/logo.svg +19 -0
- package/docs/assets/og.png +0 -0
- package/docs/assets/og.svg +41 -0
- package/docs/benchmarks-v2.json +355 -0
- package/docs/benchmarks.json +102 -0
- package/docs/benchmarks.md +211 -0
- package/docs/billing.md +185 -0
- package/docs/cloud-genome.md +155 -0
- package/docs/competitive-wozcode.md +92 -0
- package/docs/deploy.md +325 -0
- package/docs/email-templates.md +113 -0
- package/docs/embed-tuning.md +103 -0
- package/docs/genome.md +120 -0
- package/docs/github-oauth-onboarding.md +127 -0
- package/docs/hero-video-script.md +129 -0
- package/docs/index.html +2262 -0
- package/docs/install-prompt.md +78 -0
- package/docs/install-windows.md +132 -0
- package/docs/install.ps1 +171 -0
- package/docs/install.sh +146 -0
- package/docs/launch/README.md +114 -0
- package/docs/launch/hn.md +49 -0
- package/docs/launch/reddit.md +45 -0
- package/docs/launch/x.md +65 -0
- package/docs/launch-post.md +112 -0
- package/docs/legal.md +78 -0
- package/docs/llm-providers.md +99 -0
- package/docs/multi-host-mcp.md +217 -0
- package/docs/multi-turn-architecture.md +108 -0
- package/docs/operations/deployment.md +108 -0
- package/docs/operations/error-monitoring.md +70 -0
- package/docs/operations/weekly-digest.md +70 -0
- package/docs/operations.md +494 -0
- package/docs/platform-support.md +133 -0
- package/docs/policy-packs.md +188 -0
- package/docs/press-kit/fact-sheet.md +78 -0
- package/docs/press-kit/founder-bio.md +3 -0
- package/docs/press-kit/logo.svg +33 -0
- package/docs/press-kit/screenshots.md +146 -0
- package/docs/pricing.md +251 -0
- package/docs/pro-backend-architecture.md +523 -0
- package/docs/producthunt.md +52 -0
- package/docs/router-migration.md +110 -0
- package/docs/session-log-schema.md +68 -0
- package/docs/social.md +95 -0
- package/docs/team-genome.md +528 -0
- package/docs/telemetry.md +194 -0
- package/docs/test-isolation.md +100 -0
- package/docs/upgrade.md +159 -0
- package/hooks/_hook-errors.ts +87 -0
- package/hooks/_hook-perf-emit.ts +113 -0
- package/hooks/_hook-timing-ledger.ts +1133 -0
- package/hooks/_nudge-throttle.ts +127 -0
- package/hooks/_recent-blocks.ts +127 -0
- package/hooks/audit-upload.ts +86 -0
- package/hooks/codex-hooks.json +171 -0
- package/hooks/commit-attribution.ts +179 -0
- package/hooks/edit-batching-nudge.ts +154 -0
- package/hooks/genome-scribe-hook.ts +219 -0
- package/hooks/hooks.json +294 -0
- package/hooks/orient-nudge-hook.ts +242 -0
- package/hooks/policy-enforce.ts +214 -0
- package/hooks/post-tool-use-embedding.ts +93 -0
- package/hooks/post-tool-use-genome.sh +37 -0
- package/hooks/post-tool-use-genome.ts +69 -0
- package/hooks/posttooluse-correlate.ts +122 -0
- package/hooks/posttooluse-dedupe-output.ts +241 -0
- package/hooks/posttooluse-genome-refresh.ts +223 -0
- package/hooks/posttooluse-native-nudge.ts +205 -0
- package/hooks/posttooluse-stale-result.ts +277 -0
- package/hooks/pretooluse-bash.ts +63 -0
- package/hooks/pretooluse-budget-guard.ts +318 -0
- package/hooks/pretooluse-common.ts +985 -0
- package/hooks/pretooluse-eco-router.ts +196 -0
- package/hooks/pretooluse-edit.sh +93 -0
- package/hooks/pretooluse-edit.ts +197 -0
- package/hooks/pretooluse-glob.ts +70 -0
- package/hooks/pretooluse-grep.sh +85 -0
- package/hooks/pretooluse-grep.ts +96 -0
- package/hooks/pretooluse-notebookedit.ts +121 -0
- package/hooks/pretooluse-read.sh +118 -0
- package/hooks/pretooluse-read.ts +118 -0
- package/hooks/pretooluse-task.ts +130 -0
- package/hooks/pretooluse-webfetch.ts +66 -0
- package/hooks/pretooluse-websearch.ts +85 -0
- package/hooks/pretooluse-write.ts +128 -0
- package/hooks/pulse-emit.ts +197 -0
- package/hooks/session-end-consolidate.sh +35 -0
- package/hooks/session-end-consolidate.ts +188 -0
- package/hooks/session-end-stats-gc.ts +80 -0
- package/hooks/session-log-append.sh +94 -0
- package/hooks/session-log-append.ts +116 -0
- package/hooks/session-start.ts +993 -0
- package/hooks/sessionend-hook-health-nudge.ts +451 -0
- package/hooks/sessionend-savings-nudge.ts +318 -0
- package/hooks/sessionend-status-line-nudge.ts +296 -0
- package/hooks/sessionstart-brief.ts +140 -0
- package/hooks/sessionstart-cost-refactor.ts +95 -0
- package/hooks/sessionstart-efficient.ts +110 -0
- package/hooks/sessionstart-genome-author.ts +93 -0
- package/hooks/sessionstart-lean-tools.ts +98 -0
- package/hooks/sessionstart-search.ts +97 -0
- package/hooks/stop-accounting.ts +152 -0
- package/hooks/subagent-stop-rollup.ts +162 -0
- package/hooks/userpromptsubmit-brief-trigger.ts +156 -0
- package/package.json +56 -0
- package/ports/README.md +108 -0
- package/ports/cursor/mcp.json +11 -0
- package/ports/goose/recipe.yaml +26 -0
- package/scripts/ashlr-mcp.ts +40 -0
- package/scripts/auto-update.ts +177 -0
- package/scripts/baseline-scan.ts +831 -0
- package/scripts/bench-orchestrate.ts +377 -0
- package/scripts/benchmark-refs.ts +292 -0
- package/scripts/bootstrap.mjs +100 -0
- package/scripts/brief-eval.ts +234 -0
- package/scripts/bump-version.ts +82 -0
- package/scripts/bun-resolve.d.mts +11 -0
- package/scripts/bun-resolve.mjs +59 -0
- package/scripts/calibrate-grep.ts +467 -0
- package/scripts/capture-grep-workload.ts +260 -0
- package/scripts/check-tier.ts +61 -0
- package/scripts/check-version-sync.ts +97 -0
- package/scripts/cli-orchestrate-status.ts +386 -0
- package/scripts/cli-orchestrate.ts +303 -0
- package/scripts/cli.ts +478 -0
- package/scripts/cloud-smoke-test.ts +313 -0
- package/scripts/coach-report.ts +373 -0
- package/scripts/context-db-migrate.ts +137 -0
- package/scripts/context-status.ts +43 -0
- package/scripts/demo-run.ts +255 -0
- package/scripts/deploy-smoke.sh +140 -0
- package/scripts/doctor.ts +992 -0
- package/scripts/embed-file-worker.ts +104 -0
- package/scripts/embed-tune.ts +308 -0
- package/scripts/errors-report.ts +428 -0
- package/scripts/find-test-leak.ts +69 -0
- package/scripts/generate-badge.ts +357 -0
- package/scripts/genome-auto-consolidate.ts +533 -0
- package/scripts/genome-auto-propose.ts +578 -0
- package/scripts/genome-cloud-pull.ts +363 -0
- package/scripts/genome-cloud-push.ts +382 -0
- package/scripts/genome-cloud-sync.ts +587 -0
- package/scripts/genome-commit-watcher.ts +295 -0
- package/scripts/genome-init.ts +986 -0
- package/scripts/genome-key.ts +233 -0
- package/scripts/genome-keygen.ts +168 -0
- package/scripts/genome-link.ts +59 -0
- package/scripts/genome-refresh-worker.ts +364 -0
- package/scripts/genome-rewrap.ts +90 -0
- package/scripts/genome-synthesizer.ts +679 -0
- package/scripts/genome-team-init.ts +312 -0
- package/scripts/handoff-pack.ts +438 -0
- package/scripts/hook-bootstrap.mjs +75 -0
- package/scripts/hook-timing-reader.ts +371 -0
- package/scripts/hook-timings-report.ts +554 -0
- package/scripts/install-genome-hooks.ts +196 -0
- package/scripts/install-onnx-model.ts +154 -0
- package/scripts/install-permissions.ts +276 -0
- package/scripts/install-status-line.ts +150 -0
- package/scripts/mcp-entrypoint.sh +78 -0
- package/scripts/mcp-entrypoint.ts +130 -0
- package/scripts/mdx-angle-bracket-lint.ts +152 -0
- package/scripts/measure-cold-start.ts +126 -0
- package/scripts/migrate-stats-to-sqlite.ts +86 -0
- package/scripts/ollama-setup.ts +498 -0
- package/scripts/onboarding-wizard.ts +1691 -0
- package/scripts/orchestrate-emit-telemetry.ts +177 -0
- package/scripts/orchestrate-expand.ts +517 -0
- package/scripts/orchestrate-run.ts +744 -0
- package/scripts/print-legend.ts +50 -0
- package/scripts/product-metadata.ts +38 -0
- package/scripts/prune-old-memories.ts +208 -0
- package/scripts/publish.sh +88 -0
- package/scripts/read-calibration.ts +122 -0
- package/scripts/report-crash.ts +226 -0
- package/scripts/run-benchmark.ts +750 -0
- package/scripts/run-root-tests.ts +28 -0
- package/scripts/savings-dashboard.ts +1258 -0
- package/scripts/savings-report-extras.ts +447 -0
- package/scripts/savings-status-line.ts +873 -0
- package/scripts/session-event-emit.ts +266 -0
- package/scripts/session-greet.ts +686 -0
- package/scripts/session-log-report.ts +551 -0
- package/scripts/session-resume.ts +614 -0
- package/scripts/set-hook-mode.ts +83 -0
- package/scripts/smoke-cross-platform.ts +117 -0
- package/scripts/smoke-realtime.ts +257 -0
- package/scripts/smoke-tools.ts +21 -0
- package/scripts/stats-cloud-pull.ts +213 -0
- package/scripts/stats-cloud-sync.ts +261 -0
- package/scripts/telemetry-flush.ts +160 -0
- package/scripts/telemetry-status.ts +266 -0
- package/scripts/timing-budget.ts +35 -0
- package/scripts/ui-animation.ts +120 -0
- package/scripts/ui.ts +431 -0
- package/scripts/upgrade-flow.ts +775 -0
- package/scripts/weekly-digest.ts +394 -0
- package/servers/_accounting.ts +78 -0
- package/servers/_ask-router.ts +84 -0
- package/servers/_ast-chunker.ts +434 -0
- package/servers/_ast-helpers.ts +183 -0
- package/servers/_ast-languages.ts +153 -0
- package/servers/_ast-refactor/_shared.ts +221 -0
- package/servers/_ast-refactor/cross-file-rename.ts +560 -0
- package/servers/_ast-refactor/extract-function.ts +357 -0
- package/servers/_ast-refactor/file-local-rename.ts +172 -0
- package/servers/_ast-refactor.ts +41 -0
- package/servers/_ast-skeleton.ts +107 -0
- package/servers/_bash-summarizers-registry.ts +1096 -0
- package/servers/_crash-dump.ts +210 -0
- package/servers/_cwd-clamp.ts +342 -0
- package/servers/_edit-log.ts +28 -0
- package/servers/_edit-match.ts +236 -0
- package/servers/_edit-validate.ts +196 -0
- package/servers/_embed-calibration.ts +123 -0
- package/servers/_embedding-cache.ts +401 -0
- package/servers/_embedding-model.ts +329 -0
- package/servers/_events.ts +113 -0
- package/servers/_genome-cache.ts +154 -0
- package/servers/_genome-commits.ts +172 -0
- package/servers/_genome-crypto-v2.ts +242 -0
- package/servers/_genome-crypto.ts +259 -0
- package/servers/_genome-discoveries.ts +140 -0
- package/servers/_genome-embed-populator.ts +216 -0
- package/servers/_genome-freshness.ts +134 -0
- package/servers/_genome-issues.ts +171 -0
- package/servers/_genome-live.ts +263 -0
- package/servers/_genome-prs.ts +188 -0
- package/servers/_genome-search.ts +479 -0
- package/servers/_genome-sync.ts +297 -0
- package/servers/_history-tracker.ts +279 -0
- package/servers/_http-helpers.ts +151 -0
- package/servers/_identity-hash.ts +151 -0
- package/servers/_llm-providers/anthropic.ts +132 -0
- package/servers/_llm-providers/cloud.ts +195 -0
- package/servers/_llm-providers/index.ts +350 -0
- package/servers/_llm-providers/local.ts +127 -0
- package/servers/_llm-providers/onnx.ts +393 -0
- package/servers/_llm-providers/types.ts +27 -0
- package/servers/_manifest-v2.ts +447 -0
- package/servers/_mcp-host.ts +93 -0
- package/servers/_nudge-events.ts +451 -0
- package/servers/_orchestrate-executor.ts +316 -0
- package/servers/_prefetch.ts +435 -0
- package/servers/_pricing.ts +256 -0
- package/servers/_pro.ts +381 -0
- package/servers/_read-cache.ts +44 -0
- package/servers/_router-handlers.ts +46 -0
- package/servers/_router.ts +55 -0
- package/servers/_run-with-timeout.ts +173 -0
- package/servers/_savings-render.ts +214 -0
- package/servers/_stats-sqlite.ts +640 -0
- package/servers/_stats.ts +1183 -0
- package/servers/_status-line-cells.ts +469 -0
- package/servers/_streaks.ts +162 -0
- package/servers/_summarize.ts +208 -0
- package/servers/_task-graph-render.ts +217 -0
- package/servers/_task-graph.ts +545 -0
- package/servers/_telemetry.ts +719 -0
- package/servers/_test-parsers.ts +530 -0
- package/servers/_test-watch.ts +626 -0
- package/servers/_text-helpers.ts +37 -0
- package/servers/_token-measure.ts +160 -0
- package/servers/_tool-base.ts +248 -0
- package/servers/_weekly-digest.ts +391 -0
- package/servers/ask-server-handlers.ts +49 -0
- package/servers/ask-server.ts +174 -0
- package/servers/bash-server-handlers.ts +138 -0
- package/servers/bash-server.ts +1136 -0
- package/servers/bench.ts +186 -0
- package/servers/diff-semantic-server-handlers.ts +39 -0
- package/servers/diff-semantic-server.ts +566 -0
- package/servers/diff-server-handlers.ts +317 -0
- package/servers/diff-server.ts +20 -0
- package/servers/edit-server-handlers.ts +31 -0
- package/servers/edit-server.ts +209 -0
- package/servers/edit-structural-server-handlers.ts +322 -0
- package/servers/efficiency-server-handlers.ts +161 -0
- package/servers/efficiency-server.ts +1135 -0
- package/servers/flush-server-handlers.ts +21 -0
- package/servers/flush-server.ts +19 -0
- package/servers/genome-server-handlers.ts +118 -0
- package/servers/genome-server.ts +397 -0
- package/servers/github-server-handlers.ts +187 -0
- package/servers/github-server.ts +856 -0
- package/servers/glob-server-handlers.ts +233 -0
- package/servers/glob-server.ts +20 -0
- package/servers/grep-server-handlers.ts +61 -0
- package/servers/grep-server.ts +564 -0
- package/servers/http-server-handlers.ts +36 -0
- package/servers/http-server.ts +149 -0
- package/servers/logs-server-handlers.ts +42 -0
- package/servers/logs-server.ts +359 -0
- package/servers/ls-server-handlers.ts +166 -0
- package/servers/ls-server.ts +20 -0
- package/servers/multi-edit-server-handlers.ts +51 -0
- package/servers/multi-edit-server.ts +422 -0
- package/servers/notebook-edit-server-handlers.ts +34 -0
- package/servers/notebook-edit-server.ts +181 -0
- package/servers/orient-server-handlers.ts +52 -0
- package/servers/orient-server.ts +436 -0
- package/servers/pipe-server-handlers.ts +68 -0
- package/servers/pipe-server.ts +300 -0
- package/servers/read-server-handlers.ts +42 -0
- package/servers/read-server.ts +206 -0
- package/servers/rename-file-server-handlers.ts +67 -0
- package/servers/rename-file-server.ts +699 -0
- package/servers/savings-server-handlers.ts +27 -0
- package/servers/savings-server.ts +54 -0
- package/servers/search-replace-regex-server-handlers.ts +96 -0
- package/servers/search-replace-regex-server.ts +751 -0
- package/servers/sql-server-handlers.ts +58 -0
- package/servers/sql-server.ts +505 -0
- package/servers/task-server-handlers.ts +358 -0
- package/servers/task-server.ts +24 -0
- package/servers/test-server-handlers.ts +351 -0
- package/servers/test-server.ts +20 -0
- package/servers/tree-server-handlers.ts +503 -0
- package/servers/tree-server.ts +20 -0
- package/servers/webfetch-server-handlers.ts +166 -0
- package/servers/webfetch-server.ts +20 -0
- package/servers/websearch-server-handlers.ts +215 -0
- package/servers/websearch-server.ts +19 -0
- package/servers/write-server-handlers.ts +27 -0
- package/servers/write-server.ts +97 -0
- package/skills/ashlr-brief/SKILL.md +80 -0
- package/skills/ashlr-codex-doctor/SKILL.md +21 -0
- package/skills/ashlr-codex-efficient-tools/SKILL.md +17 -0
- package/skills/ashlr-codex-genome-refresh/SKILL.md +20 -0
- package/skills/ashlr-codex-parallel-explore/SKILL.md +20 -0
- package/skills/ashlr-codex-savings/SKILL.md +17 -0
- package/skills/ashlr-cost-refactor/SKILL.md +50 -0
- package/skills/ashlr-efficient/SKILL.md +64 -0
- package/skills/ashlr-genome-author/SKILL.md +43 -0
- package/skills/ashlr-lean-tools/SKILL.md +43 -0
- package/skills/ashlr-search/SKILL.md +46 -0
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
"""Sparse accessor"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
|
|
9
|
+
from pandas.compat._optional import import_optional_dependency
|
|
10
|
+
|
|
11
|
+
from pandas.core.dtypes.cast import find_common_type
|
|
12
|
+
from pandas.core.dtypes.dtypes import SparseDtype
|
|
13
|
+
|
|
14
|
+
from pandas.core.accessor import (
|
|
15
|
+
PandasDelegate,
|
|
16
|
+
delegate_names,
|
|
17
|
+
)
|
|
18
|
+
from pandas.core.arrays.sparse.array import SparseArray
|
|
19
|
+
|
|
20
|
+
if TYPE_CHECKING:
|
|
21
|
+
from scipy.sparse import (
|
|
22
|
+
coo_matrix,
|
|
23
|
+
spmatrix,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
from pandas import (
|
|
27
|
+
DataFrame,
|
|
28
|
+
Series,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class BaseAccessor:
|
|
33
|
+
_validation_msg = "Can only use the '.sparse' accessor with Sparse data."
|
|
34
|
+
|
|
35
|
+
def __init__(self, data=None) -> None:
|
|
36
|
+
self._parent = data
|
|
37
|
+
self._validate(data)
|
|
38
|
+
|
|
39
|
+
def _validate(self, data) -> None:
|
|
40
|
+
raise NotImplementedError
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@delegate_names(
|
|
44
|
+
SparseArray, ["npoints", "density", "fill_value", "sp_values"], typ="property"
|
|
45
|
+
)
|
|
46
|
+
class SparseAccessor(BaseAccessor, PandasDelegate):
|
|
47
|
+
"""
|
|
48
|
+
Accessor for SparseArray from other sparse matrix data types.
|
|
49
|
+
|
|
50
|
+
Provides methods and properties to work with the underlying sparse data
|
|
51
|
+
in a Series or DataFrame. It allows accessing sparse-specific attributes
|
|
52
|
+
such as fill value, density, and stored non-fill values, as well as
|
|
53
|
+
converting to and from scipy sparse matrices.
|
|
54
|
+
|
|
55
|
+
Parameters
|
|
56
|
+
----------
|
|
57
|
+
data : Series or DataFrame
|
|
58
|
+
The Series or DataFrame to which the SparseAccessor is attached.
|
|
59
|
+
|
|
60
|
+
See Also
|
|
61
|
+
--------
|
|
62
|
+
Series.sparse.to_coo : Create a scipy.sparse.coo_matrix from a Series with
|
|
63
|
+
MultiIndex.
|
|
64
|
+
Series.sparse.from_coo : Create a Series with sparse values from a
|
|
65
|
+
scipy.sparse.coo_matrix.
|
|
66
|
+
|
|
67
|
+
Examples
|
|
68
|
+
--------
|
|
69
|
+
>>> ser = pd.Series([0, 0, 2, 2, 2], dtype="Sparse[int]")
|
|
70
|
+
>>> ser.sparse.density
|
|
71
|
+
0.6
|
|
72
|
+
>>> ser.sparse.sp_values
|
|
73
|
+
array([2, 2, 2])
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
def _validate(self, data) -> None:
|
|
77
|
+
if not isinstance(data.dtype, SparseDtype):
|
|
78
|
+
raise AttributeError(self._validation_msg)
|
|
79
|
+
|
|
80
|
+
def _delegate_property_get(self, name: str, *args, **kwargs):
|
|
81
|
+
return getattr(self._parent.array, name)
|
|
82
|
+
|
|
83
|
+
def _delegate_method(self, name: str, *args, **kwargs):
|
|
84
|
+
if name == "from_coo":
|
|
85
|
+
return self.from_coo(*args, **kwargs)
|
|
86
|
+
elif name == "to_coo":
|
|
87
|
+
return self.to_coo(*args, **kwargs)
|
|
88
|
+
else:
|
|
89
|
+
raise ValueError
|
|
90
|
+
|
|
91
|
+
@classmethod
|
|
92
|
+
def from_coo(cls, A, dense_index: bool = False) -> Series:
|
|
93
|
+
"""
|
|
94
|
+
Create a Series with sparse values from a scipy.sparse.coo_matrix.
|
|
95
|
+
|
|
96
|
+
This method takes a ``scipy.sparse.coo_matrix`` (coordinate format) as input and
|
|
97
|
+
returns a pandas ``Series`` where the non-zero elements are represented as
|
|
98
|
+
sparse values. The index of the Series can either include only the coordinates
|
|
99
|
+
of non-zero elements (default behavior) or the full sorted set of coordinates
|
|
100
|
+
from the matrix if ``dense_index`` is set to `True`.
|
|
101
|
+
|
|
102
|
+
Parameters
|
|
103
|
+
----------
|
|
104
|
+
A : scipy.sparse.coo_matrix
|
|
105
|
+
The sparse matrix in coordinate format from which the sparse Series
|
|
106
|
+
will be created.
|
|
107
|
+
dense_index : bool, default False
|
|
108
|
+
If False (default), the index consists of only the
|
|
109
|
+
coords of the non-null entries of the original coo_matrix.
|
|
110
|
+
If True, the index consists of the full sorted
|
|
111
|
+
(row, col) coordinates of the coo_matrix.
|
|
112
|
+
|
|
113
|
+
Returns
|
|
114
|
+
-------
|
|
115
|
+
s : Series
|
|
116
|
+
A Series with sparse values.
|
|
117
|
+
|
|
118
|
+
See Also
|
|
119
|
+
--------
|
|
120
|
+
DataFrame.sparse.from_spmatrix : Create a new DataFrame from a scipy sparse
|
|
121
|
+
matrix.
|
|
122
|
+
scipy.sparse.coo_matrix : A sparse matrix in COOrdinate format.
|
|
123
|
+
|
|
124
|
+
Examples
|
|
125
|
+
--------
|
|
126
|
+
>>> from scipy import sparse
|
|
127
|
+
|
|
128
|
+
>>> A = sparse.coo_matrix(
|
|
129
|
+
... ([3.0, 1.0, 2.0], ([1, 0, 0], [0, 2, 3])), shape=(3, 4)
|
|
130
|
+
... )
|
|
131
|
+
>>> A
|
|
132
|
+
<COOrdinate sparse matrix of dtype 'float64'
|
|
133
|
+
with 3 stored elements and shape (3, 4)>
|
|
134
|
+
|
|
135
|
+
>>> A.todense()
|
|
136
|
+
matrix([[0., 0., 1., 2.],
|
|
137
|
+
[3., 0., 0., 0.],
|
|
138
|
+
[0., 0., 0., 0.]])
|
|
139
|
+
|
|
140
|
+
>>> ss = pd.Series.sparse.from_coo(A)
|
|
141
|
+
>>> ss
|
|
142
|
+
0 2 1.0
|
|
143
|
+
3 2.0
|
|
144
|
+
1 0 3.0
|
|
145
|
+
dtype: Sparse[float64, nan]
|
|
146
|
+
"""
|
|
147
|
+
from pandas import Series
|
|
148
|
+
from pandas.core.arrays.sparse.scipy_sparse import coo_to_sparse_series
|
|
149
|
+
|
|
150
|
+
result = coo_to_sparse_series(A, dense_index=dense_index)
|
|
151
|
+
result = Series(result.array, index=result.index, copy=False)
|
|
152
|
+
|
|
153
|
+
return result
|
|
154
|
+
|
|
155
|
+
def to_coo(
|
|
156
|
+
self, row_levels=(0,), column_levels=(1,), sort_labels: bool = False
|
|
157
|
+
) -> tuple[coo_matrix, list, list]:
|
|
158
|
+
"""
|
|
159
|
+
Create a scipy.sparse.coo_matrix from a Series with MultiIndex.
|
|
160
|
+
|
|
161
|
+
Use row_levels and column_levels to determine the row and column
|
|
162
|
+
coordinates respectively. row_levels and column_levels are the names
|
|
163
|
+
(labels) or numbers of the levels. {row_levels, column_levels} must be
|
|
164
|
+
a partition of the MultiIndex level names (or numbers).
|
|
165
|
+
|
|
166
|
+
Parameters
|
|
167
|
+
----------
|
|
168
|
+
row_levels : tuple/list
|
|
169
|
+
MultiIndex levels to use for row coordinates, specified by name or index.
|
|
170
|
+
column_levels : tuple/list
|
|
171
|
+
MultiIndex levels to use for column coordinates, specified by name or index.
|
|
172
|
+
sort_labels : bool, default False
|
|
173
|
+
Sort the row and column labels before forming the sparse matrix.
|
|
174
|
+
When `row_levels` and/or `column_levels` refer to a single level,
|
|
175
|
+
set to `True` for a faster execution.
|
|
176
|
+
|
|
177
|
+
Returns
|
|
178
|
+
-------
|
|
179
|
+
y : scipy.sparse.coo_matrix
|
|
180
|
+
The sparse matrix in coordinate format.
|
|
181
|
+
rows : list (row labels)
|
|
182
|
+
Labels corresponding to the row coordinates.
|
|
183
|
+
columns : list (column labels)
|
|
184
|
+
Labels corresponding to the column coordinates.
|
|
185
|
+
|
|
186
|
+
See Also
|
|
187
|
+
--------
|
|
188
|
+
Series.sparse.from_coo : Create a Series with sparse values from a
|
|
189
|
+
scipy.sparse.coo_matrix.
|
|
190
|
+
|
|
191
|
+
Examples
|
|
192
|
+
--------
|
|
193
|
+
>>> s = pd.Series([3.0, np.nan, 1.0, 3.0, np.nan, np.nan])
|
|
194
|
+
>>> s.index = pd.MultiIndex.from_tuples(
|
|
195
|
+
... [
|
|
196
|
+
... (1, 2, "a", 0),
|
|
197
|
+
... (1, 2, "a", 1),
|
|
198
|
+
... (1, 1, "b", 0),
|
|
199
|
+
... (1, 1, "b", 1),
|
|
200
|
+
... (2, 1, "b", 0),
|
|
201
|
+
... (2, 1, "b", 1),
|
|
202
|
+
... ],
|
|
203
|
+
... names=["A", "B", "C", "D"],
|
|
204
|
+
... )
|
|
205
|
+
>>> s
|
|
206
|
+
A B C D
|
|
207
|
+
1 2 a 0 3.0
|
|
208
|
+
1 NaN
|
|
209
|
+
1 b 0 1.0
|
|
210
|
+
1 3.0
|
|
211
|
+
2 1 b 0 NaN
|
|
212
|
+
1 NaN
|
|
213
|
+
dtype: float64
|
|
214
|
+
|
|
215
|
+
>>> ss = s.astype("Sparse")
|
|
216
|
+
>>> ss
|
|
217
|
+
A B C D
|
|
218
|
+
1 2 a 0 3.0
|
|
219
|
+
1 NaN
|
|
220
|
+
1 b 0 1.0
|
|
221
|
+
1 3.0
|
|
222
|
+
2 1 b 0 NaN
|
|
223
|
+
1 NaN
|
|
224
|
+
dtype: Sparse[float64, nan]
|
|
225
|
+
|
|
226
|
+
>>> A, rows, columns = ss.sparse.to_coo(
|
|
227
|
+
... row_levels=["A", "B"], column_levels=["C", "D"], sort_labels=True
|
|
228
|
+
... )
|
|
229
|
+
>>> A
|
|
230
|
+
<COOrdinate sparse matrix of dtype 'float64'
|
|
231
|
+
with 3 stored elements and shape (3, 4)>
|
|
232
|
+
>>> A.todense()
|
|
233
|
+
matrix([[0., 0., 1., 3.],
|
|
234
|
+
[3., 0., 0., 0.],
|
|
235
|
+
[0., 0., 0., 0.]])
|
|
236
|
+
|
|
237
|
+
>>> rows
|
|
238
|
+
[(1, 1), (1, 2), (2, 1)]
|
|
239
|
+
>>> columns
|
|
240
|
+
[('a', 0), ('a', 1), ('b', 0), ('b', 1)]
|
|
241
|
+
"""
|
|
242
|
+
from pandas.core.arrays.sparse.scipy_sparse import sparse_series_to_coo
|
|
243
|
+
|
|
244
|
+
A, rows, columns = sparse_series_to_coo(
|
|
245
|
+
self._parent, row_levels, column_levels, sort_labels=sort_labels
|
|
246
|
+
)
|
|
247
|
+
return A, rows, columns
|
|
248
|
+
|
|
249
|
+
def to_dense(self) -> Series:
|
|
250
|
+
"""
|
|
251
|
+
Convert a Series from sparse values to dense.
|
|
252
|
+
|
|
253
|
+
Returns
|
|
254
|
+
-------
|
|
255
|
+
Series:
|
|
256
|
+
A Series with the same values, stored as a dense array.
|
|
257
|
+
|
|
258
|
+
Examples
|
|
259
|
+
--------
|
|
260
|
+
>>> series = pd.Series(pd.arrays.SparseArray([0, 1, 0]))
|
|
261
|
+
>>> series
|
|
262
|
+
0 0
|
|
263
|
+
1 1
|
|
264
|
+
2 0
|
|
265
|
+
dtype: Sparse[int64, 0]
|
|
266
|
+
|
|
267
|
+
>>> series.sparse.to_dense()
|
|
268
|
+
0 0
|
|
269
|
+
1 1
|
|
270
|
+
2 0
|
|
271
|
+
dtype: int64
|
|
272
|
+
"""
|
|
273
|
+
from pandas import Series
|
|
274
|
+
|
|
275
|
+
return Series(
|
|
276
|
+
self._parent.array.to_dense(),
|
|
277
|
+
index=self._parent.index,
|
|
278
|
+
name=self._parent.name,
|
|
279
|
+
copy=False,
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
class SparseFrameAccessor(BaseAccessor, PandasDelegate):
|
|
284
|
+
"""
|
|
285
|
+
DataFrame accessor for sparse data.
|
|
286
|
+
|
|
287
|
+
It allows users to interact with a `DataFrame` that contains sparse data types
|
|
288
|
+
(`SparseDtype`). It provides methods and attributes to efficiently work with sparse
|
|
289
|
+
storage, reducing memory usage while maintaining compatibility with standard pandas
|
|
290
|
+
operations.
|
|
291
|
+
|
|
292
|
+
Parameters
|
|
293
|
+
----------
|
|
294
|
+
data : scipy.sparse.spmatrix
|
|
295
|
+
Must be convertible to csc format.
|
|
296
|
+
|
|
297
|
+
See Also
|
|
298
|
+
--------
|
|
299
|
+
DataFrame.sparse.density : Ratio of non-sparse points to total (dense) data points.
|
|
300
|
+
|
|
301
|
+
Examples
|
|
302
|
+
--------
|
|
303
|
+
>>> df = pd.DataFrame({"a": [1, 2, 0, 0], "b": [3, 0, 0, 4]}, dtype="Sparse[int]")
|
|
304
|
+
>>> df.sparse.density
|
|
305
|
+
np.float64(0.5)
|
|
306
|
+
"""
|
|
307
|
+
|
|
308
|
+
def _validate(self, data) -> None:
|
|
309
|
+
dtypes = data.dtypes
|
|
310
|
+
if not all(isinstance(t, SparseDtype) for t in dtypes):
|
|
311
|
+
raise AttributeError(self._validation_msg)
|
|
312
|
+
|
|
313
|
+
@classmethod
|
|
314
|
+
def from_spmatrix(cls, data, index=None, columns=None) -> DataFrame:
|
|
315
|
+
"""
|
|
316
|
+
Create a new DataFrame from a scipy sparse matrix.
|
|
317
|
+
|
|
318
|
+
This method converts a scipy sparse matrix into a pandas DataFrame
|
|
319
|
+
with sparse array columns for memory efficiency.
|
|
320
|
+
|
|
321
|
+
Parameters
|
|
322
|
+
----------
|
|
323
|
+
data : scipy.sparse.spmatrix
|
|
324
|
+
Must be convertible to csc format.
|
|
325
|
+
index, columns : Index, optional
|
|
326
|
+
Row and column labels to use for the resulting DataFrame.
|
|
327
|
+
Defaults to a RangeIndex.
|
|
328
|
+
|
|
329
|
+
Returns
|
|
330
|
+
-------
|
|
331
|
+
DataFrame
|
|
332
|
+
Each column of the DataFrame is stored as a
|
|
333
|
+
:class:`arrays.SparseArray`.
|
|
334
|
+
|
|
335
|
+
See Also
|
|
336
|
+
--------
|
|
337
|
+
DataFrame.sparse.to_coo : Return the contents of the frame as a
|
|
338
|
+
sparse SciPy COO matrix.
|
|
339
|
+
|
|
340
|
+
Examples
|
|
341
|
+
--------
|
|
342
|
+
>>> import scipy.sparse
|
|
343
|
+
>>> mat = scipy.sparse.eye(3, dtype=int)
|
|
344
|
+
>>> pd.DataFrame.sparse.from_spmatrix(mat)
|
|
345
|
+
0 1 2
|
|
346
|
+
0 1 0 0
|
|
347
|
+
1 0 1 0
|
|
348
|
+
2 0 0 1
|
|
349
|
+
"""
|
|
350
|
+
from pandas._libs.sparse import IntIndex
|
|
351
|
+
|
|
352
|
+
from pandas import DataFrame
|
|
353
|
+
|
|
354
|
+
data = data.tocsc()
|
|
355
|
+
index, columns = cls._prep_index(data, index, columns)
|
|
356
|
+
n_rows, n_columns = data.shape
|
|
357
|
+
# We need to make sure indices are sorted, as we create
|
|
358
|
+
# IntIndex with no input validation (i.e. check_integrity=False ).
|
|
359
|
+
# Indices may already be sorted in scipy in which case this adds
|
|
360
|
+
# a small overhead.
|
|
361
|
+
data.sort_indices()
|
|
362
|
+
indices = data.indices
|
|
363
|
+
indptr = data.indptr
|
|
364
|
+
array_data = data.data
|
|
365
|
+
dtype = SparseDtype(array_data.dtype)
|
|
366
|
+
arrays = []
|
|
367
|
+
for i in range(n_columns):
|
|
368
|
+
sl = slice(indptr[i], indptr[i + 1])
|
|
369
|
+
idx = IntIndex(n_rows, indices[sl], check_integrity=False)
|
|
370
|
+
arr = SparseArray._simple_new(array_data[sl], idx, dtype)
|
|
371
|
+
arrays.append(arr)
|
|
372
|
+
return DataFrame._from_arrays(
|
|
373
|
+
arrays, columns=columns, index=index, verify_integrity=False
|
|
374
|
+
)
|
|
375
|
+
|
|
376
|
+
def to_dense(self) -> DataFrame:
|
|
377
|
+
"""
|
|
378
|
+
Convert a DataFrame with sparse values to dense.
|
|
379
|
+
|
|
380
|
+
This method converts all SparseArray columns in the DataFrame to
|
|
381
|
+
regular NumPy arrays.
|
|
382
|
+
|
|
383
|
+
Returns
|
|
384
|
+
-------
|
|
385
|
+
DataFrame
|
|
386
|
+
A DataFrame with the same values stored as dense arrays.
|
|
387
|
+
|
|
388
|
+
See Also
|
|
389
|
+
--------
|
|
390
|
+
DataFrame.sparse.density : Ratio of non-sparse points to total
|
|
391
|
+
(dense) data points.
|
|
392
|
+
|
|
393
|
+
Examples
|
|
394
|
+
--------
|
|
395
|
+
>>> df = pd.DataFrame({"A": pd.arrays.SparseArray([0, 1, 0])})
|
|
396
|
+
>>> df.sparse.to_dense()
|
|
397
|
+
A
|
|
398
|
+
0 0
|
|
399
|
+
1 1
|
|
400
|
+
2 0
|
|
401
|
+
"""
|
|
402
|
+
data = {k: v.array.to_dense() for k, v in self._parent.items()}
|
|
403
|
+
return self._parent._constructor(
|
|
404
|
+
data, index=self._parent.index, columns=self._parent.columns
|
|
405
|
+
)
|
|
406
|
+
|
|
407
|
+
def to_coo(self) -> spmatrix:
|
|
408
|
+
"""
|
|
409
|
+
Return the contents of the frame as a sparse SciPy COO matrix.
|
|
410
|
+
|
|
411
|
+
This method converts the DataFrame to a scipy COO (Coordinate) sparse
|
|
412
|
+
matrix format for interoperability with scipy.sparse routines.
|
|
413
|
+
|
|
414
|
+
Returns
|
|
415
|
+
-------
|
|
416
|
+
scipy.sparse.spmatrix
|
|
417
|
+
If the caller is heterogeneous and contains booleans or objects,
|
|
418
|
+
the result will be of dtype=object. See Notes.
|
|
419
|
+
|
|
420
|
+
See Also
|
|
421
|
+
--------
|
|
422
|
+
DataFrame.sparse.to_dense : Convert a DataFrame with sparse values to dense.
|
|
423
|
+
|
|
424
|
+
Notes
|
|
425
|
+
-----
|
|
426
|
+
The dtype will be the lowest-common-denominator type (implicit
|
|
427
|
+
upcasting); that is to say if the dtypes (even of numeric types)
|
|
428
|
+
are mixed, the one that accommodates all will be chosen.
|
|
429
|
+
|
|
430
|
+
e.g. If the dtypes are float16 and float32, dtype will be upcast to
|
|
431
|
+
float32. By numpy.find_common_type convention, mixing int64 and
|
|
432
|
+
and uint64 will result in a float64 dtype.
|
|
433
|
+
|
|
434
|
+
Examples
|
|
435
|
+
--------
|
|
436
|
+
>>> df = pd.DataFrame({"A": pd.arrays.SparseArray([0, 1, 0, 1])})
|
|
437
|
+
>>> df.sparse.to_coo()
|
|
438
|
+
<COOrdinate sparse matrix of dtype 'int64'
|
|
439
|
+
with 2 stored elements and shape (4, 1)>
|
|
440
|
+
"""
|
|
441
|
+
import_optional_dependency("scipy")
|
|
442
|
+
from scipy.sparse import coo_matrix
|
|
443
|
+
|
|
444
|
+
dtype = find_common_type(self._parent.dtypes.to_list())
|
|
445
|
+
if isinstance(dtype, SparseDtype):
|
|
446
|
+
dtype = dtype.subtype
|
|
447
|
+
|
|
448
|
+
cols, rows, data = [], [], []
|
|
449
|
+
for col, (_, ser) in enumerate(self._parent.items()):
|
|
450
|
+
sp_arr = ser.array
|
|
451
|
+
|
|
452
|
+
row = sp_arr.sp_index.indices
|
|
453
|
+
cols.append(np.repeat(col, len(row)))
|
|
454
|
+
rows.append(row)
|
|
455
|
+
data.append(sp_arr.sp_values.astype(dtype, copy=False))
|
|
456
|
+
|
|
457
|
+
cols_arr = np.concatenate(cols)
|
|
458
|
+
rows_arr = np.concatenate(rows)
|
|
459
|
+
data_arr = np.concatenate(data)
|
|
460
|
+
return coo_matrix((data_arr, (rows_arr, cols_arr)), shape=self._parent.shape)
|
|
461
|
+
|
|
462
|
+
@property
|
|
463
|
+
def density(self) -> float:
|
|
464
|
+
"""
|
|
465
|
+
Ratio of non-sparse points to total (dense) data points.
|
|
466
|
+
|
|
467
|
+
This property returns the proportion of the data that is not sparse
|
|
468
|
+
(i.e., not equal to the fill value), as a value between 0 and 1.
|
|
469
|
+
|
|
470
|
+
See Also
|
|
471
|
+
--------
|
|
472
|
+
DataFrame.sparse.from_spmatrix : Create a new DataFrame from a
|
|
473
|
+
scipy sparse matrix.
|
|
474
|
+
|
|
475
|
+
Examples
|
|
476
|
+
--------
|
|
477
|
+
>>> df = pd.DataFrame({"A": pd.arrays.SparseArray([0, 1, 0, 1])})
|
|
478
|
+
>>> df.sparse.density
|
|
479
|
+
np.float64(0.5)
|
|
480
|
+
"""
|
|
481
|
+
tmp = np.mean([column.array.density for _, column in self._parent.items()])
|
|
482
|
+
return tmp
|
|
483
|
+
|
|
484
|
+
@staticmethod
|
|
485
|
+
def _prep_index(data, index, columns):
|
|
486
|
+
from pandas.core.indexes.api import (
|
|
487
|
+
default_index,
|
|
488
|
+
ensure_index,
|
|
489
|
+
)
|
|
490
|
+
|
|
491
|
+
N, K = data.shape
|
|
492
|
+
if index is None:
|
|
493
|
+
index = default_index(N)
|
|
494
|
+
else:
|
|
495
|
+
index = ensure_index(index)
|
|
496
|
+
if columns is None:
|
|
497
|
+
columns = default_index(K)
|
|
498
|
+
else:
|
|
499
|
+
columns = ensure_index(columns)
|
|
500
|
+
|
|
501
|
+
if len(columns) != K:
|
|
502
|
+
raise ValueError(f"Column length mismatch: {len(columns)} vs. {K}")
|
|
503
|
+
if len(index) != N:
|
|
504
|
+
raise ValueError(f"Index length mismatch: {len(index)} vs. {N}")
|
|
505
|
+
return index, columns
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Interaction with scipy.sparse matrices.
|
|
3
|
+
|
|
4
|
+
Currently only includes to_coo helpers.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from typing import TYPE_CHECKING
|
|
10
|
+
|
|
11
|
+
from pandas._libs import lib
|
|
12
|
+
|
|
13
|
+
from pandas.core.dtypes.missing import notna
|
|
14
|
+
|
|
15
|
+
from pandas.core.algorithms import factorize
|
|
16
|
+
from pandas.core.indexes.api import MultiIndex
|
|
17
|
+
from pandas.core.series import Series
|
|
18
|
+
|
|
19
|
+
if TYPE_CHECKING:
|
|
20
|
+
from collections.abc import Iterable
|
|
21
|
+
|
|
22
|
+
import numpy as np
|
|
23
|
+
import scipy.sparse
|
|
24
|
+
|
|
25
|
+
from pandas._typing import (
|
|
26
|
+
IndexLabel,
|
|
27
|
+
npt,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _check_is_partition(parts: Iterable, whole: Iterable) -> None:
|
|
32
|
+
whole = set(whole)
|
|
33
|
+
parts = [set(x) for x in parts]
|
|
34
|
+
if set.intersection(*parts) != set():
|
|
35
|
+
raise ValueError("Is not a partition because intersection is not null.")
|
|
36
|
+
if set.union(*parts) != whole:
|
|
37
|
+
raise ValueError("Is not a partition because union is not the whole.")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _levels_to_axis(
|
|
41
|
+
ss,
|
|
42
|
+
levels: tuple[int] | list[int],
|
|
43
|
+
valid_ilocs: npt.NDArray[np.intp],
|
|
44
|
+
sort_labels: bool = False,
|
|
45
|
+
) -> tuple[npt.NDArray[np.intp], list[IndexLabel]]:
|
|
46
|
+
"""
|
|
47
|
+
For a MultiIndexed sparse Series `ss`, return `ax_coords` and `ax_labels`,
|
|
48
|
+
where `ax_coords` are the coordinates along one of the two axes of the
|
|
49
|
+
destination sparse matrix, and `ax_labels` are the labels from `ss`' Index
|
|
50
|
+
which correspond to these coordinates.
|
|
51
|
+
|
|
52
|
+
Parameters
|
|
53
|
+
----------
|
|
54
|
+
ss : Series
|
|
55
|
+
levels : tuple/list
|
|
56
|
+
valid_ilocs : numpy.ndarray
|
|
57
|
+
Array of integer positions of valid values for the sparse matrix in ss.
|
|
58
|
+
sort_labels : bool, default False
|
|
59
|
+
Sort the axis labels before forming the sparse matrix. When `levels`
|
|
60
|
+
refers to a single level, set to True for a faster execution.
|
|
61
|
+
|
|
62
|
+
Returns
|
|
63
|
+
-------
|
|
64
|
+
ax_coords : numpy.ndarray (axis coordinates)
|
|
65
|
+
ax_labels : list (axis labels)
|
|
66
|
+
"""
|
|
67
|
+
# Since the labels are sorted in `Index.levels`, when we wish to sort and
|
|
68
|
+
# there is only one level of the MultiIndex for this axis, the desired
|
|
69
|
+
# output can be obtained in the following simpler, more efficient way.
|
|
70
|
+
if sort_labels and len(levels) == 1:
|
|
71
|
+
ax_coords = ss.index.codes[levels[0]][valid_ilocs]
|
|
72
|
+
ax_labels = ss.index.levels[levels[0]]
|
|
73
|
+
|
|
74
|
+
else:
|
|
75
|
+
levels_values = lib.fast_zip(
|
|
76
|
+
[ss.index.get_level_values(lvl).to_numpy() for lvl in levels]
|
|
77
|
+
)
|
|
78
|
+
codes, ax_labels = factorize(levels_values, sort=sort_labels)
|
|
79
|
+
ax_coords = codes[valid_ilocs]
|
|
80
|
+
|
|
81
|
+
ax_labels = ax_labels.tolist()
|
|
82
|
+
return ax_coords, ax_labels # pyright: ignore[reportReturnType]
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _to_ijv(
|
|
86
|
+
ss,
|
|
87
|
+
row_levels: tuple[int] | list[int] = (0,),
|
|
88
|
+
column_levels: tuple[int] | list[int] = (1,),
|
|
89
|
+
sort_labels: bool = False,
|
|
90
|
+
) -> tuple[
|
|
91
|
+
np.ndarray,
|
|
92
|
+
npt.NDArray[np.intp],
|
|
93
|
+
npt.NDArray[np.intp],
|
|
94
|
+
list[IndexLabel],
|
|
95
|
+
list[IndexLabel],
|
|
96
|
+
]:
|
|
97
|
+
"""
|
|
98
|
+
For an arbitrary MultiIndexed sparse Series return (v, i, j, ilabels,
|
|
99
|
+
jlabels) where (v, (i, j)) is suitable for passing to scipy.sparse.coo
|
|
100
|
+
constructor, and ilabels and jlabels are the row and column labels
|
|
101
|
+
respectively.
|
|
102
|
+
|
|
103
|
+
Parameters
|
|
104
|
+
----------
|
|
105
|
+
ss : Series
|
|
106
|
+
row_levels : tuple/list
|
|
107
|
+
column_levels : tuple/list
|
|
108
|
+
sort_labels : bool, default False
|
|
109
|
+
Sort the row and column labels before forming the sparse matrix.
|
|
110
|
+
When `row_levels` and/or `column_levels` refer to a single level,
|
|
111
|
+
set to `True` for a faster execution.
|
|
112
|
+
|
|
113
|
+
Returns
|
|
114
|
+
-------
|
|
115
|
+
values : numpy.ndarray
|
|
116
|
+
Valid values to populate a sparse matrix, extracted from
|
|
117
|
+
ss.
|
|
118
|
+
i_coords : numpy.ndarray (row coordinates of the values)
|
|
119
|
+
j_coords : numpy.ndarray (column coordinates of the values)
|
|
120
|
+
i_labels : list (row labels)
|
|
121
|
+
j_labels : list (column labels)
|
|
122
|
+
"""
|
|
123
|
+
# index and column levels must be a partition of the index
|
|
124
|
+
_check_is_partition([row_levels, column_levels], range(ss.index.nlevels))
|
|
125
|
+
# From the sparse Series, get the integer indices and data for valid sparse
|
|
126
|
+
# entries.
|
|
127
|
+
sp_vals = ss.array.sp_values
|
|
128
|
+
na_mask = notna(sp_vals)
|
|
129
|
+
values = sp_vals[na_mask]
|
|
130
|
+
valid_ilocs = ss.array.sp_index.indices[na_mask]
|
|
131
|
+
|
|
132
|
+
i_coords, i_labels = _levels_to_axis(
|
|
133
|
+
ss, row_levels, valid_ilocs, sort_labels=sort_labels
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
j_coords, j_labels = _levels_to_axis(
|
|
137
|
+
ss, column_levels, valid_ilocs, sort_labels=sort_labels
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
return values, i_coords, j_coords, i_labels, j_labels
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def sparse_series_to_coo(
|
|
144
|
+
ss: Series,
|
|
145
|
+
row_levels: Iterable[int] = (0,),
|
|
146
|
+
column_levels: Iterable[int] = (1,),
|
|
147
|
+
sort_labels: bool = False,
|
|
148
|
+
) -> tuple[scipy.sparse.coo_matrix, list[IndexLabel], list[IndexLabel]]:
|
|
149
|
+
"""
|
|
150
|
+
Convert a sparse Series to a scipy.sparse.coo_matrix using index
|
|
151
|
+
levels row_levels, column_levels as the row and column
|
|
152
|
+
labels respectively. Returns the sparse_matrix, row and column labels.
|
|
153
|
+
"""
|
|
154
|
+
import scipy.sparse
|
|
155
|
+
|
|
156
|
+
if ss.index.nlevels < 2:
|
|
157
|
+
raise ValueError("to_coo requires MultiIndex with nlevels >= 2.")
|
|
158
|
+
if not ss.index.is_unique:
|
|
159
|
+
raise ValueError(
|
|
160
|
+
"Duplicate index entries are not allowed in to_coo transformation."
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
# to keep things simple, only rely on integer indexing (not labels)
|
|
164
|
+
row_levels = [ss.index._get_level_number(x) for x in row_levels]
|
|
165
|
+
column_levels = [ss.index._get_level_number(x) for x in column_levels]
|
|
166
|
+
|
|
167
|
+
v, i, j, rows, columns = _to_ijv(
|
|
168
|
+
ss, row_levels=row_levels, column_levels=column_levels, sort_labels=sort_labels
|
|
169
|
+
)
|
|
170
|
+
sparse_matrix = scipy.sparse.coo_matrix(
|
|
171
|
+
(v, (i, j)), shape=(len(rows), len(columns))
|
|
172
|
+
)
|
|
173
|
+
return sparse_matrix, rows, columns
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def coo_to_sparse_series(
|
|
177
|
+
A: scipy.sparse.coo_matrix, dense_index: bool = False
|
|
178
|
+
) -> Series:
|
|
179
|
+
"""
|
|
180
|
+
Convert a scipy.sparse.coo_matrix to a Series with type sparse.
|
|
181
|
+
|
|
182
|
+
Parameters
|
|
183
|
+
----------
|
|
184
|
+
A : scipy.sparse.coo_matrix
|
|
185
|
+
dense_index : bool, default False
|
|
186
|
+
|
|
187
|
+
Returns
|
|
188
|
+
-------
|
|
189
|
+
Series
|
|
190
|
+
|
|
191
|
+
Raises
|
|
192
|
+
------
|
|
193
|
+
TypeError if A is not a coo_matrix
|
|
194
|
+
"""
|
|
195
|
+
from pandas import SparseDtype
|
|
196
|
+
|
|
197
|
+
try:
|
|
198
|
+
ser = Series(A.data, MultiIndex.from_arrays((A.row, A.col)), copy=False)
|
|
199
|
+
except AttributeError as err:
|
|
200
|
+
raise TypeError(
|
|
201
|
+
f"Expected coo_matrix. Got {type(A).__name__} instead."
|
|
202
|
+
) from err
|
|
203
|
+
ser = ser.sort_index()
|
|
204
|
+
ser = ser.astype(SparseDtype(ser.dtype))
|
|
205
|
+
if dense_index:
|
|
206
|
+
ind = MultiIndex.from_product([A.row, A.col])
|
|
207
|
+
ser = ser.reindex(ind)
|
|
208
|
+
return ser
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
6c03e03898d71eca976ee1ad8481cf112ae722ba
|