rgwfuncs 0.0.27__py3-none-any.whl → 0.0.29__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.
rgwfuncs/__init__.py CHANGED
@@ -1,7 +1,7 @@
1
1
  # This file is automatically generated
2
2
  # Dynamically importing functions from modules
3
3
 
4
- from .algebra_lib import compute_algebraic_expression, compute_matrix_operation, compute_ordered_series_operation, get_prime_factors_latex, simplify_algebraic_expression, solve_algebraic_expression
4
+ from .algebra_lib import compute_constant_expression, compute_matrix_expression, compute_ordered_series_expression, get_prime_factors_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
7
  from .str_lib import send_telegram_message
rgwfuncs/algebra_lib.py CHANGED
@@ -7,17 +7,18 @@ from sympy.parsing.sympy_parser import parse_expr
7
7
  from typing import Tuple, List, Dict, Optional
8
8
 
9
9
 
10
- def compute_algebraic_expression(expression: str) -> float:
10
+ def compute_constant_expression(expression: str) -> float:
11
11
  """
12
- Computes the numerical result of a given algebraic expression.
12
+ Computes the numerical result of a given expression, which can evaluate to a constant,
13
+ represented as a float.
13
14
 
14
- Evaluates an algebraic expression provided as a string and returns the computed result.
15
+ Evaluates an constant expression provided as a string and returns the computed result.
15
16
  Supports various arithmetic operations, including addition, subtraction, multiplication,
16
17
  division, and modulo, as well as mathematical functions from the math module.
17
18
 
18
19
  Parameters:
19
- expression (str): The algebraic expression to compute. This should be a string consisting
20
- of arithmetic operations and supported math module functions.
20
+ expression (str): The constant expression to compute. This should be a string consisting
21
+ of arithmetic operations and Python's math module functions.
21
22
 
22
23
  Returns:
23
24
  float: The evaluated numerical result of the expression.
@@ -36,18 +37,29 @@ def compute_algebraic_expression(expression: str) -> float:
36
37
  raise ValueError(f"Error computing expression: {e}")
37
38
 
38
39
 
39
- def simplify_algebraic_expression(expression: str) -> str:
40
+ def simplify_polynomial_expression(
41
+ expression: str,
42
+ subs: Optional[Dict[str, float]] = None
43
+ ) -> str:
40
44
  """
41
- Simplifies an algebraic expression and returns it in LaTeX format.
45
+ Simplifies an algebraic expression in polynomial form and returns it in LaTeX format.
42
46
 
43
- Takes an algebraic expression written in Python syntax and simplifies it. The result is
44
- returned as a LaTeX formatted string, suitable for academic or professional documentation.
47
+ Takes an algebraic expression, in polynomial form, written in Python syntax and simplifies it.
48
+ The result is returned as a LaTeX formatted string, suitable for academic or professional
49
+ documentation.
45
50
 
46
51
  Parameters:
