rgwfuncs 0.0.28__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,21 @@ 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(
40
+ def simplify_polynomial_expression(
40
41
  expression: str,
41
42
  subs: Optional[Dict[str, float]] = None
42
43
  ) -> str:
43
44
  """
44
- Simplifies an algebraic expression and returns it in LaTeX format.
45
+ Simplifies an algebraic expression in polynomial form and returns it in LaTeX format.
45
46
 
46
- Takes an algebraic expression written in Python syntax and simplifies it. The result is
47
- 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.
48
50
 
49
51
  Parameters:
50
- 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.
51
55
  subs (Optional[Dict[str, float]]): An optional dictionary of substitutions for variables
52
56
  in the expression.
53
57
 
@@ -58,7 +62,6 @@ def simplify_algebraic_expression(
58
62
  ValueError: If the expression cannot be simplified due to errors in expression or parameters.
59
63
  """
60
64
 
61
-
62
65
  def recursive_parse_function_call(
63
66
  func_call: str, prefix: str, sym_vars: Dict[str, Expr]) -> Tuple[str, List[Expr]]:
64
67
  # print(f"Parsing function call: {func_call}")
@@ -209,19 +212,21 @@ def simplify_algebraic_expression(
209
212
  raise ValueError(f"Error simplifying expression: {e}")
210
213
 
211
214
 
212
- def solve_algebraic_expression(
213
- expression: str,
214
- variable: str,
215
- subs: Optional[Dict[str, float]] = None
216
- ) -> str:
215
+ def solve_homogeneous_polynomial_expression(
216
+ expression: str,
217
+ variable: str,
218
+ subs: Optional[Dict[str, float]] = None
219
+ ) -> str:
217
220
  """
218
- 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.
219
223
 
220
- Solves the given equation for a designated variable. May optionally include substitutions
221
- 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.
222
227
 
223
228
  Parameters:
224
- expression (str): The algebraic equation to solve.
229
+ expression (str): The homogeneous polynomial expression to solve.
225
230
  variable (str): The variable to solve the equation for.
226
231
  subs (Optional[Dict[str, float]]): An optional dictionary of substitutions for variables
227
232
  in the equation.
@@ -260,7 +265,7 @@ def solve_algebraic_expression(
260
265
  raise ValueError(f"Error solving the expression: {e}")
261
266
 
262
267
 
263
- def compute_matrix_operation(expression: str) -> str:
268
+ def compute_matrix_expression(expression: str) -> str:
264
269
  """
265
270
  Computes the result of a matrix-like operation on 1D or 2D list inputs and returns it as a LaTeX string.
266
271
 
@@ -350,7 +355,7 @@ def compute_matrix_operation(expression: str) -> str:
350
355
  return f"Error computing matrix operation: {e}"
351
356
 
352
357
 
353
- def compute_ordered_series_operation(expression: str) -> str:
358
+ def compute_ordered_series_expression(expression: str) -> str:
354
359
  """
355
360
  Computes the result of operations on ordered series expressed as 1D lists, including discrete difference (ddd),
356
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.28
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,105 +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. Optionally applies substitutions to variables within the expression before simplifying.
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 representing the algebraic 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.
189
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.
190
188
 
191
- - **Returns:**
189
+ Returns:
192
190
  - `str`: The simplified expression formatted as a LaTeX string.
193
191
 
194
- - **Example Usage:**
192
+ Example Usage:
195
193
 
196
- from rgwfuncs import simplify_algebraic_expression
194
+ from rgwfuncs import simplify_polynomial_expression
197
195
 
198
196
  # Example 1: Simplifying a polynomial expression without substitutions
199
- simplified_expr1 = simplify_algebraic_expression("2*x + 3*x")
197
+ simplified_expr1 = simplify_polynomial_expression("2*x + 3*x")
200
198
  print(simplified_expr1) # Output: "5 x"
201
199
 
202
200
  # Example 2: Simplifying a complex expression involving derivatives
203
- simplified_expr2 = simplify_algebraic_expression(
204
- "(np.diff(3*x**8)) / (np.diff(8*x**30) * 11*y**3)"
205
- )
201
+ simplified_expr2 = simplify_polynomial_expression("(np.diff(3*x**8)) / (np.diff(8*x**30) * 11*y**3)")
206
202
  print(simplified_expr2) # Output: r"\frac{1}{110 x^{22} y^{3}}"
207
203
 
208
204
  # Example 3: Simplifying with substitutions
209
- simplified_expr3 = simplify_algebraic_expression("x**2 + y**2", subs={"x": 3, "y": 4})
205
+ simplified_expr3 = simplify_polynomial_expression("x**2 + y**2", subs={"x": 3, "y": 4})
210
206
  print(simplified_expr3) # Output: "25"
211
207
 
212
208
  # Example 4: Simplifying with partial substitution
213
- simplified_expr4 = simplify_algebraic_expression("a*b + b", subs={"b": 2})
214
- print(simplified_expr4) # Output: "a \cdot 2 + 2"
215
-
216
- These examples demonstrate the simplification of polynomial expressions, handling complex ratios involving derivatives, and applying variable substitutions before simplifying. The function handles expressions both with and without substitutions, providing flexibility in its usage.
209
+ simplified_expr4 = simplify_polynomial_expression("a*b + b", subs={"b": 2})
210
+ print(simplified_expr4) # Output: "2 a + 2"
217
211
 
218
212
  --------------------------------------------------------------------------------
219
213
 
220
- ### 3. `solve_algebraic_expression`
214
+ ### 3. `solve_homogeneous_polynomial_expression`
221
215
 
222
- 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.
223
217
 
224
- - **Parameters:**
225
- - `expression` (str): A string of the equation to solve.
218
+ Parameters:
219
+ - `expression` (str): A string of the homogeneous polynomial expression to solve.
226
220
  - `variable` (str): The variable to solve for.
227
221
  - `subs` (Optional[Dict[str, float]]): Substitutions for variables.
228
222
 
229
- - **Returns:**
223
+ Returns:
230
224
  - `str`: Solutions formatted in LaTeX.
231
225
 
232
- - **Example:**
226
+ Example:
233
227
 
234
- from rgwfuncs import solve_algebraic_expression
235
- 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})
236
230
  print(solutions1) # Output: "\left[-7/6 - sqrt(11)*I/6, -7/6 + sqrt(11)*I/6\right]"
237
231
 
238
- solutions2 = solve_algebraic_expression("x**2 - 4", "x")
232
+ solutions2 = solve_homogeneous_polynomial_expression("x**2 - 4", "x")
239
233
  print(solutions2) # Output: "\left[-2, 2\right]"
240
234
 
241
- Here, we solve both a quadratic equation with complex solutions and a simpler polynomial equation.
242
-
243
235
  --------------------------------------------------------------------------------
244
236
 
245
237
  ### 4. `get_prime_factors_latex`
246
238
 
247
239
  Computes prime factors of a number and presents them in LaTeX format.
248
240
 
249
- - **Parameters:**
241
+ Parameters:
250
242
  - `n` (int): The integer to factorize.
251
243
 
252
- - **Returns:**
244
+ Returns:
253
245
  - `str`: Prime factorization in LaTeX.
254
246
 
255
- - **Example:**
247
+ Example:
256
248
 
257
249
  from rgwfuncs import get_prime_factors_latex
258
250
  factors1 = get_prime_factors_latex(100)
@@ -266,64 +258,60 @@ Computes prime factors of a number and presents them in LaTeX format.
266
258
 
267
259
  --------------------------------------------------------------------------------
268
260
 
269
- ### 5. `compute_matrix_operation`
261
+ ### 5. `compute_matrix_expression`
270
262
 
271
- 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.
272
264
 
273
- - **Parameters:**
265
+ Parameters:
274
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 (`/`).
275
267
 
276
- - **Returns:**
268
+ Returns:
277
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.
278
270
 
279
- - **Example:**
271
+ Example:
280
272
 
281
- from rgwfuncs import compute_matrix_operation
273
+ from rgwfuncs import compute_matrix_expression
282
274
 
283
275
  # Example with addition of 2D matrices
284
- 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]]")
285
277
  print(result) # Output: \begin{bmatrix}3 & 8 & 12\\5 & 8 & 11\end{bmatrix}
286
278
 
287
279
  # Example of mixed operations with 1D matrices treated as 2D
288
- 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]")
289
281
  print(result) # Output: \begin{bmatrix}2 & 6 & 10\end{bmatrix}
290
282
 
291
283
  # Example with dimension mismatch
292
- result = compute_matrix_operation("[[4, 3, 51]] + [[1, 1]]")
284
+ result = compute_matrix_expression("[[4, 3, 51]] + [[1, 1]]")
293
285
  print(result) # Output: Operations between matrices must involve matrices of the same dimension
294
286
 
295
- 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.
296
-
297
287
  --------------------------------------------------------------------------------
298
288
 
299
- ### 6. `compute_ordered_series_operations`
289
+ ### 6. `compute_ordered_series_expression`
300
290
 
301
- 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.
302
292
 
303
- - **Parameters:**
304
- - `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.
305
295
 
306
- - **Returns:**
296
+ Returns:
307
297
  - `str`: The string representation of the resultant series after performing operations, or an error message if series lengths do not match.
308
298
 
309
- - **Example:**
299
+ Example:
310
300
 
311
- from rgwfuncs import compute_ordered_series_operations
301
+ from rgwfuncs import compute_ordered_series_expression
312
302
 
313
303
  # Example with addition and discrete differences
314
- 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])")
315
305
  print(result) # Output: [4, 3, 51] + [1, 1]
316
306
 
317
307
  # Example with elementwise subtraction
318
- result = compute_ordered_series_operations("[10, 15, 21] - [5, 5, 5]")
308
+ result = compute_ordered_series_expression("[10, 15, 21] - [5, 5, 5]")
319
309
  print(result) # Output: [5, 10, 16]
320
310
 
321
311
  # Example with length mismatch
322
- result = compute_ordered_series_operations("[4, 3, 51] + [1, 1]")
312
+ result = compute_ordered_series_expression("[4, 3, 51] + [1, 1]")
323
313
  print(result) # Output: Operations between ordered series must involve series of equal length
324
314
 
325
- 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.
326
-
327
315
  --------------------------------------------------------------------------------
328
316
 
329
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=wVe2hDrO9izDadZxknWENScdpwzsi560dMXPkmL2Y2I,18678
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.28.dist-info/LICENSE,sha256=7EI8xVBu6h_7_JlVw-yPhhOZlpY9hP8wal7kHtqKT_E,1074
7
- rgwfuncs-0.0.28.dist-info/METADATA,sha256=vMLiE-lg_340OccGcxtOXewQimasntfHMfc7YpCn66c,42878
8
- rgwfuncs-0.0.28.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
9
- rgwfuncs-0.0.28.dist-info/entry_points.txt,sha256=j-c5IOPIQ0252EaOV6j6STio56sbXl2C4ym_fQ0lXx0,43
10
- rgwfuncs-0.0.28.dist-info/top_level.txt,sha256=aGuVIzWsKiV1f2gCb6mynx0zx5ma0B1EwPGFKVEMTi4,9
11
- rgwfuncs-0.0.28.dist-info/RECORD,,