kshri 0.1.0__py3-none-any.whl
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.
- kshri/__init__.py +21 -0
- kshri/core.py +39 -0
- kshri/crazy.py +89 -0
- kshri-0.1.0.dist-info/METADATA +23 -0
- kshri-0.1.0.dist-info/RECORD +8 -0
- kshri-0.1.0.dist-info/WHEEL +5 -0
- kshri-0.1.0.dist-info/licenses/LICENSE +13 -0
- kshri-0.1.0.dist-info/top_level.txt +1 -0
kshri/__init__.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from .core import Array, DataFrame
|
|
2
|
+
from .crazy import (
|
|
3
|
+
roast,
|
|
4
|
+
vibe_check,
|
|
5
|
+
chaotic_sort,
|
|
6
|
+
time_travel,
|
|
7
|
+
explain_like_im_5,
|
|
8
|
+
indian_format,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
__version__ = "0.1.0"
|
|
12
|
+
__all__ = [
|
|
13
|
+
"Array",
|
|
14
|
+
"DataFrame",
|
|
15
|
+
"roast",
|
|
16
|
+
"vibe_check",
|
|
17
|
+
"chaotic_sort",
|
|
18
|
+
"time_travel",
|
|
19
|
+
"explain_like_im_5",
|
|
20
|
+
"indian_format",
|
|
21
|
+
]
|
kshri/core.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import copy
|
|
2
|
+
|
|
3
|
+
class Array:
|
|
4
|
+
def __init__(self, data):
|
|
5
|
+
self.data = list(data)
|
|
6
|
+
|
|
7
|
+
def __repr__(self):
|
|
8
|
+
return f"kshri.Array({self.data})"
|
|
9
|
+
|
|
10
|
+
def __len__(self):
|
|
11
|
+
return len(self.data)
|
|
12
|
+
|
|
13
|
+
def __getitem__(self, idx):
|
|
14
|
+
return self.data[idx]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class DataFrame:
|
|
18
|
+
def __init__(self, data_dict):
|
|
19
|
+
self.columns = {k: list(v) for k, v in data_dict.items()}
|
|
20
|
+
self._history = []
|
|
21
|
+
|
|
22
|
+
def _save_snapshot(self):
|
|
23
|
+
self._history.append(copy.deepcopy(self.columns))
|
|
24
|
+
|
|
25
|
+
def drop(self, col_name):
|
|
26
|
+
if col_name in self.columns:
|
|
27
|
+
self._save_snapshot()
|
|
28
|
+
del self.columns[col_name]
|
|
29
|
+
return self
|
|
30
|
+
|
|
31
|
+
def __getitem__(self, col_name):
|
|
32
|
+
return Array(self.columns[col_name])
|
|
33
|
+
|
|
34
|
+
def __setitem__(self, col_name, values):
|
|
35
|
+
self._save_snapshot()
|
|
36
|
+
self.columns[col_name] = list(values)
|
|
37
|
+
|
|
38
|
+
def __repr__(self):
|
|
39
|
+
return f"kshri.DataFrame({self.columns})"
|
kshri/crazy.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import random
|
|
2
|
+
import statistics
|
|
3
|
+
from .core import Array, DataFrame
|
|
4
|
+
|
|
5
|
+
def roast(df):
|
|
6
|
+
cols = df.columns if isinstance(df, DataFrame) else df
|
|
7
|
+
if not cols:
|
|
8
|
+
return "Empty dataset? Bold strategy."
|
|
9
|
+
|
|
10
|
+
total_rows = len(next(iter(cols.values())))
|
|
11
|
+
missing = sum(1 for col in cols.values() for val in col if val is None)
|
|
12
|
+
|
|
13
|
+
report = [f"Dataset size: {total_rows} rows."]
|
|
14
|
+
if missing > 0:
|
|
15
|
+
report.append(f"Bro, you have {missing} missing values. Did your cat walk on the keyboard?")
|
|
16
|
+
elif total_rows < 5:
|
|
17
|
+
report.append(f"{total_rows} rows? That's not Big Data, that's a sticky note.")
|
|
18
|
+
else:
|
|
19
|
+
report.append("Actually clean data. Did you fake this dataset?")
|
|
20
|
+
return "\n".join(report)
|
|
21
|
+
|
|
22
|
+
def vibe_check(df):
|
|
23
|
+
cols = df.columns if isinstance(df, DataFrame) else df
|
|
24
|
+
warnings = []
|
|
25
|
+
for name, values in cols.items():
|
|
26
|
+
types = {type(v).__name__ for v in values if v is not None}
|
|
27
|
+
if len(types) > 1:
|
|
28
|
+
warnings.append(f"Column '{name}' has mixed vibes (types: {types}).")
|
|
29
|
+
elif "str" in types and any(str(v).isdigit() for v in values if v is not None):
|
|
30
|
+
warnings.append(f"Column '{name}' has numbers hiding as strings!")
|
|
31
|
+
return "\n".join(warnings) if warnings else "Vibe check passed! All columns look consistent."
|
|
32
|
+
|
|
33
|
+
def chaotic_sort(arr, chaos=True, chaos_rate=0.2):
|
|
34
|
+
data = list(arr.data if isinstance(arr, Array) else arr)
|
|
35
|
+
sorted_data = sorted(data)
|
|
36
|
+
if chaos and len(sorted_data) > 1:
|
|
37
|
+
swaps = max(1, int(len(sorted_data) * chaos_rate))
|
|
38
|
+
for _ in range(swaps):
|
|
39
|
+
i, j = random.sample(range(len(sorted_data)), 2)
|
|
40
|
+
sorted_data[i], sorted_data[j] = sorted_data[j], sorted_data[i]
|
|
41
|
+
return Array(sorted_data)
|
|
42
|
+
|
|
43
|
+
def time_travel(df, steps=1):
|
|
44
|
+
if not isinstance(df, DataFrame):
|
|
45
|
+
raise TypeError("time_travel requires a kshri.DataFrame!")
|
|
46
|
+
for _ in range(steps):
|
|
47
|
+
if df._history:
|
|
48
|
+
df.columns = df._history.pop()
|
|
49
|
+
else:
|
|
50
|
+
print("Cannot travel further back—you are at the beginning of time!")
|
|
51
|
+
break
|
|
52
|
+
return df
|
|
53
|
+
|
|
54
|
+
def explain_like_im_5(arr):
|
|
55
|
+
data = [x for x in (arr.data if isinstance(arr, Array) else arr) if isinstance(x, (int, float))]
|
|
56
|
+
if not data:
|
|
57
|
+
return "There are no numbers here for me to explain!"
|
|
58
|
+
avg = statistics.mean(data)
|
|
59
|
+
med = statistics.median(data)
|
|
60
|
+
high = max(data)
|
|
61
|
+
low = min(data)
|
|
62
|
+
|
|
63
|
+
msg = f"Most numbers sit around {med:.1f} (average is {avg:.1f}). The smallest is {low} and the biggest is {high}."
|
|
64
|
+
if high > med * 3 and med > 0:
|
|
65
|
+
msg += f" Watch out: that massive spike at {high} is pulling your average way up!"
|
|
66
|
+
return msg
|
|
67
|
+
|
|
68
|
+
def indian_format(num_or_arr):
|
|
69
|
+
def _format_one(n):
|
|
70
|
+
s, *dec = f"{n}".split(".")
|
|
71
|
+
neg = s.startswith("-")
|
|
72
|
+
if neg:
|
|
73
|
+
s = s[1:]
|
|
74
|
+
if len(s) > 3:
|
|
75
|
+
last3 = s[-3:]
|
|
76
|
+
rest = s[:-3]
|
|
77
|
+
pairs = []
|
|
78
|
+
while len(rest) > 2:
|
|
79
|
+
pairs.append(rest[-2:])
|
|
80
|
+
rest = rest[:-2]
|
|
81
|
+
if rest:
|
|
82
|
+
pairs.append(rest)
|
|
83
|
+
s = ",".join(reversed(pairs)) + "," + last3
|
|
84
|
+
return ("-" if neg else "") + s + ("." + dec[0] if dec else "")
|
|
85
|
+
|
|
86
|
+
if isinstance(num_or_arr, (Array, list)):
|
|
87
|
+
data = num_or_arr.data if isinstance(num_or_arr, Array) else num_or_arr
|
|
88
|
+
return [_format_one(x) for x in data]
|
|
89
|
+
return _format_one(num_or_arr)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kshri
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Kshri: A fun, lightweight array and dataframe library with personality.
|
|
5
|
+
Author-email: Rishabh <rishabh@example.com>
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.8
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# Kshri
|
|
15
|
+
A lightweight Python data library with personality (`roast`, `time_travel`, `vibe_check`, `indian_format`, and more).
|
|
16
|
+
|
|
17
|
+
## Quickstart
|
|
18
|
+
```python
|
|
19
|
+
from kshri import DataFrame, roast, time_travel, indian_format
|
|
20
|
+
|
|
21
|
+
df = DataFrame({"name": ["Rishabh", "Aman"], "score": [95, None]})
|
|
22
|
+
print(roast(df))
|
|
23
|
+
```
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
kshri/__init__.py,sha256=hwhVdq0nTx6RYWpo7Tv59rVdEbWcgXJMjrHrd4KDoYc,345
|
|
2
|
+
kshri/core.py,sha256=ybnqr7LwqsMyPLWNtNwA5yFb-kT0jLb0wCIj-C_DHnM,949
|
|
3
|
+
kshri/crazy.py,sha256=AIc_do6xSmgPRk0Sfpug_6JYdGiY9ez285X3ENJnXeU,3456
|
|
4
|
+
kshri-0.1.0.dist-info/licenses/LICENSE,sha256=svo-JLQ5Per5z6sHds0miE5xK-ihhztne_8H7OpFyzs,602
|
|
5
|
+
kshri-0.1.0.dist-info/METADATA,sha256=dbA_d6fKiyodPXwLPhG6woWmN-NbfAI6dl9ATFi0uqc,731
|
|
6
|
+
kshri-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
7
|
+
kshri-0.1.0.dist-info/top_level.txt,sha256=0BwQVEHMT8Yt4eRss5BOaSTaPtbMTLeRtorUdN1buQs,6
|
|
8
|
+
kshri-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rishabh
|
|
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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
kshri
|