nitro-pandas 0.1.0__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.
- nitro_pandas-0.1.0/.gitignore +142 -0
- nitro_pandas-0.1.0/LICENSE +22 -0
- nitro_pandas-0.1.0/PKG-INFO +436 -0
- nitro_pandas-0.1.0/README.md +420 -0
- nitro_pandas-0.1.0/docs/nitro-pandas-logo.png +0 -0
- nitro_pandas-0.1.0/nitro_pandas/__init__.py +50 -0
- nitro_pandas-0.1.0/nitro_pandas/dataframe.py +1113 -0
- nitro_pandas-0.1.0/nitro_pandas/io/__init__.py +26 -0
- nitro_pandas-0.1.0/nitro_pandas/io/csv.py +245 -0
- nitro_pandas-0.1.0/nitro_pandas/io/excel.py +212 -0
- nitro_pandas-0.1.0/nitro_pandas/io/json.py +163 -0
- nitro_pandas-0.1.0/nitro_pandas/io/parquet.py +184 -0
- nitro_pandas-0.1.0/nitro_pandas/lazyframe.py +346 -0
- nitro_pandas-0.1.0/pyproject.toml +25 -0
- nitro_pandas-0.1.0/tests/__init__.py +2 -0
- nitro_pandas-0.1.0/tests/helpers.py +94 -0
- nitro_pandas-0.1.0/tests/test_dataframe.py +447 -0
- nitro_pandas-0.1.0/tests/test_groupby.py +190 -0
- nitro_pandas-0.1.0/tests/test_io.py +641 -0
- nitro_pandas-0.1.0/tests/test_runner.py +93 -0
- nitro_pandas-0.1.0/uv.lock +298 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
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
|
+
pip-wheel-metadata/
|
|
24
|
+
share/python-wheels/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.installed.cfg
|
|
27
|
+
*.egg
|
|
28
|
+
MANIFEST
|
|
29
|
+
|
|
30
|
+
# PyInstaller
|
|
31
|
+
*.manifest
|
|
32
|
+
*.spec
|
|
33
|
+
|
|
34
|
+
# Installer logs
|
|
35
|
+
pip-log.txt
|
|
36
|
+
pip-delete-this-directory.txt
|
|
37
|
+
|
|
38
|
+
# Unit test / coverage reports
|
|
39
|
+
htmlcov/
|
|
40
|
+
.tox/
|
|
41
|
+
.nox/
|
|
42
|
+
.coverage
|
|
43
|
+
.coverage.*
|
|
44
|
+
.cache
|
|
45
|
+
nosetests.xml
|
|
46
|
+
coverage.xml
|
|
47
|
+
*.cover
|
|
48
|
+
*.py,cover
|
|
49
|
+
.hypothesis/
|
|
50
|
+
.pytest_cache/
|
|
51
|
+
|
|
52
|
+
# Translations
|
|
53
|
+
*.mo
|
|
54
|
+
*.pot
|
|
55
|
+
|
|
56
|
+
# Django stuff:
|
|
57
|
+
*.log
|
|
58
|
+
local_settings.py
|
|
59
|
+
db.sqlite3
|
|
60
|
+
db.sqlite3-journal
|
|
61
|
+
|
|
62
|
+
# Flask stuff:
|
|
63
|
+
instance/
|
|
64
|
+
.webassets-cache
|
|
65
|
+
|
|
66
|
+
# Scrapy stuff:
|
|
67
|
+
.scrapy
|
|
68
|
+
|
|
69
|
+
# Sphinx documentation
|
|
70
|
+
docs/_build/
|
|
71
|
+
|
|
72
|
+
# PyBuilder
|
|
73
|
+
target/
|
|
74
|
+
|
|
75
|
+
# Jupyter Notebook
|
|
76
|
+
.ipynb_checkpoints
|
|
77
|
+
|
|
78
|
+
# IPython
|
|
79
|
+
profile_default/
|
|
80
|
+
ipython_config.py
|
|
81
|
+
|
|
82
|
+
# pyenv
|
|
83
|
+
.python-version
|
|
84
|
+
|
|
85
|
+
# pipenv
|
|
86
|
+
Pipfile.lock
|
|
87
|
+
|
|
88
|
+
# PEP 582
|
|
89
|
+
__pypackages__/
|
|
90
|
+
|
|
91
|
+
# Celery stuff
|
|
92
|
+
celerybeat-schedule
|
|
93
|
+
celerybeat.pid
|
|
94
|
+
|
|
95
|
+
# SageMath parsed files
|
|
96
|
+
*.sage.py
|
|
97
|
+
|
|
98
|
+
# Environments
|
|
99
|
+
.env
|
|
100
|
+
.venv
|
|
101
|
+
env/
|
|
102
|
+
venv/
|
|
103
|
+
ENV/
|
|
104
|
+
env.bak/
|
|
105
|
+
venv.bak/
|
|
106
|
+
|
|
107
|
+
# Spyder project settings
|
|
108
|
+
.spyderproject
|
|
109
|
+
.spyproject
|
|
110
|
+
|
|
111
|
+
# Rope project settings
|
|
112
|
+
.ropeproject
|
|
113
|
+
|
|
114
|
+
# mkdocs documentation
|
|
115
|
+
/site
|
|
116
|
+
|
|
117
|
+
# mypy
|
|
118
|
+
.mypy_cache/
|
|
119
|
+
.dmypy.json
|
|
120
|
+
dmypy.json
|
|
121
|
+
|
|
122
|
+
# Pyre type checker
|
|
123
|
+
.pyre/
|
|
124
|
+
|
|
125
|
+
# IDEs
|
|
126
|
+
.vscode/
|
|
127
|
+
.idea/
|
|
128
|
+
*.swp
|
|
129
|
+
*.swo
|
|
130
|
+
*~
|
|
131
|
+
|
|
132
|
+
# OS
|
|
133
|
+
.DS_Store
|
|
134
|
+
Thumbs.db
|
|
135
|
+
|
|
136
|
+
# Project specific
|
|
137
|
+
*.pyc
|
|
138
|
+
.pytest_cache/
|
|
139
|
+
|
|
140
|
+
# PyPI credentials
|
|
141
|
+
.pypirc
|
|
142
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 nitro-pandas contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nitro-pandas
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A pandas-like API wrapper around Polars for high-performance data manipulation
|
|
5
|
+
Author-email: Labdi Wassim <labdiwassim18@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Keywords: data-analysis,dataframe,pandas,performance,polars
|
|
9
|
+
Requires-Python: >=3.11
|
|
10
|
+
Requires-Dist: fastexcel>=0.7.0
|
|
11
|
+
Requires-Dist: openpyxl>=3.1.5
|
|
12
|
+
Requires-Dist: pandas>=2.2.3
|
|
13
|
+
Requires-Dist: polars>=1.30.0
|
|
14
|
+
Requires-Dist: pyarrow>=20.0.0
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
<div align="center">
|
|
19
|
+
|
|
20
|
+