47
- expression (str): The algebraic expression to simplify.
52
+ expression (str): The algebraic expression, in polynomial form, to simplify. For instance,
53
+ the expression `np.diff(8*x**30)` is a polynomial, whereas np.diff([2,5,9,11)
54
+ is not a polynomial.
55
+ subs (Optional[Dict[str, float]]): An optional dictionary of substitutions for variables
56
+ in the expression.
48
57
 
49
58
  Returns:
50
59
  str: The simplified expression represented as a LaTeX string.
60
+
61
+ Raises:
62
+ ValueError: If the expression cannot be simplified due to errors in expression or parameters.
51
63
  """
52
64
 
53
65
  def recursive_parse_function_call(
@@ -178,13 +190,18 @@ def simplify_algebraic_expression(expression: str) -> str:
178
190
  # print("Level 2 processed_expression:", processed_expression)
179
191
 
180
192
  try:
181
- if processed_expression.startswith(
182
- '[') and processed_expression.endswith(']'):
183
- return processed_expression
184
-
193
+ # Parse the expression
185
194
  expr = parse_expr(processed_expression, local_dict=sym_vars)
195
+
196
+ # Apply substitutions if provided
197
+ if subs:
198
+ subs_symbols = {symbols(k): v for k, v in subs.items()}
199
+ expr = expr.subs(subs_symbols)
200
+
201
+ # Simplify the expression
186
202
  final_result = simplify(expr)
187
203
 
204
+ # Convert the result to LaTeX format
188
205
  if final_result.free_symbols:
189
206
  latex_result = latex(final_result)
190
207
  return latex_result
@@ -195,16 +212,21 @@ def simplify_algebraic_expression(expression: str) -> str:
195
212
  raise ValueError(f"Error simplifying expression: {e}")
196
213
 
197
214
 
198
- def solve_algebraic_expression(
199
- expression: str, variable: str, subs: Optional[Dict[str, float]] = None) -> str:
215
+ def solve_homogeneous_polynomial_expression(
216
+ expression: str,
217
+ variable: str,
218
+ subs: Optional[Dict[str, float]] = None
219
+ ) -> str:
200
220
  """
201
- Solves an algebraic equation for a specified variable and returns solutions in LaTeX format.
221
+ Solves a homogeneous polynomial expression for a specified variable and returns solutions
222
+ in LaTeX format.
202
223
 
203
- Solves the given equation for a designated variable. May optionally include substitutions
204
- for other variables in the equation. The solutions are provided as a LaTeX formatted string.
224
+ Assumes that the expression is homoegeneous (i.e. equal to zero), and solves for a
225
+ designated variable. May optionally include substitutions for other variables in the
226
+ equation. The solutions are provided as a LaTeX formatted string.
205
227
 
206
228
  Parameters:
207
- expression (str): The algebraic equation to solve.
229
+ expression (str): The homogeneous polynomial expression to solve.
208
230
  variable (str): The variable to solve the equation for.
209
231
  subs (Optional[Dict[str, float]]): An optional dictionary of substitutions for variables
210
232
  in the equation.
@@ -243,7 +265,7 @@ def solve_algebraic_expression(
243
265
  raise ValueError(f"Error solving the expression: {e}")
244
266
 
245
267
 
246
- def compute_matrix_operation(expression: str) -> str:
268
+ def compute_matrix_expression(expression: str) -> str:
247
269
  """
248
270
  Computes the result of a matrix-like operation on 1D or 2D list inputs and returns it as a LaTeX string.
249
271
 
@@ -333,7 +355,7 @@ def compute_matrix_operation(expression: str) -> str:
333
355
  return f"Error computing matrix operation: {e}"
334
356
 
335
357
 
336
- def compute_ordered_series_operation(expression: str) -> str:
358
+ def compute_ordered_series_expression(expression: str) -> str:
337
359
  """
338
360
  Computes the result of operations on ordered series expressed as 1D lists, including discrete difference (ddd),
339
361
  and returns it as a string.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: rgwfuncs
3
- Version: 0.0.27
3
+ Version: 0.0.29
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
@@ -154,91 +154,97 @@ Print a list of available function names in alphabetical order. If a filter is p
154
154
 
155
155
  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
156
 
157
- ### 1. `compute_algebraic_expression`
157
+ ### 1. `compute_constant_expression`
158
158
 
159
- Evaluates complex algebraic expressions and provides numerical results.
159
+ Computes the numerical result of a given expression, which can evaluate to a constant, represented as a float. Evaluates an constant expression provided as a string and returns the computed result. Supports various arithmetic operations, including addition, subtraction, multiplication, division, and modulo, as well as mathematical functions from the math module.
160
160
 
161
- - **Parameters:**
162
- - `expression` (str): A string representing an arithmetic operation.
161
+ Parameters:
162
+ - `expression` (str): The constant expression to compute. This should be a string consisting of arithmetic operations and Python's math module functions.
163
163
 
164
- - **Returns:**
164
+ Returns:
165
165
  - `float`: The computed numerical result.
166
166
 
167
- - **Example:**
167
+ Example:
168
168
 
169
- from rgwfuncs import compute_algebraic_expression
170
- result1 = compute_algebraic_expression("2 + 2")
169
+ from rgwfuncs import compute_constant_expression
170
+ result1 = compute_constant_expression("2 + 2")
171
171
  print(result1) # Output: 4.0
172
172
 
173
- result2 = compute_algebraic_expression("10 % 3")
173
+ result2 = compute_constant_expression("10 % 3")
174
174
  print(result2) # Output: 1.0
175
175
 
176
- result3 = compute_algebraic_expression("math.gcd(36, 60) * math.sin(math.radians(45)) * 10000")
176
+ result3 = compute_constant_expression("math.gcd(36, 60) * math.sin(math.radians(45)) * 10000")
177
177
  print(result3) # Output: 84852.8137423857
178
178
 
179
- These examples illustrate the ability to handle basic arithmetic, the modulo operator, and functions utilizing the Python math module.
180
-
181
179
  --------------------------------------------------------------------------------
182
180
 
183
- ### 2. `simplify_algebraic_expression`
181
+ ### 2. `simplify_polynomial_expression`
184
182
 
185
- Simplifies expressions and returns them in LaTeX format.
183
+ Simplifies an algebraic expression in polynomial form and returns it in LaTeX format. Takes an algebraic expression, in polynomial form, written in Python syntax and simplifies it. The result is returned as a LaTeX formatted string, suitable for academic or professional documentation.
186
184
 
187
- - **Parameters:**
188
- - `expression` (str): A string of the expression to simplify.
185
+ Parameters:
186
+ - `expression` (str): The algebraic expression, in polynomial form, to simplify. For instance, the expression 'np.diff(8*x**30) where as 'np.diff([2,5,9,11)' is not a polynomial.
187
+ - `subs` (Optional[Dict[str, float]]): An optional dictionary of substitutions where keys are variable names and values are the numbers to substitute them with.
189
188
 
190
- - **Returns:**
191
- - `str`: Simplified expression in LaTeX.
189
+ Returns:
190
+ - `str`: The simplified expression formatted as a LaTeX string.
192
191
 
193
- - **Example:**
192
+ Example Usage:
193
+
194
+ from rgwfuncs import simplify_polynomial_expression
194
195
 
195
- from rgwfuncs import simplify_algebraic_expression
196
- simplified_expr1 = simplify_algebraic_expression("2*x + 3*x")
196
+ # Example 1: Simplifying a polynomial expression without substitutions
197
+ simplified_expr1 = simplify_polynomial_expression("2*x + 3*x")
197
198
  print(simplified_expr1) # Output: "5 x"
198
199
 
199
- simplified_expr2 = simplify_algebraic_expression("(np.diff(3*x**8)) / (np.diff(8*x**30) * 11*y**3)")
200
- print(simplified_expr2) # Output: "\frac{1}{110 x^{22} y^{3}}"
200
+ # Example 2: Simplifying a complex expression involving derivatives
201
+ simplified_expr2 = simplify_polynomial_expression("(np.diff(3*x**8)) / (np.diff(8*x**30) * 11*y**3)")
202
+ print(simplified_expr2) # Output: r"\frac{1}{110 x^{22} y^{3}}"
203
+
204
+ # Example 3: Simplifying with substitutions
205
+ simplified_expr3 = simplify_polynomial_expression("x**2 + y**2", subs={"x": 3, "y": 4})
206
+ print(simplified_expr3) # Output: "25"
201
207
 
202
- These examples demonstrate simplification of polynomial expressions and more complex ratios involving derivatives.
208
+ # Example 4: Simplifying with partial substitution
209
+ simplified_expr4 = simplify_polynomial_expression("a*b + b", subs={"b": 2})
210
+ print(simplified_expr4) # Output: "2 a + 2"
203
211
 
204
212
  --------------------------------------------------------------------------------
205
213
 
206
- ### 3. `solve_algebraic_expression`
214
+ ### 3. `solve_homogeneous_polynomial_expression`
207
215
 
208
- Solves equations for specified variables, with optional substitutions, returning LaTeX-formatted solutions.
216
+ Solves a homogeneous polynomial expression for a specified variable and returns solutions in LaTeX format. Assumes that the expression is homoegeneous (i.e. equal to zero), and solves for a designated variable. May optionally include substitutions for other variables in the equation. The solutions are provided as a LaTeX formatted string. The method solves equations for specified variables, with optional substitutions, returning LaTeX-formatted solutions.
209
217
 
210
- - **Parameters:**
211
- - `expression` (str): A string of the equation to solve.
218
+ Parameters:
219
+ - `expression` (str): A string of the homogeneous polynomial expression to solve.
212
220
  - `variable` (str): The variable to solve for.
213
221
  - `subs` (Optional[Dict[str, float]]): Substitutions for variables.
214
222
 
215
- - **Returns:**
223
+ Returns:
216
224
  - `str`: Solutions formatted in LaTeX.
217
225
 
218
- - **Example:**
226
+ Example:
219
227
 
220
- from rgwfuncs import solve_algebraic_expression
221
- solutions1 = solve_algebraic_expression("a*x**2 + b*x + c", "x", {"a": 3, "b": 7, "c": 5})
228
+ from rgwfuncs import solve_homogeneous_polynomial_expression
229
+ solutions1 = solve_homogeneous_polynomial_expression("a*x**2 + b*x + c", "x", {"a": 3, "b": 7, "c": 5})
222
230
  print(solutions1) # Output: "\left[-7/6 - sqrt(11)*I/6, -7/6 + sqrt(11)*I/6\right]"
223
231
 
224
- solutions2 = solve_algebraic_expression("x**2 - 4", "x")
232
+ solutions2 = solve_homogeneous_polynomial_expression("x**2 - 4", "x")
225
233
  print(solutions2) # Output: "\left[-2, 2\right]"
226
234
 
227
- Here, we solve both a quadratic equation with complex solutions and a simpler polynomial equation.
228
-
229
235
  --------------------------------------------------------------------------------
230
236
 
231
237
  ### 4. `get_prime_factors_latex`
232
238
 
233
239
  Computes prime factors of a number and presents them in LaTeX format.
234
240
 
235
- - **Parameters:**
241
+ Parameters:
236
242
  - `n` (int): The integer to factorize.
237
243
 
238
- - **Returns:**
244
+ Returns:
239
245
  - `str`: Prime factorization in LaTeX.
240
246
 
241
- - **Example:**
247
+ Example:
242
248
 
243
249
  from rgwfuncs import get_prime_factors_latex
244
250
  factors1 = get_prime_factors_latex(100)
@@ -252,64 +258,60 @@ Computes prime factors of a number and presents them in LaTeX format.
252
258
 
253
259
  --------------------------------------------------------------------------------
254
260
 
255
- ### 5. `compute_matrix_operation`
261
+ ### 5. `compute_matrix_expression`
256
262
 
257
- Computes the results of 1D or 2D matrix operations and formats them as LaTeX strings.
263
+ Computes the results of expressions containing 1D or 2D matrix operations and formats them as LaTeX strings.
258
264
 
259
- - **Parameters:**
265
+ Parameters:
260
266
  - `expression` (str): A string representing a sequence of matrix operations involving either 1D or 2D lists. Supported operations include addition (`+`), subtraction (`-`), multiplication (`*`), and division (`/`).
261
267
 
262
- - **Returns:**
268
+ Returns:
263
269
  - `str`: The LaTeX-formatted string representation of the computed matrix, or an error message if the operations cannot be performed due to dimensional mismatches.
264
270
 
265
- - **Example:**
271
+ Example:
266
272
 
267
- from rgwfuncs import compute_matrix_operation
273
+ from rgwfuncs import compute_matrix_expression
268
274
 
269
275
  # Example with addition of 2D matrices
270
- result = compute_matrix_operation("[[2, 6, 9], [1, 3, 5]] + [[1, 2, 3], [4, 5, 6]]")
276
+ result = compute_matrix_expression("[[2, 6, 9], [1, 3, 5]] + [[1, 2, 3], [4, 5, 6]]")
271
277
  print(result) # Output: \begin{bmatrix}3 & 8 & 12\\5 & 8 & 11\end{bmatrix}
272
278
 
273
279
  # Example of mixed operations with 1D matrices treated as 2D
274
- result = compute_matrix_operation("[3, 6, 9] + [1, 2, 3] - [2, 2, 2]")
280
+ result = compute_matrix_expression("[3, 6, 9] + [1, 2, 3] - [2, 2, 2]")
275
281
  print(result) # Output: \begin{bmatrix}2 & 6 & 10\end{bmatrix}
276
282
 
277
283
  # Example with dimension mismatch
278
- result = compute_matrix_operation("[[4, 3, 51]] + [[1, 1]]")
284
+ result = compute_matrix_expression("[[4, 3, 51]] + [[1, 1]]")
279
285
  print(result) # Output: Operations between matrices must involve matrices of the same dimension
280
286
 
281
- This function performs elementwise operations on both 1D and 2D matrices represented as Python lists and formats the result as a LaTeX string. It handles operations sequentially from left to right and gracefully handles dimension mismatches by returning a meaningful message. It utilizes Python's `ast.literal_eval` for safe and robust parsing.
282
-
283
287
  --------------------------------------------------------------------------------
284
288
 
285
- ### 6. `compute_ordered_series_operations`
289
+ ### 6. `compute_ordered_series_expression`
286
290
 
287
- Computes the result of operations on ordered series expressed as 1D lists, including the discrete difference operator `ddd`.
291
+ Computes the result of expressions containing operations on ordered series expressed as 1D lists. The syntax of the expression supports the discrete difference operator via the `ddd()` method.
288
292
 
289
- - **Parameters:**
290
- - `expression` (str): A series operation expression. Supports operations such as "+", "-", "*", "/", and `ddd` for discrete differences.
293
+ Parameters:
294
+ - `expression` (str): A series operation expression. Supports operations such as "+", "-", "*", "/", and `ddd()` for discrete differences.
291
295
 
292
- - **Returns:**
296
+ Returns:
293
297
  - `str`: The string representation of the resultant series after performing operations, or an error message if series lengths do not match.
294
298
 
295
- - **Example:**
299
+ Example:
296
300
 
297
- from rgwfuncs import compute_ordered_series_operations
301
+ from rgwfuncs import compute_ordered_series_expression
298
302
 
299
303
  # Example with addition and discrete differences
300
- result = compute_ordered_series_operations("ddd([2, 6, 9, 60]) + ddd([78, 79, 80])")
304
+ result = compute_ordered_series_expression("ddd([2, 6, 9, 60]) + ddd([78, 79, 80])")
301
305
  print(result) # Output: [4, 3, 51] + [1, 1]
302
306
 
303
307
  # Example with elementwise subtraction
304
- result = compute_ordered_series_operations("[10, 15, 21] - [5, 5, 5]")
308
+ result = compute_ordered_series_expression("[10, 15, 21] - [5, 5, 5]")
305
309
  print(result) # Output: [5, 10, 16]
306
310
 
307
311
  # Example with length mismatch
308
- result = compute_ordered_series_operations("[4, 3, 51] + [1, 1]")
312
+ result = compute_ordered_series_expression("[4, 3, 51] + [1, 1]")
309
313
  print(result) # Output: Operations between ordered series must involve series of equal length
310
314
 
311
- This function first applies the discrete difference operator to any series where applicable, then evaluates arithmetic operations between series. It returns a string representation of the result or an error message if the series lengths do not match. The function is robust, directly parsing and evaluating given series expressions with safety checks in place.
312
-
313
315
  --------------------------------------------------------------------------------
314
316
 
315
317
  ## String Based Functions
@@ -0,0 +1,11 @@
1
+ rgwfuncs/__init__.py,sha256=DdRwXNEo_bN8R3WOWhysKmuHMNiyC6dpBj0GWP4HR0E,1390
2
+ rgwfuncs/algebra_lib.py,sha256=h3gGCcu6BOo1yTwprxx4pyaFO6MTYqKeiiJIruDcMhg,19037
3
+ rgwfuncs/df_lib.py,sha256=G_H3PXNVeseX2YLjkkrmO9eXA_7r29swUZlbPBDZjXA,66612
4
+ rgwfuncs/docs_lib.py,sha256=y3wSAOPO3qsA4HZ7xAtW8HimM8w-c8hjcEzMRLJ96ao,1960
5
+ rgwfuncs/str_lib.py,sha256=rtAdRlnSJIu3JhI-tA_A0wCiPK2m-zn5RoGpBxv_g-4,2228
6
+ rgwfuncs-0.0.29.dist-info/LICENSE,sha256=7EI8xVBu6h_7_JlVw-yPhhOZlpY9hP8wal7kHtqKT_E,1074
7
+ rgwfuncs-0.0.29.dist-info/METADATA,sha256=hAU47MpLVyGntoeVhv1bqgeAM3KJnhgJKKDZzmK76mk,42739
8
+ rgwfuncs-0.0.29.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
9
+ rgwfuncs-0.0.29.dist-info/entry_points.txt,sha256=j-c5IOPIQ0252EaOV6j6STio56sbXl2C4ym_fQ0lXx0,43
10
+ rgwfuncs-0.0.29.dist-info/top_level.txt,sha256=aGuVIzWsKiV1f2gCb6mynx0zx5ma0B1EwPGFKVEMTi4,9
11
+ rgwfuncs-0.0.29.dist-info/RECORD,,
@@ -1,11 +0,0 @@
1
- rgwfuncs/__init__.py,sha256=6QXVaHomLh1AIbC-b-edLf-GS1oEqRT-JffHPNIKowA,1375
2
- rgwfuncs/algebra_lib.py,sha256=VZS0d-sUGJvfHv00HmgD1htxBGbugsKkKuUKsJbLPkI,18205
3
- rgwfuncs/df_lib.py,sha256=G_H3PXNVeseX2YLjkkrmO9eXA_7r29swUZlbPBDZjXA,66612
4
- rgwfuncs/docs_lib.py,sha256=y3wSAOPO3qsA4HZ7xAtW8HimM8w-c8hjcEzMRLJ96ao,1960
5
- rgwfuncs/str_lib.py,sha256=rtAdRlnSJIu3JhI-tA_A0wCiPK2m-zn5RoGpBxv_g-4,2228
6
- rgwfuncs-0.0.27.dist-info/LICENSE,sha256=7EI8xVBu6h_7_JlVw-yPhhOZlpY9hP8wal7kHtqKT_E,1074
7
- rgwfuncs-0.0.27.dist-info/METADATA,sha256=NSNgM-VFveOpzvmosZgjg7kSC9KovbyXspCTXCdMdrU,41874
8
- rgwfuncs-0.0.27.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
9
- rgwfuncs-0.0.27.dist-info/entry_points.txt,sha256=j-c5IOPIQ0252EaOV6j6STio56sbXl2C4ym_fQ0lXx0,43
10
- rgwfuncs-0.0.27.dist-info/top_level.txt,sha256=aGuVIzWsKiV1f2gCb6mynx0zx5ma0B1EwPGFKVEMTi4,9
11
- rgwfuncs-0.0.27.dist-info/RECORD,,