rgwfuncs 0.0.32__tar.gz → 0.0.34__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.
- {rgwfuncs-0.0.32/src/rgwfuncs.egg-info → rgwfuncs-0.0.34}/PKG-INFO +83 -6
- {rgwfuncs-0.0.32 → rgwfuncs-0.0.34}/README.md +82 -5
- {rgwfuncs-0.0.32 → rgwfuncs-0.0.34}/pyproject.toml +1 -1
- {rgwfuncs-0.0.32 → rgwfuncs-0.0.34}/setup.cfg +1 -1
- {rgwfuncs-0.0.32 → rgwfuncs-0.0.34}/src/rgwfuncs/__init__.py +2 -1
- {rgwfuncs-0.0.32 → rgwfuncs-0.0.34}/src/rgwfuncs/algebra_lib.py +4 -8
- rgwfuncs-0.0.34/src/rgwfuncs/interactive_shell_lib.py +32 -0
- {rgwfuncs-0.0.32 → rgwfuncs-0.0.34/src/rgwfuncs.egg-info}/PKG-INFO +83 -6
- {rgwfuncs-0.0.32 → rgwfuncs-0.0.34}/src/rgwfuncs.egg-info/SOURCES.txt +2 -2
- rgwfuncs-0.0.32/tests/test_algebra_lib.py +0 -144
- {rgwfuncs-0.0.32 → rgwfuncs-0.0.34}/LICENSE +0 -0
- {rgwfuncs-0.0.32 → rgwfuncs-0.0.34}/src/rgwfuncs/df_lib.py +0 -0
- {rgwfuncs-0.0.32 → rgwfuncs-0.0.34}/src/rgwfuncs/docs_lib.py +0 -0
- {rgwfuncs-0.0.32 → rgwfuncs-0.0.34}/src/rgwfuncs/str_lib.py +0 -0
- {rgwfuncs-0.0.32 → rgwfuncs-0.0.34}/src/rgwfuncs.egg-info/dependency_links.txt +0 -0
- {rgwfuncs-0.0.32 → rgwfuncs-0.0.34}/src/rgwfuncs.egg-info/entry_points.txt +0 -0
- {rgwfuncs-0.0.32 → rgwfuncs-0.0.34}/src/rgwfuncs.egg-info/requires.txt +0 -0
- {rgwfuncs-0.0.32 → rgwfuncs-0.0.34}/src/rgwfuncs.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: rgwfuncs
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.34
|
4
4
|
Summary: A functional programming paradigm for mathematical modelling and data science
|
5
5
|
Home-page: https://github.com/ryangerardwilson/rgwfunc
|
6
6
|
Author: Ryan Gerard Wilson
|
@@ -150,11 +150,88 @@ Print a list of available function names in alphabetical order. If a filter is p
|
|
150
150
|
|
151
151
|
--------------------------------------------------------------------------------
|
152
152
|
|
153
|
+
## Interactive Shell Function
|
154
|
+
|
155
|
+
This section includes functions that facilitate launching an interactive Python shell to inspect and modify local variables within the user's environment.
|
156
|
+
|
157
|
+
### 1. `interactive_shell`
|
158
|
+
|
159
|
+
#### Usage
|
160
|
+
|
161
|
+
Launches an interactive prompt for inspecting and modifying local variables, making all methods in the rgwfuncs library available by default. This REPL (Read-Eval-Print Loop) environment supports command history and autocompletion, making it easier to interact with your Python code.
|
162
|
+
|
163
|
+
• Parameters:
|
164
|
+
- `local_vars` (dict, optional): A dictionary of local variables to be accessible within the interactive shell. If not provided, defaults to an empty dictionary.
|
165
|
+
|
166
|
+
• Usage:
|
167
|
+
- You can call this function to enter an interactive shell where you can view and modify the variables in the given local scope.
|
168
|
+
|
169
|
+
• Example:
|
170
|
+
|
171
|
+
from rgwfuncs import interactive_shell
|
172
|
+
import pandas as pd
|
173
|
+
import numpy as np
|
174
|
+
|
175
|
+
# Example DataFrame
|
176
|
+
df = pd.DataFrame({
|
177
|
+
'id': [1, 2, 3, 4, 5],
|
178
|
+
'name': ['Alice', 'Bob', 'Charlie', 'David', 'Eva'],
|
179
|
+
'age': [30, 25, 35, 28, 22],
|
180
|
+
'city': ['New York', 'Los Angeles', 'Chicago', 'San Francisco', 'Boston']
|
181
|
+
})
|
182
|
+
|
183
|
+
# Function to retrieve the first n rows of a DataFrame
|
184
|
+
def first_n_rows(df, n):
|
185
|
+
return df.head(n).to_dict('records')
|
186
|
+
|
187
|
+
# Launch the interactive shell with local variables
|
188
|
+
interactive_shell(locals())
|
189
|
+
|
190
|
+
- Once in the interactive shell, you are greeted with a welcome message. You can access the variables defined in the local scope where `interactive_shell(locals())` was called, including any imported modules such as `pandas` (accessed as `pd`) and `numpy` (accessed as `np`). This means you can directly use these modules in the interactive session. Type `exit()` to quit the shell.
|
191
|
+
|
192
|
+
#### Interactive Shell Example Sessions
|
193
|
+
|
194
|
+
1. DataFrame Inspection with Pandas:
|
195
|
+
|
196
|
+
Welcome to the rgwfuncs interactive shell.
|
197
|
+
>>> pirst_n_rows(df, 2)
|
198
|
+
Traceback (most recent call last):
|
199
|
+
File "<console>", line 1, in <module>
|
200
|
+
NameError: name 'pirst_n_rows' is not defined. Did you mean: 'first_n_rows'?
|
201
|
+
>>> first_n_rows(df, 2)
|
202
|
+
{'age': '30', 'city': 'New York', 'id': '1', 'name': 'Alice'}
|
203
|
+
{'age': '25', 'city': 'Los Angeles', 'id': '2', 'name': 'Bob'}
|
204
|
+
>>> print(df)
|
205
|
+
id name age city
|
206
|
+
0 1 Alice 30 New York
|
207
|
+
1 2 Bob 25 Los Angeles
|
208
|
+
2 3 Charlie 35 Chicago
|
209
|
+
3 4 David 28 San Francisco
|
210
|
+
4 5 Eva 22 Boston
|
211
|
+
|
212
|
+
2. Array Operations with NumPy:
|
213
|
+
|
214
|
+
Welcome to the rgwfuncs interactive shell.
|
215
|
+
>>> arr = np.array([1, 2, 3, 4, 5])
|
216
|
+
>>> arr
|
217
|
+
array([1, 2, 3, 4, 5])
|
218
|
+
|
219
|
+
These examples illustrate how you can use functions and variables within the interactive shell, handle errors with meaningful suggestions, and perform operations using external libraries like pandas and numpy.
|
220
|
+
|
221
|
+
#### Key Features
|
222
|
+
|
223
|
+
- Autocompletion: Uses the `rlcompleter` library to provide tab-completion of variables and functions names, enhancing ease of use.
|
224
|
+
- History Support: Utilizes `readline` for command-line history, allowing you to navigate through previous commands using the arrow keys.
|
225
|
+
|
226
|
+
This function is particularly useful for debugging purposes when you want real-time interaction with your program's execution environment.
|
227
|
+
|
228
|
+
--------------------------------------------------------------------------------
|
229
|
+
|
153
230
|
## Algebra Based Functions
|
154
231
|
|
155
232
|
This section provides comprehensive functions for handling algebraic expressions, performing tasks such as computation, simplification, solving equations, and prime factorization, all outputted in LaTeX format.
|
156
233
|
|
157
|
-
### 1. `
|
234
|
+
### 1. `compute_prime_factors`
|
158
235
|
|
159
236
|
Computes prime factors of a number and presents them in LaTeX format.
|
160
237
|
|
@@ -166,14 +243,14 @@ Computes prime factors of a number and presents them in LaTeX format.
|
|
166
243
|
|
167
244
|
• Example:
|
168
245
|
|
169
|
-
from rgwfuncs import
|
170
|
-
factors_1 =
|
246
|
+
from rgwfuncs import compute_prime_factors
|
247
|
+
factors_1 = compute_prime_factors(100)
|
171
248
|
print(factors_1) # Output: "2^{2} \cdot 5^{2}"
|
172
249
|
|
173
|
-
factors_2 =
|
250
|
+
factors_2 = compute_prime_factors(60)
|
174
251
|
print(factors_2) # Output: "2^{2} \cdot 3 \cdot 5"
|
175
252
|
|
176
|
-
factors_3 =
|
253
|
+
factors_3 = compute_prime_factors(17)
|
177
254
|
print(factors_3) # Output: "17"
|
178
255
|
|
179
256
|
--------------------------------------------------------------------------------
|
@@ -124,11 +124,88 @@ Print a list of available function names in alphabetical order. If a filter is p
|
|
124
124
|
|
125
125
|
--------------------------------------------------------------------------------
|
126
126
|
|
127
|
+
## Interactive Shell Function
|
128
|
+
|
129
|
+
This section includes functions that facilitate launching an interactive Python shell to inspect and modify local variables within the user's environment.
|
130
|
+
|
131
|
+
### 1. `interactive_shell`
|
132
|
+
|
133
|
+
#### Usage
|
134
|
+
|
135
|
+
Launches an interactive prompt for inspecting and modifying local variables, making all methods in the rgwfuncs library available by default. This REPL (Read-Eval-Print Loop) environment supports command history and autocompletion, making it easier to interact with your Python code.
|
136
|
+
|
137
|
+
• Parameters:
|
138
|
+
- `local_vars` (dict, optional): A dictionary of local variables to be accessible within the interactive shell. If not provided, defaults to an empty dictionary.
|
139
|
+
|
140
|
+
• Usage:
|
141
|
+
- You can call this function to enter an interactive shell where you can view and modify the variables in the given local scope.
|
142
|
+
|
143
|
+
• Example:
|
144
|
+
|
145
|
+
from rgwfuncs import interactive_shell
|
146
|
+
import pandas as pd
|
147
|
+
import numpy as np
|
148
|
+
|
149
|
+
# Example DataFrame
|
150
|
+
df = pd.DataFrame({
|
151
|
+
'id': [1, 2, 3, 4, 5],
|
152
|
+
'name': ['Alice', 'Bob', 'Charlie', 'David', 'Eva'],
|
153
|
+
'age': [30, 25, 35, 28, 22],
|
154
|
+
'city': ['New York', 'Los Angeles', 'Chicago', 'San Francisco', 'Boston']
|
155
|
+
})
|
156
|
+
|
157
|
+
# Function to retrieve the first n rows of a DataFrame
|
158
|
+
def first_n_rows(df, n):
|
159
|
+
return df.head(n).to_dict('records')
|
160
|
+
|
161
|
+
# Launch the interactive shell with local variables
|
162
|
+
interactive_shell(locals())
|
163
|
+
|
164
|
+
- Once in the interactive shell, you are greeted with a welcome message. You can access the variables defined in the local scope where `interactive_shell(locals())` was called, including any imported modules such as `pandas` (accessed as `pd`) and `numpy` (accessed as `np`). This means you can directly use these modules in the interactive session. Type `exit()` to quit the shell.
|
165
|
+
|
166
|
+
#### Interactive Shell Example Sessions
|
167
|
+
|
168
|
+
1. DataFrame Inspection with Pandas:
|
169
|
+
|
170
|
+
Welcome to the rgwfuncs interactive shell.
|
171
|
+
>>> pirst_n_rows(df, 2)
|
172
|
+
Traceback (most recent call last):
|
173
|
+
File "<console>", line 1, in <module>
|
174
|
+
NameError: name 'pirst_n_rows' is not defined. Did you mean: 'first_n_rows'?
|
175
|
+
>>> first_n_rows(df, 2)
|
176
|
+
{'age': '30', 'city': 'New York', 'id': '1', 'name': 'Alice'}
|
177
|
+
{'age': '25', 'city': 'Los Angeles', 'id': '2', 'name': 'Bob'}
|
178
|
+
>>> print(df)
|
179
|
+
id name age city
|
180
|
+
0 1 Alice 30 New York
|
181
|
+
1 2 Bob 25 Los Angeles
|
182
|
+
2 3 Charlie 35 Chicago
|
183
|
+
3 4 David 28 San Francisco
|
184
|
+
4 5 Eva 22 Boston
|
185
|
+
|
186
|
+
2. Array Operations with NumPy:
|
187
|
+
|
188
|
+
Welcome to the rgwfuncs interactive shell.
|
189
|
+
>>> arr = np.array([1, 2, 3, 4, 5])
|
190
|
+
>>> arr
|
191
|
+
array([1, 2, 3, 4, 5])
|
192
|
+
|
193
|
+
These examples illustrate how you can use functions and variables within the interactive shell, handle errors with meaningful suggestions, and perform operations using external libraries like pandas and numpy.
|
194
|
+
|
195
|
+
#### Key Features
|
196
|
+
|
197
|
+
- Autocompletion: Uses the `rlcompleter` library to provide tab-completion of variables and functions names, enhancing ease of use.
|
198
|
+
- History Support: Utilizes `readline` for command-line history, allowing you to navigate through previous commands using the arrow keys.
|
199
|
+
|
200
|
+
This function is particularly useful for debugging purposes when you want real-time interaction with your program's execution environment.
|
201
|
+
|
202
|
+
--------------------------------------------------------------------------------
|
203
|
+
|
127
204
|
## Algebra Based Functions
|
128
205
|
|
129
206
|
This section provides comprehensive functions for handling algebraic expressions, performing tasks such as computation, simplification, solving equations, and prime factorization, all outputted in LaTeX format.
|
130
207
|
|
131
|
-
### 1. `
|
208
|
+
### 1. `compute_prime_factors`
|
132
209
|
|
133
210
|
Computes prime factors of a number and presents them in LaTeX format.
|
134
211
|
|
@@ -140,14 +217,14 @@ Computes prime factors of a number and presents them in LaTeX format.
|
|
140
217
|
|
141
218
|
• Example:
|
142
219
|
|
143
|
-
from rgwfuncs import
|
144
|
-
factors_1 =
|
220
|
+
from rgwfuncs import compute_prime_factors
|
221
|
+
factors_1 = compute_prime_factors(100)
|
145
222
|
print(factors_1) # Output: "2^{2} \cdot 5^{2}"
|
146
223
|
|
147
|
-
factors_2 =
|
224
|
+
factors_2 = compute_prime_factors(60)
|
148
225
|
print(factors_2) # Output: "2^{2} \cdot 3 \cdot 5"
|
149
226
|
|
150
|
-
factors_3 =
|
227
|
+
factors_3 = compute_prime_factors(17)
|
151
228
|
print(factors_3) # Output: "17"
|
152
229
|
|
153
230
|
--------------------------------------------------------------------------------
|
@@ -1,7 +1,8 @@
|
|
1
1
|
# This file is automatically generated
|
2
2
|
# Dynamically importing functions from modules
|
3
3
|
|
4
|
-
from .algebra_lib import compute_constant_expression, compute_constant_expression_involving_matrices, compute_constant_expression_involving_ordered_series,
|
4
|
+
from .algebra_lib import compute_constant_expression, compute_constant_expression_involving_matrices, compute_constant_expression_involving_ordered_series, compute_prime_factors, python_polynomial_expression_to_latex, simplify_polynomial_expression, solve_homogeneous_polynomial_expression
|
5
5
|
from .df_lib import append_columns, append_percentile_classification_column, append_ranged_classification_column, append_ranged_date_classification_column, append_rows, append_xgb_labels, append_xgb_logistic_regression_predictions, append_xgb_regression_predictions, bag_union_join, bottom_n_unique_values, cascade_sort, delete_rows, drop_duplicates, drop_duplicates_retain_first, drop_duplicates_retain_last, filter_dataframe, filter_indian_mobiles, first_n_rows, from_raw_data, insert_dataframe_in_sqlite_database, last_n_rows, left_join, limit_dataframe, load_data_from_path, load_data_from_query, load_data_from_sqlite_path, mask_against_dataframe, mask_against_dataframe_converse, numeric_clean, order_columns, print_correlation, print_dataframe, print_memory_usage, print_n_frequency_cascading, print_n_frequency_linear, rename_columns, retain_columns, right_join, send_data_to_email, send_data_to_slack, send_dataframe_via_telegram, sync_dataframe_to_sqlite_database, top_n_unique_values, union_join, update_rows
|
6
6
|
from .docs_lib import docs
|
7
|
+
from .interactive_shell_lib import interactive_shell
|
7
8
|
from .str_lib import send_telegram_message
|
@@ -10,7 +10,7 @@ from sympy.parsing.sympy_parser import (standard_transformations, implicit_multi
|
|
10
10
|
from typing import Tuple, List, Dict, Optional
|
11
11
|
|
12
12
|
|
13
|
-
def
|
13
|
+
def compute_prime_factors(n: int) -> str:
|
14
14
|
"""
|
15
15
|
Computes the prime factors of a number and returns the factorization as a LaTeX string.
|
16
16
|
|
@@ -76,7 +76,7 @@ def compute_constant_expression_involving_matrices(expression: str) -> str:
|
|
76
76
|
Computes the result of a constant expression involving matrices and returns it as a LaTeX string.
|
77
77
|
|
78
78
|
Parameters:
|
79
|
-
expression (str): The constant expression involving matrices. Example format includes operations such as "+",
|
79
|
+
expression (str): The constant expression involving matrices. Example format includes operations such as "+",
|
80
80
|
"-", "*", "/".
|
81
81
|
|
82
82
|
Returns:
|
@@ -161,9 +161,9 @@ def compute_constant_expression_involving_matrices(expression: str) -> str:
|
|
161
161
|
|
162
162
|
def compute_constant_expression_involving_ordered_series(expression: str) -> str:
|
163
163
|
"""
|
164
|
-
Computes the result of a constant expression involving ordered series, and returns it as a Latex string.
|
164
|
+
Computes the result of a constant expression involving ordered series, and returns it as a Latex string.
|
165
165
|
Supports operations lile "+", "-", "*", "/", as well as "dd()" (the discrete difference operator).
|
166
|
-
|
166
|
+
|
167
167
|
The function first applies the discrete difference operator to any series where applicable, then evaluates
|
168
168
|
arithmetic operations between series.
|
169
169
|
|
@@ -261,8 +261,6 @@ def compute_constant_expression_involving_ordered_series(expression: str) -> str
|
|
261
261
|
return f"Error computing ordered series operation: {e}"
|
262
262
|
|
263
263
|
|
264
|
-
|
265
|
-
|
266
264
|
def python_polynomial_expression_to_latex(
|
267
265
|
expression: str,
|
268
266
|
subs: Optional[Dict[str, float]] = None
|
@@ -549,5 +547,3 @@ def solve_homogeneous_polynomial_expression(
|
|
549
547
|
|
550
548
|
except Exception as e:
|
551
549
|
raise ValueError(f"Error solving the expression: {e}")
|
552
|
-
|
553
|
-
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import code
|
2
|
+
import readline
|
3
|
+
import rlcompleter # noqa: F401
|
4
|
+
import sys # noqa: F401
|
5
|
+
from typing import Dict, Any
|
6
|
+
from .df_lib import * # noqa: F401, F403, E402
|
7
|
+
from .algebra_lib import * # noqa: F401, F403, E402
|
8
|
+
from .str_lib import * # noqa: F401, F403, E402
|
9
|
+
from .docs_lib import * # noqa: F401, F403, E402
|
10
|
+
|
11
|
+
|
12
|
+
def interactive_shell(local_vars: Dict[str, Any]) -> None:
|
13
|
+
"""
|
14
|
+
Launches an interactive prompt for inspecting and modifying local variables, making all methods
|
15
|
+
in the rgwfuncs library available by default.
|
16
|
+
|
17
|
+
Parameters:
|
18
|
+
local_vars (dict): Dictionary of local variables to be available in the interactive shell.
|
19
|
+
"""
|
20
|
+
if not isinstance(local_vars, dict):
|
21
|
+
raise TypeError("local_vars must be a dictionary")
|
22
|
+
|
23
|
+
readline.parse_and_bind("tab: complete")
|
24
|
+
|
25
|
+
# Make imported functions available in the REPL
|
26
|
+
local_vars.update(globals())
|
27
|
+
|
28
|
+
# Create interactive console with local context
|
29
|
+
console = code.InteractiveConsole(locals=local_vars)
|
30
|
+
|
31
|
+
# Start interactive session
|
32
|
+
console.interact(banner="Welcome to the rgwfuncs interactive shell.")
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: rgwfuncs
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.34
|
4
4
|
Summary: A functional programming paradigm for mathematical modelling and data science
|
5
5
|
Home-page: https://github.com/ryangerardwilson/rgwfunc
|
6
6
|
Author: Ryan Gerard Wilson
|
@@ -150,11 +150,88 @@ Print a list of available function names in alphabetical order. If a filter is p
|
|
150
150
|
|
151
151
|
--------------------------------------------------------------------------------
|
152
152
|
|
153
|
+
## Interactive Shell Function
|
154
|
+
|
155
|
+
This section includes functions that facilitate launching an interactive Python shell to inspect and modify local variables within the user's environment.
|
156
|
+
|
157
|
+
### 1. `interactive_shell`
|
158
|
+
|
159
|
+
#### Usage
|
160
|
+
|
161
|
+
Launches an interactive prompt for inspecting and modifying local variables, making all methods in the rgwfuncs library available by default. This REPL (Read-Eval-Print Loop) environment supports command history and autocompletion, making it easier to interact with your Python code.
|
162
|
+
|
163
|
+
• Parameters:
|
164
|
+
- `local_vars` (dict, optional): A dictionary of local variables to be accessible within the interactive shell. If not provided, defaults to an empty dictionary.
|
165
|
+
|
166
|
+
• Usage:
|
167
|
+
- You can call this function to enter an interactive shell where you can view and modify the variables in the given local scope.
|
168
|
+
|
169
|
+
• Example:
|
170
|
+
|
171
|
+
from rgwfuncs import interactive_shell
|
172
|
+
import pandas as pd
|
173
|
+
import numpy as np
|
174
|
+
|
175
|
+
# Example DataFrame
|
176
|
+
df = pd.DataFrame({
|
177
|
+
'id': [1, 2, 3, 4, 5],
|
178
|
+
'name': ['Alice', 'Bob', 'Charlie', 'David', 'Eva'],
|
179
|
+
'age': [30, 25, 35, 28, 22],
|
180
|
+
'city': ['New York', 'Los Angeles', 'Chicago', 'San Francisco', 'Boston']
|
181
|
+
})
|
182
|
+
|
183
|
+
# Function to retrieve the first n rows of a DataFrame
|
184
|
+
def first_n_rows(df, n):
|
185
|
+
return df.head(n).to_dict('records')
|
186
|
+
|
187
|
+
# Launch the interactive shell with local variables
|
188
|
+
interactive_shell(locals())
|
189
|
+
|
190
|
+
- Once in the interactive shell, you are greeted with a welcome message. You can access the variables defined in the local scope where `interactive_shell(locals())` was called, including any imported modules such as `pandas` (accessed as `pd`) and `numpy` (accessed as `np`). This means you can directly use these modules in the interactive session. Type `exit()` to quit the shell.
|
191
|
+
|
192
|
+
#### Interactive Shell Example Sessions
|
193
|
+
|
194
|
+
1. DataFrame Inspection with Pandas:
|
195
|
+
|
196
|
+
Welcome to the rgwfuncs interactive shell.
|
197
|
+
>>> pirst_n_rows(df, 2)
|
198
|
+
Traceback (most recent call last):
|
199
|
+
File "<console>", line 1, in <module>
|
200
|
+
NameError: name 'pirst_n_rows' is not defined. Did you mean: 'first_n_rows'?
|
201
|
+
>>> first_n_rows(df, 2)
|
202
|
+
{'age': '30', 'city': 'New York', 'id': '1', 'name': 'Alice'}
|
203
|
+
{'age': '25', 'city': 'Los Angeles', 'id': '2', 'name': 'Bob'}
|
204
|
+
>>> print(df)
|
205
|
+
id name age city
|
206
|
+
0 1 Alice 30 New York
|
207
|
+
1 2 Bob 25 Los Angeles
|
208
|
+
2 3 Charlie 35 Chicago
|
209
|
+
3 4 David 28 San Francisco
|
210
|
+
4 5 Eva 22 Boston
|
211
|
+
|
212
|
+
2. Array Operations with NumPy:
|
213
|
+
|
214
|
+
Welcome to the rgwfuncs interactive shell.
|
215
|
+
>>> arr = np.array([1, 2, 3, 4, 5])
|
216
|
+
>>> arr
|
217
|
+
array([1, 2, 3, 4, 5])
|
218
|
+
|
219
|
+
These examples illustrate how you can use functions and variables within the interactive shell, handle errors with meaningful suggestions, and perform operations using external libraries like pandas and numpy.
|
220
|
+
|
221
|
+
#### Key Features
|
222
|
+
|
223
|
+
- Autocompletion: Uses the `rlcompleter` library to provide tab-completion of variables and functions names, enhancing ease of use.
|
224
|
+
- History Support: Utilizes `readline` for command-line history, allowing you to navigate through previous commands using the arrow keys.
|
225
|
+
|
226
|
+
This function is particularly useful for debugging purposes when you want real-time interaction with your program's execution environment.
|
227
|
+
|
228
|
+
--------------------------------------------------------------------------------
|
229
|
+
|
153
230
|
## Algebra Based Functions
|
154
231
|
|
155
232
|
This section provides comprehensive functions for handling algebraic expressions, performing tasks such as computation, simplification, solving equations, and prime factorization, all outputted in LaTeX format.
|
156
233
|
|
157
|
-
### 1. `
|
234
|
+
### 1. `compute_prime_factors`
|
158
235
|
|
159
236
|
Computes prime factors of a number and presents them in LaTeX format.
|
160
237
|
|
@@ -166,14 +243,14 @@ Computes prime factors of a number and presents them in LaTeX format.
|
|
166
243
|
|
167
244
|
• Example:
|
168
245
|
|
169
|
-
from rgwfuncs import
|
170
|
-
factors_1 =
|
246
|
+
from rgwfuncs import compute_prime_factors
|
247
|
+
factors_1 = compute_prime_factors(100)
|
171
248
|
print(factors_1) # Output: "2^{2} \cdot 5^{2}"
|
172
249
|
|
173
|
-
factors_2 =
|
250
|
+
factors_2 = compute_prime_factors(60)
|
174
251
|
print(factors_2) # Output: "2^{2} \cdot 3 \cdot 5"
|
175
252
|
|
176
|
-
factors_3 =
|
253
|
+
factors_3 = compute_prime_factors(17)
|
177
254
|
print(factors_3) # Output: "17"
|
178
255
|
|
179
256
|
--------------------------------------------------------------------------------
|
@@ -6,11 +6,11 @@ src/rgwfuncs/__init__.py
|
|
6
6
|
src/rgwfuncs/algebra_lib.py
|
7
7
|
src/rgwfuncs/df_lib.py
|
8
8
|
src/rgwfuncs/docs_lib.py
|
9
|
+
src/rgwfuncs/interactive_shell_lib.py
|
9
10
|
src/rgwfuncs/str_lib.py
|
10
11
|
src/rgwfuncs.egg-info/PKG-INFO
|
11
12
|
src/rgwfuncs.egg-info/SOURCES.txt
|
12
13
|
src/rgwfuncs.egg-info/dependency_links.txt
|
13
14
|
src/rgwfuncs.egg-info/entry_points.txt
|
14
15
|
src/rgwfuncs.egg-info/requires.txt
|
15
|
-
src/rgwfuncs.egg-info/top_level.txt
|
16
|
-
tests/test_algebra_lib.py
|
16
|
+
src/rgwfuncs.egg-info/top_level.txt
|
@@ -1,144 +0,0 @@
|
|
1
|
-
import sys
|
2
|
-
import os
|
3
|
-
import math
|
4
|
-
|
5
|
-
# flake8: noqa: E402
|
6
|
-
# Allow the following import statement to be AFTER sys.path modifications
|
7
|
-
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
8
|
-
|
9
|
-
from src.rgwfuncs.algebra_lib import (
|
10
|
-
compute_prime_factors_latex,
|
11
|
-
compute_constant_expression,
|
12
|
-
compute_constant_expression_involving_matrices,
|
13
|
-
compute_constant_expression_involving_ordered_series,
|
14
|
-
python_polynomial_expression_to_latex,
|
15
|
-
simplify_polynomial_expression,
|
16
|
-
solve_homogeneous_polynomial_expression)
|
17
|
-
|
18
|
-
|
19
|
-
def test_compute_prime_factors_latex():
|
20
|
-
test_cases = [
|
21
|
-
(100, "2^{2} \\cdot 5^{2}"),
|
22
|
-
(60, "2^{2} \\cdot 3 \\cdot 5"),
|
23
|
-
(45, "3^{2} \\cdot 5"),
|
24
|
-
(1, ""), # Handle case with 1, which has no prime factors
|
25
|
-
(17, "17") # Prime number itself
|
26
|
-
]
|
27
|
-
|
28
|
-
for n, expected_output in test_cases:
|
29
|
-
result = compute_prime_factors_latex(n)
|
30
|
-
assert result == expected_output, f"Failed for {n}, got {result}"
|
31
|
-
|
32
|
-
|
33
|
-
def test_compute_constant_expression():
|
34
|
-
test_cases = [
|
35
|
-
("2 + 2", 4.0),
|
36
|
-
("5 - 3", 2.0),
|
37
|
-
("3 * 3", 9.0),
|
38
|
-
("8 / 2", 4.0),
|
39
|
-
("10 % 3", 1.0),
|
40
|
-
("math.gcd(36, 60) * math.sin(math.radians(45)) * 10000", 84852.8137423857),
|
41
|
-
# ("np.diff([2,6,9,60])", r"\left[\begin{matrix}4\\3\\51\end{matrix}\right]"),
|
42
|
-
]
|
43
|
-
|
44
|
-
for input_data, expected_output in test_cases:
|
45
|
-
result = compute_constant_expression(input_data)
|
46
|
-
assert math.isclose(result, expected_output, rel_tol=1e-9), f"Failed for {input_data}, got {result}"
|
47
|
-
|
48
|
-
def test_compute_constant_expression_involving_matrices():
|
49
|
-
test_cases = [
|
50
|
-
("[[2, 6, 9],[1, 3, 5]] + [[1, 2, 3],[4, 5, 6]]", r"\begin{bmatrix}3 & 8 & 12\\5 & 8 & 11\end{bmatrix}"),
|
51
|
-
("[[10, 10, 10],[2, 4, 6]] - [[5, 3, 2],[1, 2, 1]]", r"\begin{bmatrix}5 & 7 & 8\\1 & 2 & 5\end{bmatrix}"),
|
52
|
-
("[[2, 4],[6, 8]] * [[1, 0.5],[2, 0.25]]", r"\begin{bmatrix}2 & 2.0\\12 & 2.0\end{bmatrix}"),
|
53
|
-
("[[8, 16],[32, 64]] / [[2, 2],[8, 16]]", r"\begin{bmatrix}4.0 & 8.0\\4.0 & 4.0\end{bmatrix}"),
|
54
|
-
("[[2, 6, 9], [1, 3, 5]] + [[1, 2, 3], [4, 5, 6]] - [[1, 1, 1], [1, 1, 1]]", r"\begin{bmatrix}2 & 7 & 11\\4 & 7 & 10\end{bmatrix}"),
|
55
|
-
("[2, 6, 9] + [1, 2, 3] - [1, 1, 1]", r"\begin{bmatrix}2 & 7 & 11\end{bmatrix}"),
|
56
|
-
("[[1, 2], [3, 4]] + [[2, 3], [4, 5]] + [[1, 1], [1, 1]]", r"\begin{bmatrix}4 & 6\\8 & 10\end{bmatrix}"),
|
57
|
-
("[3, 6, 9] - [1, 2, 3] + [5, 5, 5]", r"\begin{bmatrix}7 & 9 & 11\end{bmatrix}"),
|
58
|
-
("[3, 6, 9] - [1, 2, 3, 4]", r"Operations between matrices must involve matrices of the same dimension"),
|
59
|
-
|
60
|
-
# Edge cases
|
61
|
-
("[]", r"\begin{bmatrix}\end{bmatrix}"), # Empty list
|
62
|
-
("[5]", r"\begin{bmatrix}5\end{bmatrix}"), # Single-element list
|
63
|
-
]
|
64
|
-
|
65
|
-
for input_data, expected_output in test_cases:
|
66
|
-
result = compute_constant_expression_involving_matrices(input_data)
|
67
|
-
assert result == expected_output, f"Failed for {input_data}, got {result}"
|
68
|
-
|
69
|
-
# Example test function
|
70
|
-
|
71
|
-
|
72
|
-
def test_compute_constant_expression_involving_ordered_series():
|
73
|
-
test_cases = [
|
74
|
-
("[2, 6, 9] + [1, 2, 3]", "[3, 8, 12]"),
|
75
|
-
("[10, 15, 21] - [5, 5, 5]", "[5, 10, 16]"),
|
76
|
-
("[2, 4, 6] * [1, 2, 3]", "[2, 8, 18]"),
|
77
|
-
("[8, 16, 32] / [2, 2, 8]", "[4.0, 8.0, 4.0]"),
|
78
|
-
("dd([2, 6, 9, 60]) + dd([78, 79, 80])", "Operations between ordered series must involve series of equal length"),
|
79
|
-
("dd([1, 3, 6, 10]) - dd([0, 1, 1, 2])", "[1, 3, 3]"),
|
80
|
-
|
81
|
-
# Edge cases
|
82
|
-
("dd([1])", "[]"), # Single-element list, becomes empty
|
83
|
-
("dd([])", "[]"), # Empty list case
|
84
|
-
("[5]", "[5]"), # Single-element list, unchanged
|
85
|
-
("[]", "[]"), # Empty list
|
86
|
-
("[4, 3, 51] + [1, 1]", "Operations between ordered series must involve series of equal length"), # Test unequal lengths
|
87
|
-
]
|
88
|
-
|
89
|
-
for input_data, expected_output in test_cases:
|
90
|
-
result = compute_constant_expression_involving_ordered_series(input_data)
|
91
|
-
assert result == expected_output, f"Failed for {input_data}, got {result}"
|
92
|
-
|
93
|
-
|
94
|
-
def test_python_polynomial_expression_to_latex():
|
95
|
-
test_cases = [
|
96
|
-
# Without substitutions
|
97
|
-
("x**2 + y**2", None, r"x^{2} + y^{2}"),
|
98
|
-
("3*a + 4*b", None, r"3 a + 4 b"),
|
99
|
-
("3*x**3 / (7*y*m**(n+2) + 103)", None, r"\frac{3 x^{3}}{7 m^{n + 2} y + 103}"),
|
100
|
-
|
101
|
-
# With substitutions
|
102
|
-
("x**2 + y**2", {"x": 3, "y": 4}, r"25"),
|
103
|
-
("x**2 + y**2", {"x": 3}, r"y^{2} + 9"),
|
104
|
-
("a*b + b", {"b": 2}, r"2 a + 2"),
|
105
|
-
("sin(x+z**2) + cos(y)", {"x": 55}, r"cos y + sin \left(z^{2} + 55\right)"),
|
106
|
-
("sin(x) + cos(y)", {"x": 0}, r"cos y")
|
107
|
-
]
|
108
|
-
|
109
|
-
for expression, subs, expected_output in test_cases:
|
110
|
-
output = python_polynomial_expression_to_latex(expression, subs)
|
111
|
-
assert output == expected_output, (
|
112
|
-
f"Test failed for expression: {expression} with substitutions: {subs}. "
|
113
|
-
f"Expected {expected_output}, got {output}"
|
114
|
-
)
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
def test_simplify_polynomial_expression():
|
119
|
-
test_cases = [
|
120
|
-
# Without substitutions
|
121
|
-
(("(np.diff(3*x**8)) / (np.diff(8*x**30) * 11*y**3)", None), r"\frac{1}{110 x^{22} y^{3}}"),
|
122
|
-
|
123
|
-
# With substitutions
|
124
|
-
(("x**2 + y**2", {"x": 3, "y": 4}), "25"),
|
125
|
-
(("a*b + b", {"b": 2}), r"2 a + 2"), # Assumes no simplification of `a*b`
|
126
|
-
(("(x**2 + y**2 + z**2)", {"x": 1, "y": 0, "z": 0}), "1")
|
127
|
-
]
|
128
|
-
|
129
|
-
for (expression, subs), expected_output in test_cases:
|
130
|
-
output = simplify_polynomial_expression(expression, subs)
|
131
|
-
assert output == expected_output, (f"Test failed for expression: {expression} with substitutions: {subs}. Expected {expected_output}, got {output}")
|
132
|
-
|
133
|
-
|
134
|
-
def test_solve_homogeneous_polynomial_expression():
|
135
|
-
test_cases = [
|
136
|
-
# Test case with substitutions
|
137
|
-
(("a*x**2 + b*x + c", "x", {"a": 3, "b": 7, "c": 5}), r"\left[-7/6 - sqrt(11)*I/6, -7/6 + sqrt(11)*I/6\right]"),
|
138
|
-
]
|
139
|
-
|
140
|
-
for (expression, variable, subs), expected_output in test_cases:
|
141
|
-
assert solve_homogeneous_polynomial_expression(expression, variable, subs) == expected_output
|
142
|
-
|
143
|
-
|
144
|
-
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|