Skip to content

Commit 58e8334

Browse files
committed
reorganize docs and better where_ method
1 parent e2ef99a commit 58e8334

14 files changed

+95
-62
lines changed

.gitignore

+2-4
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ ipython_config.py
8888
# pyenv
8989
# For a library or package, you might want to ignore these files since the code is
9090
# intended to run in multiple environments; otherwise, check them in:
91-
# .python-version
91+
.python-version
9292

9393
# pipenv
9494
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
@@ -161,6 +161,4 @@ cython_debug/
161161
docs/_build/
162162

163163
# uv stuff
164-
uv.lock
165-
166-
.python-version
164+
uv.lock
File renamed without changes.
File renamed without changes.

docs/conf.py

-26
This file was deleted.
File renamed without changes.

docs/api.rst docs/source/api.rst

File renamed without changes.
File renamed without changes.

docs/source/conf.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import os
2+
import sys
3+
4+
# Ajoute le répertoire parent au chemin Python
5+
sys.path.insert(0, os.path.abspath('..'))
6+
print("Python path:", sys.path)
7+
8+
# Information sur le projet
9+
project = 'seekwellpandas'
10+
copyright = '2024, Essi Parent'
11+
author = 'Essi Parent'
12+
release = '0.2'
13+
14+
# Extensions Sphinx
15+
extensions = [
16+
'sphinx.ext.autodoc',
17+
'sphinx.ext.napoleon',
18+
'nbsphinx',
19+
'sphinx.ext.viewcode', # Ajoute des liens vers le code source
20+
'sphinx.ext.githubpages', # Support pour GitHub Pages
21+
]
22+
23+
# Configuration de base
24+
master_doc = 'index'
25+
source_suffix = ['.rst', '.md']
26+
27+
# Configuration de la sortie
28+
htmlhelp_basename = 'seekwellpandasDoc'
29+
templates_path = ['_templates']
30+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
31+
32+
# Thème et style
33+
html_theme = 'alabaster'
34+
html_static_path = ['_static']
35+
html_logo = '_static/logo.png'
36+
37+
# Configuration supplémentaire pour une meilleure documentation
38+
autodoc_member_order = 'bysource'
39+
napoleon_google_docstring = True
40+
napoleon_numpy_docstring = True
41+
napoleon_include_init_with_doc = False
42+
napoleon_include_private_with_doc = False
43+
napoleon_include_special_with_doc = True
44+
napoleon_use_admonition_for_examples = False
45+
napoleon_use_admonition_for_notes = False
46+
napoleon_use_admonition_for_references = False
47+
napoleon_use_ivar = False
48+
napoleon_use_param = True
49+
napoleon_use_rtype = True

docs/index.rst docs/source/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ This project is licensed under the GPLv3 License.
5656
:caption: Contents:
5757

5858
about
59-
_examples/basic-usage
59+
basic-usage
6060
api

pyproject.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "seekwellpandas"
7-
dynamic = ["version"]
7+
revision = 0.2
88
authors = [
99
{name = "Essi Parent", email = "[email protected]"},
1010
]
@@ -21,6 +21,9 @@ dependencies = [
2121
"pandas-flavor>=0.3.0"
2222
]
2323

24+
[project.optional-dependencies]
25+
dev = ["bump-my-version", "marimo", "uv"]
26+
2427
[tool.setuptools_scm]
2528
write_to = "src/seekwellpandas/_version.py"
2629

requirements-dev.txt

-3
This file was deleted.

src/seekwellpandas/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,3 @@
1919
)
2020

2121
from .methods import __all__
22-
23-
__version__ = "0.2"

src/seekwellpandas/_version.py

-16
This file was deleted.

src/seekwellpandas/methods.py

+39-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
import pandas as pd
23
import pandas_flavor as pf
34
import warnings
@@ -57,20 +58,49 @@ def _process_column(col, all_columns, selected_columns, excluded_columns):
5758
selected_columns.add(col)
5859

5960
@pf.register_dataframe_method
60-
def where_(df, condition):
61+
def where2_(df: DataFrame, condition: str) -> DataFrame:
6162
"""
62-
Filter the DataFrame based on a condition.
63-
63+
Filter the DataFrame based on SQL-like conditions.
64+
6465
Parameters:
6566
df (pd.DataFrame): The DataFrame to filter.
66-
condition (str or list): The condition(s) to filter by. Can be a string or a list of strings.
67-
67+
condition (str): A string representing the condition in SQL-like syntax.
68+
6869
Returns:
6970
pd.DataFrame: A filtered DataFrame.
70-
"""
71-
if isinstance(condition, list):
72-
condition = ' and '.join(f'({cond})' for cond in condition)
73-
return df.query(condition)
71+
72+
Examples:
73+
df.where_('column > 5')
74+
df.where_('column in value1, value2, value3')
75+
df.where_('column1 == value and column2 > 10')
76+
"""
77+
def parse_condition(cond):
78+
# Parse 'in' conditions
79+
in_match = re.match(r'(\w+)\s+in\s+(.*)', cond)
80+
if in_match:
81+
column, values = in_match.groups()
82+
values = [v.strip() for v in values.split(',')]
83+
return f"{column}.isin({values})"
84+
85+
# Parse other conditions
86+
ops = {'==': '==', '!=': '!=', '>': '>', '<': '<', '>=': '>=', '<=': '<='}
87+
for op in ops:
88+
if op in cond:
89+
column, value = cond.split(op)
90+
return f"{column.strip()} {ops[op]} {value.strip()}"
91+
92+
return cond
93+
94+
# Split the condition string into individual conditions
95+
conditions = [c.strip() for c in re.split(r'\s+and\s+|\s+or\s+', condition)]
96+
parsed_conditions = [parse_condition(c) for c in conditions]
97+
98+
# Reconstruct the query string
99+
query = re.sub(r'\s+and\s+|\s+or\s+', lambda m: m.group(0), condition)
100+
for original, parsed in zip(conditions, parsed_conditions):
101+
query = query.replace(original, parsed)
102+
103+
return df.query(query)
74104

75105
@pf.register_dataframe_method
76106
def group_by(df, *columns):

0 commit comments

Comments
 (0)