|
|
21
|
+
|
|
22
|
+
**A high-performance pandas-like DataFrame library powered by Polars**
|
|
23
|
+
|
|
24
|
+
[](https://www.python.org/downloads/)
|
|
25
|
+
[](LICENSE)
|
|
26
|
+
[](https://github.com/psf/black)
|
|
27
|
+
|
|
28
|
+
*Combine the familiar pandas API with Polars' blazing-fast performance*
|
|
29
|
+
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## ✨ Features
|
|
35
|
+
|
|
36
|
+
- 🐼 **Pandas-like API** - Use familiar pandas syntax without learning a new library
|
|
37
|
+
- ⚡ **Polars Backend** - Leverage Polars' optimized engine for maximum performance
|
|
38
|
+
- 🔄 **Lazy Evaluation** - Optimize queries with lazy operations before execution
|
|
39
|
+
- 📊 **Comprehensive I/O** - Read/write CSV, Parquet, JSON, and Excel files
|
|
40
|
+
- 🎯 **Automatic Fallback** - Seamless fallback to pandas for unimplemented methods
|
|
41
|
+
- 🔧 **Type Safety** - Support for pandas-like type casting and schema inference
|
|
42
|
+
|
|
43
|
+
## 🎯 Why nitro-pandas?
|
|
44
|
+
|
|
45
|
+
**nitro-pandas** bridges the gap between pandas' user-friendly API and Polars' exceptional performance. If you're familiar with pandas but need better performance, nitro-pandas is the perfect solution.
|
|
46
|
+
|
|
47
|
+
### Performance Comparison
|
|
48
|
+
|
|
49
|
+
| Operation | pandas | nitro-pandas (Polars) | Speedup |
|
|
50
|
+
|-----------|--------|---------------------|---------|
|
|
51
|
+
| Large CSV Read | 10s | 2s | **5x faster** |
|
|
52
|
+
| GroupBy Aggregation | 5s | 0.5s | **10x faster** |
|
|
53
|
+
| Filter Operations | 3s | 0.3s | **10x faster** |
|
|
54
|
+
|
|
55
|
+
*Results may vary based on data size and hardware*
|
|
56
|
+
|
|
57
|
+
## 📦 Installation
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
# Using uv (recommended)
|
|
61
|
+
uv add nitro-pandas
|
|
62
|
+
|
|
63
|
+
# Using pip
|
|
64
|
+
pip install nitro-pandas
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Requirements
|
|
68
|
+
|
|
69
|
+
- **Python 3.11+**
|
|
70
|
+
- **Dependencies** (automatically installed):
|
|
71
|
+
- `polars>=1.30.0` - High-performance DataFrame engine
|
|
72
|
+
- `pandas>=2.2.3` - For fallback methods
|
|
73
|
+
- `fastexcel>=0.7.0` - Fast Excel reading
|
|
74
|
+
- `openpyxl>=3.1.5` - Excel file support
|
|
75
|
+
- `pyarrow>=20.0.0` - Parquet file support
|
|
76
|
+
|
|
77
|
+
## 🚀 Quick Start
|
|
78
|
+
|
|
79
|
+
### Basic Usage
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
import nitro_pandas as npd
|
|
83
|
+
|
|
84
|
+
# Create a DataFrame (pandas-like syntax)
|
|
85
|
+
df = npd.DataFrame({
|
|
86
|
+
'name': ['Alice', 'Bob', 'Charlie'],
|
|
87
|
+
'age': [25, 30, 35],
|
|
88
|
+
'city': ['Paris', 'London', 'New York']
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
# Access columns (returns pandas Series for compatibility)
|
|
92
|
+
ages = df['age']
|
|
93
|
+
print(ages > 30) # Boolean Series
|
|
94
|
+
|
|
95
|
+
# Filter data
|
|
96
|
+
filtered = df.loc[df['age'] > 30]
|
|
97
|
+
print(filtered)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Reading Files
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
# Read CSV
|
|
104
|
+
df = npd.read_csv('data.csv')
|
|
105
|
+
|
|
106
|
+
# Read with lazy evaluation (optimized for large files)
|
|
107
|
+
lf = npd.read_csv_lazy('large_data.csv')
|
|
108
|
+
df = lf.filter(lf['id'] > 1000).collect()
|
|
109
|
+
|
|
110
|
+
# Read other formats
|
|
111
|
+
df_parquet = npd.read_parquet('data.parquet')
|
|
112
|
+
df_excel = npd.read_excel('data.xlsx')
|
|
113
|
+
df_json = npd.read_json('data.json')
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Data Operations
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
# GroupBy operations (pandas-like syntax, Polars backend)
|
|
120
|
+
result = df.groupby('city')['age'].mean()
|
|
121
|
+
print(result)
|
|
122
|
+
|
|
123
|
+
# Multi-column groupby
|
|
124
|
+
result = df.groupby(['city', 'category'])['value'].sum()
|
|
125
|
+
|
|
126
|
+
# Aggregations with dictionaries
|
|
127
|
+
result = df.groupby('category').agg({
|
|
128
|
+
'value': 'mean',
|
|
129
|
+
'count': 'sum'
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
# Sorting and filtering
|
|
133
|
+
df_sorted = df.sort_values('age', ascending=False)
|
|
134
|
+
df_filtered = df.query("age > 25 and city == 'Paris'")
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Writing Files
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
# Write to various formats
|
|
141
|
+
df.to_csv('output.csv')
|
|
142
|
+
df.to_parquet('output.parquet')
|
|
143
|
+
df.to_json('output.json')
|
|
144
|
+
df.to_excel('output.xlsx')
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## 📚 API Reference
|
|
148
|
+
|
|
149
|
+
### DataFrame Operations
|
|
150
|
+
|
|
151
|
+
#### Creation
|
|
152
|
+
```python
|
|
153
|
+
# From dictionary
|
|
154
|
+
df = npd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]})
|
|
155
|
+
|
|
156
|
+
# From Polars DataFrame
|
|
157
|
+
df = npd.DataFrame(pl.DataFrame({'a': [1, 2, 3]}))
|
|
158
|
+
|
|
159
|
+
# Empty DataFrame
|
|
160
|
+
df = npd.DataFrame()
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
#### Indexing
|
|
164
|
+
```python
|
|
165
|
+
# Column selection
|
|
166
|
+
df['column_name'] # Returns pandas Series
|
|
167
|
+
df[['col1', 'col2']] # Returns DataFrame
|
|
168
|
+
|
|
169
|
+
# Boolean filtering
|
|
170
|
+
df[df['age'] > 30] # Returns DataFrame
|
|
171
|
+
|
|
172
|
+
# Label-based indexing
|
|
173
|
+
df.loc[df['age'] > 30, 'name'] # Returns Series
|
|
174
|
+
df.loc[0:5, ['name', 'age']] # Returns DataFrame
|
|
175
|
+
|
|
176
|
+
# Position-based indexing
|
|
177
|
+
df.iloc[0:5, 0:2] # Returns DataFrame
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
#### Transformations
|
|
181
|
+
```python
|
|
182
|
+
# Type casting (pandas-like types)
|
|
183
|
+
df = df.astype({'id': 'int64', 'name': 'str'})
|
|
184
|
+
|
|
185
|
+
# Rename columns
|
|
186
|
+
df = df.rename(columns={'old_name': 'new_name'})
|
|
187
|
+
|
|
188
|
+
# Drop rows/columns
|
|
189
|
+
df = df.drop(labels=[0, 1], axis=0) # Drop rows
|
|
190
|
+
df = df.drop(labels=['col1'], axis=1) # Drop columns
|
|
191
|
+
|
|
192
|
+
# Fill null values
|
|
193
|
+
df = df.fillna({'column': 0})
|
|
194
|
+
|
|
195
|
+
# Sort values
|
|
196
|
+
df = df.sort_values('age', ascending=False)
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### I/O Functions
|
|
200
|
+
|
|
201
|
+
#### CSV
|
|
202
|
+
```python
|
|
203
|
+
# Eager reading
|
|
204
|
+
df = npd.read_csv('file.csv',
|
|
205
|
+
sep=',',
|
|
206
|
+
usecols=['col1', 'col2'],
|
|
207
|
+
dtype={'id': 'int64'})
|
|
208
|
+
|
|
209
|
+
# Lazy reading
|
|
210
|
+
lf = npd.read_csv_lazy('file.csv', n_rows=1000)
|
|
211
|
+
df = lf.collect()
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
#### Parquet
|
|
215
|
+
```python
|
|
216
|
+
# Eager reading
|
|
217
|
+
df = npd.read_parquet('file.parquet',
|
|
218
|
+
columns=['col1', 'col2'],
|
|
219
|
+
n_rows=1000)
|
|
220
|
+
|
|
221
|
+
# Lazy reading
|
|
222
|
+
lf = npd.read_parquet_lazy('file.parquet')
|
|
223
|
+
df = lf.collect()
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
#### Excel
|
|
227
|
+
```python
|
|
228
|
+
# Eager reading
|
|
229
|
+
df = npd.read_excel('file.xlsx',
|
|
230
|
+
sheet_name=0,
|
|
231
|
+
usecols=['col1', 'col2'],
|
|
232
|
+
nrows=1000)
|
|
233
|
+
|
|
234
|
+
# Lazy reading
|
|
235
|
+
lf = npd.read_excel_lazy('file.xlsx', sheet_name='Sheet1')
|
|
236
|
+
df = lf.collect()
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
#### JSON
|
|
240
|
+
```python
|
|
241
|
+
# Eager reading
|
|
242
|
+
df = npd.read_json('file.json',
|
|
243
|
+
dtype={'id': 'int64'},
|
|
244
|
+
n_rows=1000)
|
|
245
|
+
|
|
246
|
+
# Lazy reading
|
|
247
|
+
lf = npd.read_json_lazy('file.json', lines=True)
|
|
248
|
+
df = lf.collect()
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### LazyFrame Operations
|
|
252
|
+
|
|
253
|
+
```python
|
|
254
|
+
# Create lazy frame
|
|
255
|
+
lf = npd.read_csv_lazy('large_file.csv')
|
|
256
|
+
|
|
257
|
+
# Chain operations (optimized before execution)
|
|
258
|
+
result = (lf
|
|
259
|
+
.filter(lf['age'] > 30)
|
|
260
|
+
.groupby('city')
|
|
261
|
+
.agg({'value': 'mean'})
|
|
262
|
+
.sort_values('value', ascending=False))
|
|
263
|
+
|
|
264
|
+
# Execute query
|
|
265
|
+
df = result.collect()
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## 🔄 Migration from pandas
|
|
269
|
+
|
|
270
|
+
Migrating from pandas to nitro-pandas is straightforward:
|
|
271
|
+
|
|
272
|
+
```python
|
|
273
|
+
# Before (pandas)
|
|
274
|
+
import pandas as pd
|
|
275
|
+
df = pd.read_csv('data.csv')
|
|
276
|
+
result = df.groupby('category')['value'].mean()
|
|
277
|
+
|
|
278
|
+
# After (nitro-pandas)
|
|
279
|
+
import nitro_pandas as npd
|
|
280
|
+
df = npd.read_csv('data.csv')
|
|
281
|
+
result = df.groupby('category')['value'].mean()
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
Most pandas operations work the same way! The main differences:
|
|
285
|
+
|
|
286
|
+
- **Single column selection** (`df['col']`) returns a pandas Series for compatibility
|
|
287
|
+
- **Comparison operations** (`df > 2`) return pandas DataFrames for boolean indexing
|
|
288
|
+
- **Unimplemented methods** automatically fall back to pandas
|
|
289
|
+
|
|
290
|
+
## 🎓 Examples
|
|
291
|
+
|
|
292
|
+
### Example 1: Data Analysis Pipeline
|
|
293
|
+
|
|
294
|
+
```python
|
|
295
|
+
import nitro_pandas as npd
|
|
296
|
+
|
|
297
|
+
# Load data
|
|
298
|
+
df = npd.read_csv('sales.csv')
|
|
299
|
+
|
|
300
|
+
# Clean data
|
|
301
|
+
df = df.dropna(subset=['amount'])
|
|
302
|
+
df = df.astype({'amount': 'float64'})
|
|
303
|
+
|
|
304
|
+
# Analyze
|
|
305
|
+
summary = df.groupby('region').agg({
|
|
306
|
+
'amount': 'sum',
|
|
307
|
+
'orders': 'count'
|
|
308
|
+
})
|
|
309
|
+
|
|
310
|
+
# Filter top regions
|
|
311
|
+
top_regions = summary.sort_values('amount', ascending=False).head(10)
|
|
312
|
+
|
|
313
|
+
# Export
|
|
314
|
+
top_regions.to_excel('top_regions.xlsx')
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### Example 2: Large File Processing
|
|
318
|
+
|
|
319
|
+
```python
|
|
320
|
+
import nitro_pandas as npd
|
|
321
|
+
|
|
322
|
+
# Use lazy evaluation for large files
|
|
323
|
+
lf = npd.read_csv_lazy('huge_file.csv')
|
|
324
|
+
|
|
325
|
+
# Build optimized query
|
|
326
|
+
result = (lf
|
|
327
|
+
.filter(lf['date'] > '2024-01-01')
|
|
328
|
+
.groupby('category')
|
|
329
|
+
.agg({'sales': 'sum', 'orders': 'count'})
|
|
330
|
+
.sort_values('sales', ascending=False))
|
|
331
|
+
|
|
332
|
+
# Execute only when needed
|
|
333
|
+
df = result.collect()
|
|
334
|
+
print(df)
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### Example 3: Complex GroupBy
|
|
338
|
+
|
|
339
|
+
```python
|
|
340
|
+
import nitro_pandas as npd
|
|
341
|
+
|
|
342
|
+
df = npd.DataFrame({
|
|
343
|
+
'city': ['Paris', 'Paris', 'Lyon', 'Lyon'],
|
|
344
|
+
'category': ['A', 'B', 'A', 'B'],
|
|
345
|
+
'revenue': [1000, 2000, 1500, 1800]
|
|
346
|
+
})
|
|
347
|
+
|
|
348
|
+
# Multi-column groupby
|
|
349
|
+
result = df.groupby(['city', 'category'])['revenue'].sum()
|
|
350
|
+
print(result)
|
|
351
|
+
|
|
352
|
+
# Dictionary-based aggregation
|
|
353
|
+
result = df.groupby('city').agg({
|
|
354
|
+
'revenue': 'mean',
|
|
355
|
+
'category': 'count'
|
|
356
|
+
})
|
|
357
|
+
print(result)
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
## 🏗️ Project Structure
|
|
361
|
+
|
|
362
|
+
```
|
|
363
|
+
nitro-pandas/
|
|
364
|
+
├── nitro_pandas/
|
|
365
|
+
│ ├── __init__.py # Package initialization
|
|
366
|
+
│ ├── dataframe.py # DataFrame implementation
|
|
367
|
+
│ ├── lazyframe.py # LazyFrame implementation
|
|
368
|
+
│ └── io/
|
|
369
|
+
│ ├── __init__.py # IO module exports
|
|
370
|
+
│ ├── csv.py # CSV I/O
|
|
371
|
+
│ ├── parquet.py # Parquet I/O
|
|
372
|
+
│ ├── json.py # JSON I/O
|
|
373
|
+
│ └── excel.py # Excel I/O
|
|
374
|
+
├── tests/
|
|
375
|
+
│ ├── test_dataframe.py # DataFrame tests
|
|
376
|
+
│ ├── test_groupby.py # GroupBy tests
|
|
377
|
+
│ ├── test_io.py # I/O tests
|
|
378
|
+
│ └── helpers.py # Test utilities
|
|
379
|
+
├── pyproject.toml # Project configuration
|
|
380
|
+
└── README.md # This file
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
## 🤝 Contributing
|
|
384
|
+
|
|
385
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
386
|
+
|
|
387
|
+
1. Fork the repository
|
|
388
|
+
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
|
|
389
|
+
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
|
|
390
|
+
4. Push to the branch (`git push origin feature/AmazingFeature`)
|
|
391
|
+
5. Open a Pull Request
|
|
392
|
+
|
|
393
|
+
### Development Setup
|
|
394
|
+
|
|
395
|
+
```bash
|
|
396
|
+
# Clone repository
|
|
397
|
+
git clone https://github.com/yourusername/nitro-pandas.git
|
|
398
|
+
cd nitro-pandas
|
|
399
|
+
|
|
400
|
+
# Install development dependencies
|
|
401
|
+
uv sync --dev
|
|
402
|
+
|
|
403
|
+
# Run tests
|
|
404
|
+
uv run python tests/test_runner.py
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
## 📝 License
|
|
408
|
+
|
|
409
|
+
This project is licensed under the **MIT License** - see the [LICENSE](LICENSE) file for details.
|
|
410
|
+
|
|
411
|
+
The MIT License is a permissive open-source license that allows anyone to:
|
|
412
|
+
- ✅ Use the software for any purpose (commercial or personal)
|
|
413
|
+
- ✅ Modify the software
|
|
414
|
+
- ✅ Distribute the software
|
|
415
|
+
- ✅ Sublicense the software
|
|
416
|
+
|
|
417
|
+
**In short: Everyone can use it freely!**
|
|
418
|
+
|
|
419
|
+
## 🙏 Acknowledgments
|
|
420
|
+
|
|
421
|
+
- [Polars](https://www.pola.rs/) - For the high-performance DataFrame engine
|
|
422
|
+
- [pandas](https://pandas.pydata.org/) - For the API inspiration and fallback support
|
|
423
|
+
|
|
424
|
+
## 📧 Contact
|
|
425
|
+
|
|
426
|
+
For questions, suggestions, or support, please open an issue on GitHub.
|
|
427
|
+
|
|
428
|
+
---
|
|
429
|
+
|
|
430
|
+
<div align="center">
|
|
431
|
+
|
|
432
|
+
**Made with ❤️ for the Python data science community**
|
|
433
|
+
|
|
434
|
+
⭐ Star this repo if you find it useful!
|
|
435
|
+
|
|
436
|
+
</div>
|