pandasquery 0.0.1__tar.gz
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.
- pandasquery-0.0.1/.github/workflows/publish.yaml +34 -0
- pandasquery-0.0.1/.gitignore +223 -0
- pandasquery-0.0.1/PKG-INFO +78 -0
- pandasquery-0.0.1/README.md +42 -0
- pandasquery-0.0.1/pyproject.toml +85 -0
- pandasquery-0.0.1/setup.cfg +4 -0
- pandasquery-0.0.1/src/pandasquery/PandasQuery.py +113 -0
- pandasquery-0.0.1/src/pandasquery/__init__.py +1 -0
- pandasquery-0.0.1/src/pandasquery/conditions/__init__.py +3 -0
- pandasquery-0.0.1/src/pandasquery/conditions/pandas_query_and_condition.py +18 -0
- pandasquery-0.0.1/src/pandasquery/conditions/pandas_query_condition.py +38 -0
- pandasquery-0.0.1/src/pandasquery/conditions/pandas_query_or_condition.py +18 -0
- pandasquery-0.0.1/src/pandasquery/enums/__init__.py +2 -0
- pandasquery-0.0.1/src/pandasquery/enums/pandas_query_condition_binder_values.py +6 -0
- pandasquery-0.0.1/src/pandasquery/enums/pandas_query_operators_enum.py +9 -0
- pandasquery-0.0.1/src/pandasquery.egg-info/PKG-INFO +78 -0
- pandasquery-0.0.1/src/pandasquery.egg-info/SOURCES.txt +25 -0
- pandasquery-0.0.1/src/pandasquery.egg-info/dependency_links.txt +1 -0
- pandasquery-0.0.1/src/pandasquery.egg-info/requires.txt +10 -0
- pandasquery-0.0.1/src/pandasquery.egg-info/scm_file_list.json +22 -0
- pandasquery-0.0.1/src/pandasquery.egg-info/scm_version.json +8 -0
- pandasquery-0.0.1/src/pandasquery.egg-info/top_level.txt +1 -0
- pandasquery-0.0.1/tests/__init__.py +0 -0
- pandasquery-0.0.1/tests/data/titanic.csv +888 -0
- pandasquery-0.0.1/tests/loaders.py +11 -0
- pandasquery-0.0.1/tests/test_equal.py +16 -0
- pandasquery-0.0.1/tests/test_greater_and_greater_than.py +22 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- 'v*'
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
build-and-publish:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
environment: release
|
|
12
|
+
permissions:
|
|
13
|
+
id-token: write
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- name: Checkout code
|
|
17
|
+
uses: actions/checkout@v4
|
|
18
|
+
with:
|
|
19
|
+
# required for setuptools_scm to see the git tags
|
|
20
|
+
fetch-depth: 0
|
|
21
|
+
|
|
22
|
+
- name: Set up Python
|
|
23
|
+
uses: actions/setup-python@v5
|
|
24
|
+
with:
|
|
25
|
+
python-version: "3.x"
|
|
26
|
+
|
|
27
|
+
- name: Install build tools
|
|
28
|
+
run: python -m pip install --upgrade build
|
|
29
|
+
|
|
30
|
+
- name: Build the package
|
|
31
|
+
run: python -m build
|
|
32
|
+
|
|
33
|
+
- name: Publish to PyPI
|
|
34
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
*.lcov
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
cover/
|
|
54
|
+
|
|
55
|
+
# Translations
|
|
56
|
+
*.mo
|
|
57
|
+
*.pot
|
|
58
|
+
|
|
59
|
+
# Django stuff:
|
|
60
|
+
*.log
|
|
61
|
+
local_settings.py
|
|
62
|
+
db.sqlite3
|
|
63
|
+
db.sqlite3-journal
|
|
64
|
+
|
|
65
|
+
# Flask stuff:
|
|
66
|
+
instance/
|
|
67
|
+
.webassets-cache
|
|
68
|
+
|
|
69
|
+
# Scrapy stuff:
|
|
70
|
+
.scrapy
|
|
71
|
+
|
|
72
|
+
# Sphinx documentation
|
|
73
|
+
docs/_build/
|
|
74
|
+
|
|
75
|
+
# PyBuilder
|
|
76
|
+
.pybuilder/
|
|
77
|
+
target/
|
|
78
|
+
|
|
79
|
+
# Jupyter Notebook
|
|
80
|
+
.ipynb_checkpoints
|
|
81
|
+
|
|
82
|
+
# IPython
|
|
83
|
+
profile_default/
|
|
84
|
+
ipython_config.py
|
|
85
|
+
|
|
86
|
+
# pyenv
|
|
87
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
88
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
89
|
+
# .python-version
|
|
90
|
+
|
|
91
|
+
# pipenv
|
|
92
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
93
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
94
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
95
|
+
# install all needed dependencies.
|
|
96
|
+
# Pipfile.lock
|
|
97
|
+
|
|
98
|
+
# uv
|
|
99
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
100
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
101
|
+
# commonly ignored for libraries.
|
|
102
|
+
# uv.lock
|
|
103
|
+
|
|
104
|
+
# poetry
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
106
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
107
|
+
# commonly ignored for libraries.
|
|
108
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
109
|
+
# poetry.lock
|
|
110
|
+
# poetry.toml
|
|
111
|
+
|
|
112
|
+
# pdm
|
|
113
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
114
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
115
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
116
|
+
# pdm.lock
|
|
117
|
+
# pdm.toml
|
|
118
|
+
.pdm-python
|
|
119
|
+
.pdm-build/
|
|
120
|
+
|
|
121
|
+
# pixi
|
|
122
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
123
|
+
# pixi.lock
|
|
124
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
125
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
126
|
+
.pixi/*
|
|
127
|
+
!.pixi/config.toml
|
|
128
|
+
|
|
129
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
130
|
+
__pypackages__/
|
|
131
|
+
|
|
132
|
+
# Celery stuff
|
|
133
|
+
celerybeat-schedule*
|
|
134
|
+
celerybeat.pid
|
|
135
|
+
|
|
136
|
+
# Redis
|
|
137
|
+
*.rdb
|
|
138
|
+
*.aof
|
|
139
|
+
*.pid
|
|
140
|
+
|
|
141
|
+
# RabbitMQ
|
|
142
|
+
mnesia/
|
|
143
|
+
rabbitmq/
|
|
144
|
+
rabbitmq-data/
|
|
145
|
+
|
|
146
|
+
# ActiveMQ
|
|
147
|
+
activemq-data/
|
|
148
|
+
|
|
149
|
+
# SageMath parsed files
|
|
150
|
+
*.sage.py
|
|
151
|
+
|
|
152
|
+
# Environments
|
|
153
|
+
.env
|
|
154
|
+
.envrc
|
|
155
|
+
.venv
|
|
156
|
+
env/
|
|
157
|
+
venv/
|
|
158
|
+
ENV/
|
|
159
|
+
env.bak/
|
|
160
|
+
venv.bak/
|
|
161
|
+
|
|
162
|
+
# Conda environments
|
|
163
|
+
conda-meta/
|
|
164
|
+
|
|
165
|
+
# Spyder project settings
|
|
166
|
+
.spyderproject
|
|
167
|
+
.spyproject
|
|
168
|
+
|
|
169
|
+
# Rope project settings
|
|
170
|
+
.ropeproject
|
|
171
|
+
|
|
172
|
+
# mkdocs/Zensical documentation
|
|
173
|
+
/site
|
|
174
|
+
|
|
175
|
+
# mypy
|
|
176
|
+
.mypy_cache/
|
|
177
|
+
.dmypy.json
|
|
178
|
+
dmypy.json
|
|
179
|
+
|
|
180
|
+
# Pyre type checker
|
|
181
|
+
.pyre/
|
|
182
|
+
|
|
183
|
+
# pytype static type analyzer
|
|
184
|
+
.pytype/
|
|
185
|
+
|
|
186
|
+
# Cython debug symbols
|
|
187
|
+
cython_debug/
|
|
188
|
+
|
|
189
|
+
# PyCharm
|
|
190
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
191
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
192
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
193
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
194
|
+
# .idea/
|
|
195
|
+
|
|
196
|
+
# Abstra
|
|
197
|
+
# Abstra is an AI-powered process automation framework.
|
|
198
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
199
|
+
# Learn more at https://abstra.io/docs
|
|
200
|
+
.abstra/
|
|
201
|
+
|
|
202
|
+
# Visual Studio Code
|
|
203
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore that
|
|
204
|
+
# can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
205
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer, you
|
|
206
|
+
# could uncomment the following to ignore the entire vscode folder
|
|
207
|
+
# .vscode/
|
|
208
|
+
# Temporary file for partial code execution
|
|
209
|
+
tempCodeRunnerFile.py
|
|
210
|
+
|
|
211
|
+
# Ruff stuff:
|
|
212
|
+
.ruff_cache/
|
|
213
|
+
|
|
214
|
+
# PyPI configuration file
|
|
215
|
+
.pypirc
|
|
216
|
+
|
|
217
|
+
# Marimo
|
|
218
|
+
marimo/_static/
|
|
219
|
+
marimo/_lsp/
|
|
220
|
+
__marimo__/
|
|
221
|
+
|
|
222
|
+
# Streamlit
|
|
223
|
+
.streamlit/secrets.toml
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pandasquery
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Provides an efficient simple interface to query a Pandas DataFrame or Series.
|
|
5
|
+
Author-email: Taha Shieenavaz <tahashieenavaz@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/tahashieenavaz/pandas-query
|
|
8
|
+
Project-URL: Repository, https://github.com/tahashieenavaz/pandas-query
|
|
9
|
+
Project-URL: Documentation, https://github.com/tahashieenavaz/pandas-query#readme
|
|
10
|
+
Project-URL: Issues, https://github.com/tahashieenavaz/pandas-query/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/tahashieenavaz/pandas-query/blob/main/CHANGELOG.md
|
|
12
|
+
Keywords: series,pandas,dataframe,search,query
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
|
+
Requires-Python: >=3.9
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
Requires-Dist: numpy
|
|
28
|
+
Requires-Dist: pandas
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: build; extra == "dev"
|
|
31
|
+
Requires-Dist: pytest; extra == "dev"
|
|
32
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
33
|
+
Requires-Dist: ruff; extra == "dev"
|
|
34
|
+
Requires-Dist: mypy; extra == "dev"
|
|
35
|
+
Requires-Dist: twine; extra == "dev"
|
|
36
|
+
|
|
37
|
+
# Pandas Query
|
|
38
|
+
|
|
39
|
+
Provides an efficient simple class to query a Pandas DataFrame or Series.
|
|
40
|
+
|
|
41
|
+
## Installation
|
|
42
|
+
|
|
43
|
+
For using the package inside your projects simply install the package using `pip`:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install pandasquery
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Alternatively, for development after cloning the repository use:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install -e .
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Usage
|
|
56
|
+
|
|
57
|
+
You can instantiate queries with `Query` class and apply them memory-efficiently to the same dataframe as you please:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from pandasquery import Query
|
|
61
|
+
|
|
62
|
+
# load the data
|
|
63
|
+
dataframe = load_dataframe()
|
|
64
|
+
|
|
65
|
+
# create the specific query
|
|
66
|
+
youth_query = Query().where("age", "<=", 30)
|
|
67
|
+
|
|
68
|
+
# apply it directly to the dataframe
|
|
69
|
+
print(youth_query.apply(dataframe))
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Methods
|
|
73
|
+
|
|
74
|
+
### where
|
|
75
|
+
### on
|
|
76
|
+
### andWhere
|
|
77
|
+
### orWhere
|
|
78
|
+
### apply
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Pandas Query
|
|
2
|
+
|
|
3
|
+
Provides an efficient simple class to query a Pandas DataFrame or Series.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
For using the package inside your projects simply install the package using `pip`:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install pandasquery
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Alternatively, for development after cloning the repository use:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install -e .
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
You can instantiate queries with `Query` class and apply them memory-efficiently to the same dataframe as you please:
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from pandasquery import Query
|
|
25
|
+
|
|
26
|
+
# load the data
|
|
27
|
+
dataframe = load_dataframe()
|
|
28
|
+
|
|
29
|
+
# create the specific query
|
|
30
|
+
youth_query = Query().where("age", "<=", 30)
|
|
31
|
+
|
|
32
|
+
# apply it directly to the dataframe
|
|
33
|
+
print(youth_query.apply(dataframe))
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Methods
|
|
37
|
+
|
|
38
|
+
### where
|
|
39
|
+
### on
|
|
40
|
+
### andWhere
|
|
41
|
+
### orWhere
|
|
42
|
+
### apply
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
|
|
2
|
+
[build-system]
|
|
3
|
+
requires = [
|
|
4
|
+
"setuptools>=77.0",
|
|
5
|
+
"setuptools-scm>=8.0",
|
|
6
|
+
]
|
|
7
|
+
build-backend = "setuptools.build_meta"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
[project]
|
|
11
|
+
name = "pandasquery"
|
|
12
|
+
dynamic = ["version"]
|
|
13
|
+
|
|
14
|
+
description = "Provides an efficient simple interface to query a Pandas DataFrame or Series."
|
|
15
|
+
readme = { file = "README.md", content-type = "text/markdown" }
|
|
16
|
+
requires-python = ">=3.9"
|
|
17
|
+
|
|
18
|
+
license = "MIT"
|
|
19
|
+
license-files = ["LICENSE*"]
|
|
20
|
+
|
|
21
|
+
authors = [
|
|
22
|
+
{ name = "Taha Shieenavaz", email = "tahashieenavaz@gmail.com"},
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
keywords = ["series", "pandas", "dataframe", "search", "query"]
|
|
26
|
+
|
|
27
|
+
classifiers = [
|
|
28
|
+
"Development Status :: 4 - Beta",
|
|
29
|
+
"Intended Audience :: Developers",
|
|
30
|
+
"Operating System :: OS Independent",
|
|
31
|
+
"Programming Language :: Python :: 3",
|
|
32
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
33
|
+
"Programming Language :: Python :: 3.9",
|
|
34
|
+
"Programming Language :: Python :: 3.10",
|
|
35
|
+
"Programming Language :: Python :: 3.11",
|
|
36
|
+
"Programming Language :: Python :: 3.12",
|
|
37
|
+
"Programming Language :: Python :: 3.13",
|
|
38
|
+
"Programming Language :: Python :: 3.14",
|
|
39
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
dependencies = ["numpy", "pandas"]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
[project.optional-dependencies]
|
|
46
|
+
dev = [
|
|
47
|
+
"build",
|
|
48
|
+
"pytest",
|
|
49
|
+
"pytest-cov",
|
|
50
|
+
"ruff",
|
|
51
|
+
"mypy",
|
|
52
|
+
"twine",
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
[project.urls]
|
|
57
|
+
Homepage = "https://github.com/tahashieenavaz/pandas-query"
|
|
58
|
+
Repository = "https://github.com/tahashieenavaz/pandas-query"
|
|
59
|
+
Documentation = "https://github.com/tahashieenavaz/pandas-query#readme"
|
|
60
|
+
Issues = "https://github.com/tahashieenavaz/pandas-query/issues"
|
|
61
|
+
Changelog = "https://github.com/tahashieenavaz/pandas-query/blob/main/CHANGELOG.md"
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
[tool.setuptools]
|
|
65
|
+
package-dir = {"" = "src"}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
[tool.setuptools.packages.find]
|
|
69
|
+
where = ["src"]
|
|
70
|
+
exclude = [
|
|
71
|
+
"tests*",
|
|
72
|
+
"docs*",
|
|
73
|
+
"figures*",
|
|
74
|
+
"mermaid*",
|
|
75
|
+
"scripts*",
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
[tool.setuptools.package-data]
|
|
80
|
+
pandasquery = ["*.md", "*.txt", "*.png"]
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
[tool.setuptools_scm]
|
|
84
|
+
version_scheme = "guess-next-dev"
|
|
85
|
+
local_scheme = "no-local-version"
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import pandas
|
|
2
|
+
from typing import Optional
|
|
3
|
+
from pandasquery.conditions import PandasQueryCondition
|
|
4
|
+
from pandasquery.conditions import PandasQueryAndCondition
|
|
5
|
+
from pandasquery.conditions import PandasQueryOrCondition
|
|
6
|
+
from pandasquery.enums import PandasQueryConditionBinderValues
|
|
7
|
+
from pandasquery.enums import PandasQueryOperatorsEnum
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class PandasQuery:
|
|
11
|
+
def __init__(self):
|
|
12
|
+
self.conditions: list[PandasQueryCondition] = []
|
|
13
|
+
|
|
14
|
+
def where(
|
|
15
|
+
self,
|
|
16
|
+
column: str,
|
|
17
|
+
operatorOrValue: any,
|
|
18
|
+
valueIfNotProvidedBefore: Optional[any] = None,
|
|
19
|
+
*,
|
|
20
|
+
binder: Optional[PandasQueryConditionBinderValues] = None,
|
|
21
|
+
):
|
|
22
|
+
if binder is None and len(self.conditions) != 0:
|
|
23
|
+
raise Exception(
|
|
24
|
+
"Binder can be None only for the first condition. Use orWhere or andWhere instead of where over and over again."
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
self.conditions.append(
|
|
28
|
+
PandasQueryAndCondition(
|
|
29
|
+
column=column,
|
|
30
|
+
operatorOrValue=operatorOrValue,
|
|
31
|
+
valueIfNotProvidedBefore=valueIfNotProvidedBefore,
|
|
32
|
+
)
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
return self
|
|
36
|
+
|
|
37
|
+
def andWhere(
|
|
38
|
+
self,
|
|
39
|
+
column: str,
|
|
40
|
+
operatorOrValue: any,
|
|
41
|
+
valueIfNotProvidedBefore: Optional[any] = None,
|
|
42
|
+
):
|
|
43
|
+
if len(self.conditions) == 0:
|
|
44
|
+
raise Exception(
|
|
45
|
+
"Please start the conditions using `where` method and continue using auxiliaries such as `andWhere` and `orWhere`."
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
self.conditions.append(
|
|
49
|
+
PandasQueryAndCondition(
|
|
50
|
+
column=column,
|
|
51
|
+
operatorOrValue=operatorOrValue,
|
|
52
|
+
valueIfNotProvidedBefore=valueIfNotProvidedBefore,
|
|
53
|
+
)
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
return self
|
|
57
|
+
|
|
58
|
+
def orWhere(
|
|
59
|
+
self,
|
|
60
|
+
column: str,
|
|
61
|
+
operatorOrValue: any,
|
|
62
|
+
valueIfNotProvidedBefore: Optional[any] = None,
|
|
63
|
+
):
|
|
64
|
+
if len(self.conditions) == 0:
|
|
65
|
+
raise Exception(
|
|
66
|
+
"Please start the conditions using `where` method and continue using auxiliaries such as `andWhere` and `orWhere`."
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
self.conditions.append(
|
|
70
|
+
PandasQueryOrCondition(
|
|
71
|
+
column=column,
|
|
72
|
+
operatorOrValue=operatorOrValue,
|
|
73
|
+
valueIfNotProvidedBefore=valueIfNotProvidedBefore,
|
|
74
|
+
)
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
return self
|
|
78
|
+
|
|
79
|
+
def apply(self, dataframe: pandas.DataFrame) -> pandas.DataFrame:
|
|
80
|
+
_mask = pandas.Series(True, index=dataframe.index)
|
|
81
|
+
for condition in self.conditions:
|
|
82
|
+
column, value, operator = condition.unpack()
|
|
83
|
+
|
|
84
|
+
if operator not in PandasQueryOperatorsEnum:
|
|
85
|
+
raise Exception(f"Invalid operator found in conditions. {operator}")
|
|
86
|
+
|
|
87
|
+
if condition.is_and():
|
|
88
|
+
if operator == PandasQueryOperatorsEnum.EqualTo:
|
|
89
|
+
_mask &= dataframe[column] == value
|
|
90
|
+
elif operator == PandasQueryOperatorsEnum.GreaterThan:
|
|
91
|
+
_mask &= dataframe[column] > value
|
|
92
|
+
elif operator == PandasQueryOperatorsEnum.GreaterThanOrEqualTo:
|
|
93
|
+
_mask &= dataframe[column] >= value
|
|
94
|
+
elif operator == PandasQueryOperatorsEnum.LesserThan:
|
|
95
|
+
_mask &= dataframe[column] < value
|
|
96
|
+
elif operator == PandasQueryOperatorsEnum.LesserThanOrEqualTo:
|
|
97
|
+
_mask &= dataframe[column] <= value
|
|
98
|
+
elif condition.is_or():
|
|
99
|
+
if operator == PandasQueryOperatorsEnum.EqualTo:
|
|
100
|
+
_mask |= dataframe[column] == value
|
|
101
|
+
elif operator == PandasQueryOperatorsEnum.GreaterThan:
|
|
102
|
+
_mask |= dataframe[column] > value
|
|
103
|
+
elif operator == PandasQueryOperatorsEnum.GreaterThanOrEqualTo:
|
|
104
|
+
_mask |= dataframe[column] >= value
|
|
105
|
+
elif operator == PandasQueryOperatorsEnum.LesserThan:
|
|
106
|
+
_mask |= dataframe[column] < value
|
|
107
|
+
elif operator == PandasQueryOperatorsEnum.LesserThanOrEqualTo:
|
|
108
|
+
_mask |= dataframe[column] <= value
|
|
109
|
+
else:
|
|
110
|
+
raise Exception(
|
|
111
|
+
"Unknown condition type was passed. Condition binder must be in {AND, OR}."
|
|
112
|
+
)
|
|
113
|
+
return dataframe[_mask]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .PandasQuery import PandasQuery
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
from pandasquery.conditions import PandasQueryCondition
|
|
3
|
+
from pandasquery.enums import PandasQueryConditionBinderValues
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class PandasQueryAndCondition(PandasQueryCondition):
|
|
7
|
+
def __init__(
|
|
8
|
+
self,
|
|
9
|
+
column: str,
|
|
10
|
+
operatorOrValue: any,
|
|
11
|
+
valueIfNotProvidedBefore: Optional[any] = None,
|
|
12
|
+
):
|
|
13
|
+
super().__init__(
|
|
14
|
+
column=column,
|
|
15
|
+
operatorOrValue=operatorOrValue,
|
|
16
|
+
valueIfNotProvidedBefore=valueIfNotProvidedBefore,
|
|
17
|
+
binder=PandasQueryConditionBinderValues.AND,
|
|
18
|
+
)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
from pandasquery.enums import PandasQueryConditionBinderValues
|
|
3
|
+
from pandasquery.enums import PandasQueryOperatorsEnum
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class PandasQueryCondition:
|
|
7
|
+
def __init__(
|
|
8
|
+
self,
|
|
9
|
+
column: str,
|
|
10
|
+
operatorOrValue: any,
|
|
11
|
+
valueIfNotProvidedBefore: Optional[any] = None,
|
|
12
|
+
*,
|
|
13
|
+
binder: Optional[PandasQueryConditionBinderValues] = None,
|
|
14
|
+
):
|
|
15
|
+
self.column = column
|
|
16
|
+
self.binder = binder
|
|
17
|
+
|
|
18
|
+
if valueIfNotProvidedBefore is not None:
|
|
19
|
+
self.value = valueIfNotProvidedBefore
|
|
20
|
+
self.operator = operatorOrValue
|
|
21
|
+
else:
|
|
22
|
+
self.value = operatorOrValue
|
|
23
|
+
self.operator = PandasQueryOperatorsEnum.EqualTo
|
|
24
|
+
|
|
25
|
+
def unpack(self) -> tuple[str, any]:
|
|
26
|
+
return (self.column, self.value, self.operator)
|
|
27
|
+
|
|
28
|
+
def is_and(self):
|
|
29
|
+
return self.binder == PandasQueryConditionBinderValues.AND
|
|
30
|
+
|
|
31
|
+
def is_or(self):
|
|
32
|
+
return self.binder == PandasQueryConditionBinderValues.OR
|
|
33
|
+
|
|
34
|
+
def __str__(self):
|
|
35
|
+
return f"PandasQueryCondition({self.column}, {self.operator}, {self.value})"
|
|
36
|
+
|
|
37
|
+
def __repr__(self):
|
|
38
|
+
return self.__str__()
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
from pandasquery.enums import PandasQueryConditionBinderValues
|
|
3
|
+
from .pandas_query_condition import PandasQueryCondition
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class PandasQueryOrCondition(PandasQueryCondition):
|
|
7
|
+
def __init__(
|
|
8
|
+
self,
|
|
9
|
+
column: str,
|
|
10
|
+
operatorOrValue: any,
|
|
11
|
+
valueIfNotProvidedBefore: Optional[any] = None,
|
|
12
|
+
):
|
|
13
|
+
super().__init__(
|
|
14
|
+
column=column,
|
|
15
|
+
operatorOrValue=operatorOrValue,
|
|
16
|
+
valueIfNotProvidedBefore=valueIfNotProvidedBefore,
|
|
17
|
+
binder=PandasQueryConditionBinderValues.OR,
|
|
18
|
+
)
|