pdx2


Namepdx2 JSON
Version 0.10.0 PyPI version JSON
download
home_pageNone
SummaryHelper functions to run SQL on Pandas DataFrames
upload_time2024-12-30 22:19:22
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseBSD 3-Clause License Copyright (c) 2024, AJ Friend Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
keywords etl sql data-wrangling duckdb pipelines
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PDX2: Helper functions to run SQL on Pandas DataFrames

[GitHub](https://github.com/ajfriend/pdx2) | [PyPI](https://pypi.org/project/pdx2/)

**NOTE**: This is basically a clone of https://github.com/ajfriend/pdx (since `pdx` is already taken on PyPI.)

```shell
pip install pdx2
```

Small ergonomic improvements to make it easy to run [DuckDB](https://duckdb.org/) queries on Pandas DataFrames.

- `pdx2` monkey-patches `pandas.DataFrame` to provide a `df.sql(...)` method.
- since `pdx` uses DuckDB, you can leverage their convienient SQL dialect:
  - https://duckdb.org/2022/05/04/friendlier-sql.html
  - https://duckdbsnippets.com/


Query a Pandas DataFrame with `df.sql(...)`.
Omit the `FROM` clause because it is added implicitly:

```python
import pdx2
iris = pdx2.data.get_iris()  # returns pandas.DataFrame

iris.sql("""
select
    species,
    count(*)
        as num,
group by
    1
""")
```

You can use short SQL (sub-)expressions because `FROM` and `SELECT *` are implied whenever they're omitted:

```python
iris.sql('where petal_length > 4.5')
```

```python
iris.sql('limit 10')
```

```python
iris.sql('order by petal_length')
```

```python
iris.sql('')  # returns the dataframe unmodified. I.e., 'select * from iris'
```

For more, check out the [example notebook folder](notebooks).

# Other affordances

- `df.aslist()`
- `df.asdict()`
- `df.asitem()`
- `df.cols2dict()`
- save/load helpers for DuckDB database files

# Reference

- [Apache Arrow and the "10 Things I Hate About pandas"](https://wesmckinney.com/blog/apache-arrow-pandas-internals/)

## For bleeding edge DuckDB

```
git clone https://github.com/duckdb/duckdb.git
cd duckdb
../env/bin/pip install -e tools/pythonpkg --verbose
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pdx2",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "ETL, SQL, data-wrangling, duckdb, pipelines",
    "author": null,
    "author_email": "AJ Friend <ajfriend@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/38/ec/04b5ff572396bc571699b7709d1d99458df4484e11b96d0f6be70aab18ff/pdx2-0.10.0.tar.gz",
    "platform": null,
    "description": "# PDX2: Helper functions to run SQL on Pandas DataFrames\n\n[GitHub](https://github.com/ajfriend/pdx2) | [PyPI](https://pypi.org/project/pdx2/)\n\n**NOTE**: This is basically a clone of https://github.com/ajfriend/pdx (since `pdx` is already taken on PyPI.)\n\n```shell\npip install pdx2\n```\n\nSmall ergonomic improvements to make it easy to run [DuckDB](https://duckdb.org/) queries on Pandas DataFrames.\n\n- `pdx2` monkey-patches `pandas.DataFrame` to provide a `df.sql(...)` method.\n- since `pdx` uses DuckDB, you can leverage their convienient SQL dialect:\n  - https://duckdb.org/2022/05/04/friendlier-sql.html\n  - https://duckdbsnippets.com/\n\n\nQuery a Pandas DataFrame with `df.sql(...)`.\nOmit the `FROM` clause because it is added implicitly:\n\n```python\nimport pdx2\niris = pdx2.data.get_iris()  # returns pandas.DataFrame\n\niris.sql(\"\"\"\nselect\n    species,\n    count(*)\n        as num,\ngroup by\n    1\n\"\"\")\n```\n\nYou can use short SQL (sub-)expressions because `FROM` and `SELECT *` are implied whenever they're omitted:\n\n```python\niris.sql('where petal_length > 4.5')\n```\n\n```python\niris.sql('limit 10')\n```\n\n```python\niris.sql('order by petal_length')\n```\n\n```python\niris.sql('')  # returns the dataframe unmodified. I.e., 'select * from iris'\n```\n\nFor more, check out the [example notebook folder](notebooks).\n\n# Other affordances\n\n- `df.aslist()`\n- `df.asdict()`\n- `df.asitem()`\n- `df.cols2dict()`\n- save/load helpers for DuckDB database files\n\n# Reference\n\n- [Apache Arrow and the \"10 Things I Hate About pandas\"](https://wesmckinney.com/blog/apache-arrow-pandas-internals/)\n\n## For bleeding edge DuckDB\n\n```\ngit clone https://github.com/duckdb/duckdb.git\ncd duckdb\n../env/bin/pip install -e tools/pythonpkg --verbose\n```\n",
    "bugtrack_url": null,
    "license": "BSD 3-Clause License  Copyright (c) 2024, AJ Friend  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.",
    "summary": "Helper functions to run SQL on Pandas DataFrames",
    "version": "0.10.0",
    "project_urls": {
        "documentation": "https://github.com/ajfriend/pdx2",
        "homepage": "https://github.com/ajfriend/pdx2",
        "pypi": "https://pypi.org/project/pdx2",
        "repository": "https://github.com/ajfriend/pdx2"
    },
    "split_keywords": [
        "etl",
        " sql",
        " data-wrangling",
        " duckdb",
        " pipelines"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "edf3f58353aa7f80309b980cba5d77124ba91f647d4ddaba533382ceab837783",
                "md5": "ea51e339337f8671e06c494ea6cf7424",
                "sha256": "ee8f786d9bb96e0da950b3df2858dfe2c34065be7ca84d6dba02a0b9c0585302"
            },
            "downloads": -1,
            "filename": "pdx2-0.10.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ea51e339337f8671e06c494ea6cf7424",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 7764,
            "upload_time": "2024-12-30T22:19:19",
            "upload_time_iso_8601": "2024-12-30T22:19:19.632800Z",
            "url": "https://files.pythonhosted.org/packages/ed/f3/f58353aa7f80309b980cba5d77124ba91f647d4ddaba533382ceab837783/pdx2-0.10.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "38ec04b5ff572396bc571699b7709d1d99458df4484e11b96d0f6be70aab18ff",
                "md5": "b35c291bf44c8c999851811b2fd7e3b3",
                "sha256": "c920c08b01b10b8414af8038bebc611bcbe384701a29f37d34a75ca412f2b0dc"
            },
            "downloads": -1,
            "filename": "pdx2-0.10.0.tar.gz",
            "has_sig": false,
            "md5_digest": "b35c291bf44c8c999851811b2fd7e3b3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 5704,
            "upload_time": "2024-12-30T22:19:22",
            "upload_time_iso_8601": "2024-12-30T22:19:22.255468Z",
            "url": "https://files.pythonhosted.org/packages/38/ec/04b5ff572396bc571699b7709d1d99458df4484e11b96d0f6be70aab18ff/pdx2-0.10.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-30 22:19:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ajfriend",
    "github_project": "pdx2",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pdx2"
}
        
Elapsed time: 1.86364s