rgwfuncs 0.0.37__tar.gz → 0.0.40__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: rgwfuncs
3
- Version: 0.0.37
3
+ Version: 0.0.40
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
@@ -23,12 +23,16 @@ Requires-Dist: xgboost
23
23
  Requires-Dist: requests
24
24
  Requires-Dist: slack-sdk
25
25
  Requires-Dist: google-api-python-client
26
+ Requires-Dist: boto
26
27
 
27
28
  # RGWFUNCS
28
29
 
29
30
  ***By Ryan Gerard Wilson (https://ryangerardwilson.com)***
30
31
 
31
- This library is meant to make ML/ Data Science pipelines more readable. It assumes a linux environment, and the existence of a `.rgwfuncsrc` file for certain features (like db querying, sending data to slack, etc.)
32
+
33
+ This library is meant to protect your eyes (and brain) from OOP syntax. It is unbelievably sad that some of the best work done in creating math and data science libraries in Python has been corrupted by the OOP mind-virus.
34
+
35
+ By creating a functional-programming wrapper around these libraries, we aim to soothe. This library assumes a Linux environment and the existence of a `.rgwfuncsrc` file for certain features (like database querying, sending data to Slack, etc.).
32
36
 
33
37
  --------------------------------------------------------------------------------
34
38
 
@@ -362,6 +366,42 @@ Converts a polynomial expression written in Python syntax to a LaTeX formatted s
362
366
 
363
367
  --------------------------------------------------------------------------------
364
368
 
369
+ ### 6. `expand_polynomial_expression`
370
+
371
+ Expands a polynomial expression written in Python syntax and converts it into a LaTeX formatted string. This function takes algebraic expressions provided as strings using Python's syntax, applies polynomial expansion through SymPy, and translates them into LaTeX representations, suitable for academic or professional documentation. It supports expressions with named variables and provides an option to substitute specific values into the expression before expansion.
372
+
373
+ - Parameters:
374
+ - `expression` (str): The algebraic expression to expand and convert to LaTeX. This string should be formatted using Python syntax acceptable by SymPy.
375
+ - `subs` (Optional[Dict[str, float]]): An optional dictionary of substitutions where the keys are variable names in the expression, and the values are the numbers with which to substitute those variables before expanding.
376
+
377
+ - Returns:
378
+ - `str`: The LaTeX formatted string of the expanded expression.
379
+
380
+ - Raises:
381
+ - `ValueError`: If the expression cannot be parsed due to syntax errors.
382
+
383
+ - Example:
384
+
385
+ from rgwfuncs import expand_polynomial_expression
386
+
387
+ # Expand a simple polynomial expression and convert to LaTeX
388
+ latex_result1 = expand_polynomial_expression("(x + y)**2")
389
+ print(latex_result1) # Output: "x^{2} + 2 x y + y^{2}"
390
+
391
+ # Expand polynomial expression with substituted values
392
+ latex_result2 = expand_polynomial_expression("(x + y)**2", {"x": 3, "y": 4})
393
+ print(latex_result2) # Output: "49"
394
+
395
+ # Another example with partial substitution
396
+ latex_result3 = expand_polynomial_expression("(x + y)**2", {"x": 3})
397
+ print(latex_result3) # Output: "y^{2} + 6 y + 9"
398
+
399
+ # Handling trigonometric functions with symbolic variables
400
+ latex_result4 = expand_polynomial_expression("sin(x + z**2) + cos(y)", {"x": 55})
401
+ print(latex_result4) # Output: "cos y + sin \\left(z^{2} + 55\\right)"
402
+
403
+ --------------------------------------------------------------------------------
404
+
365
405
  ### 6. `simplify_polynomial_expression`
366
406
 
367
407
  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.
@@ -2,7 +2,10 @@
2
2
 
3
3
  ***By Ryan Gerard Wilson (https://ryangerardwilson.com)***
4
4
 
5
- This library is meant to make ML/ Data Science pipelines more readable. It assumes a linux environment, and the existence of a `.rgwfuncsrc` file for certain features (like db querying, sending data to slack, etc.)
5
+
6
+ This library is meant to protect your eyes (and brain) from OOP syntax. It is unbelievably sad that some of the best work done in creating math and data science libraries in Python has been corrupted by the OOP mind-virus.
7
+
8
+ By creating a functional-programming wrapper around these libraries, we aim to soothe. This library assumes a Linux environment and the existence of a `.rgwfuncsrc` file for certain features (like database querying, sending data to Slack, etc.).
6
9
 
7
10
  --------------------------------------------------------------------------------
8
11
 
@@ -336,6 +339,42 @@ Converts a polynomial expression written in Python syntax to a LaTeX formatted s
336
339
 
337
340
  --------------------------------------------------------------------------------
338
341
 
342
+ ### 6. `expand_polynomial_expression`
343
+
344
+ Expands a polynomial expression written in Python syntax and converts it into a LaTeX formatted string. This function takes algebraic expressions provided as strings using Python's syntax, applies polynomial expansion through SymPy, and translates them into LaTeX representations, suitable for academic or professional documentation. It supports expressions with named variables and provides an option to substitute specific values into the expression before expansion.
345
+
346
+ - Parameters:
347
+ - `expression` (str): The algebraic expression to expand and convert to LaTeX. This string should be formatted using Python syntax acceptable by SymPy.
348
+ - `subs` (Optional[Dict[str, float]]): An optional dictionary of substitutions where the keys are variable names in the expression, and the values are the numbers with which to substitute those variables before expanding.
349
+
350
+ - Returns:
351
+ - `str`: The LaTeX formatted string of the expanded expression.
352
+
353
+ - Raises:
354
+ - `ValueError`: If the expression cannot be parsed due to syntax errors.
355
+
356
+ - Example:
357
+
358
+ from rgwfuncs import expand_polynomial_expression
359
+
360
+ # Expand a simple polynomial expression and convert to LaTeX
361
+ latex_result1 = expand_polynomial_expression("(x + y)**2")
362
+ print(latex_result1) # Output: "x^{2} + 2 x y + y^{2}"
363
+
364
+ # Expand polynomial expression with substituted values
365
+ latex_result2 = expand_polynomial_expression("(x + y)**2", {"x": 3, "y": 4})
366
+ print(latex_result2) # Output: "49"
367
+
368
+ # Another example with partial substitution
369
+ latex_result3 = expand_polynomial_expression("(x + y)**2", {"x": 3})
370
+ print(latex_result3) # Output: "y^{2} + 6 y + 9"
371
+
372
+ # Handling trigonometric functions with symbolic variables
373
+ latex_result4 = expand_polynomial_expression("sin(x + z**2) + cos(y)", {"x": 55})
374
+ print(latex_result4) # Output: "cos y + sin \\left(z^{2} + 55\\right)"
375
+
376
+ --------------------------------------------------------------------------------
377
+
339
378
  ### 6. `simplify_polynomial_expression`
340
379
 
341
380
  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.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "rgwfuncs"
7
- version = "0.0.37"
7
+ version = "0.0.40"
8
8
  authors = [
9
9
  { name = "Ryan Gerard Wilson", email = "ryangerardwilson@gmail.com" },
10
10
  ]
@@ -27,6 +27,7 @@ dependencies = [
27
27
  "requests",
28
28
  "slack-sdk",
29
29
  "google-api-python-client",
30
+ "boto"
30
31
  ]
31
32
 
32
33
  dynamic = ["scripts"]
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = rgwfuncs
3
- version = 0.0.37
3
+ version = 0.0.40
4
4
  author = Ryan Gerard Wilson
5
5
  author_email = ryangerardwilson@gmail.com
6
6
  description = A functional programming paradigm for mathematical modelling and data science
@@ -28,6 +28,7 @@ install_requires =
28
28
  requests
29
29
  slack-sdk
30
30
  google-api-python-client
31
+ boto
31
32
 
32
33
  [options.packages.find]
33
34
  where = src
@@ -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_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
4
+ from .algebra_lib import compute_constant_expression, compute_constant_expression_involving_matrices, compute_constant_expression_involving_ordered_series, compute_prime_factors, expand_polynomial_expression, 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
7
  from .interactive_shell_lib import interactive_shell
@@ -320,6 +320,50 @@ def python_polynomial_expression_to_latex(
320
320
  latex_result = latex(expr)
321
321
  return latex_result
322
322
 
323
+ def expand_polynomial_expression(
324
+ expression: str,
325
+ subs: Optional[Dict[str, float]] = None
326
+ ) -> str:
327
+ """
328
+ Expands a polynomial expression written in Python syntax and converts it to LaTeX format.
329
+
330
+ This function takes an algebraic expression written in Python syntax,
331
+ applies polynomial expansion, and converts the expanded expression
332
+ to a LaTeX formatted string. The expression should be compatible with sympy.
333
+
334
+ Parameters:
335
+ expression (str): The algebraic expression to expand and convert to LaTeX.
336
+ The expression should be written using Python syntax.
337
+ subs (Optional[Dict[str, float]]): An optional dictionary of substitutions
338
+ to apply to variables in the expression
339
+ before expansion.
340
+
341
+ Returns:
342
+ str: The expanded expression represented as a LaTeX string.
343
+
344
+ Raises:
345
+ ValueError: If the expression cannot be parsed due to syntax errors.
346
+ """
347
+ transformations = standard_transformations + (implicit_multiplication_application,)
348
+
349
+ def parse_and_expand_expression(expr_str: str, sym_vars: Dict[str, symbols]) -> symbols:
350
+ try:
351
+ expr = parse_expr(expr_str, local_dict=sym_vars, transformations=transformations)
352
+ if subs:
353
+ subs_symbols = {symbols(k): v for k, v in subs.items()}
354
+ expr = expr.subs(subs_symbols)
355
+ return expr.expand()
356
+ except (SyntaxError, ValueError, TypeError) as e:
357
+ raise ValueError(f"Error parsing expression: {expr_str}. Error: {e}")
358
+
359
+ variable_names = set(re.findall(r'\b[a-zA-Z]\w*\b', expression))
360
+ sym_vars = {var: symbols(var) for var in variable_names}
361
+
362
+ expr = parse_and_expand_expression(expression, sym_vars)
363
+ latex_result = latex(expr)
364
+ return latex_result
365
+
366
+
323
367
 
324
368
  def simplify_polynomial_expression(
325
369
  expression: str,
@@ -21,6 +21,7 @@ from email.mime.base import MIMEBase
21
21
  from email import encoders
22
22
  from googleapiclient.discovery import build
23
23
  import base64
24
+ import boto3
24
25
  # import inspect
25
26
  from typing import Optional, Dict, List, Tuple, Any
26
27
  import warnings
@@ -434,7 +435,7 @@ def load_data_from_query(db_preset_name: str, query: str) -> pd.DataFrame:
434
435
  return pd.DataFrame(data, columns=columns)
435
436
 
436
437
 
437
- aws_region = db_preset['region']
438
+ aws_region = db_preset['aws_region']
438
439
  database = db_preset['database']
439
440
  output_bucket = db_preset['output_bucket']
440
441
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: rgwfuncs
3
- Version: 0.0.37
3
+ Version: 0.0.40
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
@@ -23,12 +23,16 @@ Requires-Dist: xgboost
23
23
  Requires-Dist: requests
24
24
  Requires-Dist: slack-sdk
25
25
  Requires-Dist: google-api-python-client
26
+ Requires-Dist: boto
26
27
 
27
28
  # RGWFUNCS
28
29
 
29
30
  ***By Ryan Gerard Wilson (https://ryangerardwilson.com)***
30
31
 
31
- This library is meant to make ML/ Data Science pipelines more readable. It assumes a linux environment, and the existence of a `.rgwfuncsrc` file for certain features (like db querying, sending data to slack, etc.)
32
+
33
+ This library is meant to protect your eyes (and brain) from OOP syntax. It is unbelievably sad that some of the best work done in creating math and data science libraries in Python has been corrupted by the OOP mind-virus.
34
+
35
+ By creating a functional-programming wrapper around these libraries, we aim to soothe. This library assumes a Linux environment and the existence of a `.rgwfuncsrc` file for certain features (like database querying, sending data to Slack, etc.).
32
36
 
33
37
  --------------------------------------------------------------------------------
34
38
 
@@ -362,6 +366,42 @@ Converts a polynomial expression written in Python syntax to a LaTeX formatted s
362
366
 
363
367
  --------------------------------------------------------------------------------
364
368
 
369
+ ### 6. `expand_polynomial_expression`
370
+
371
+ Expands a polynomial expression written in Python syntax and converts it into a LaTeX formatted string. This function takes algebraic expressions provided as strings using Python's syntax, applies polynomial expansion through SymPy, and translates them into LaTeX representations, suitable for academic or professional documentation. It supports expressions with named variables and provides an option to substitute specific values into the expression before expansion.
372
+
373
+ - Parameters:
374
+ - `expression` (str): The algebraic expression to expand and convert to LaTeX. This string should be formatted using Python syntax acceptable by SymPy.
375
+ - `subs` (Optional[Dict[str, float]]): An optional dictionary of substitutions where the keys are variable names in the expression, and the values are the numbers with which to substitute those variables before expanding.
376
+
377
+ - Returns:
378
+ - `str`: The LaTeX formatted string of the expanded expression.
379
+
380
+ - Raises:
381
+ - `ValueError`: If the expression cannot be parsed due to syntax errors.
382
+
383
+ - Example:
384
+
385
+ from rgwfuncs import expand_polynomial_expression
386
+
387
+ # Expand a simple polynomial expression and convert to LaTeX
388
+ latex_result1 = expand_polynomial_expression("(x + y)**2")
389
+ print(latex_result1) # Output: "x^{2} + 2 x y + y^{2}"
390
+
391
+ # Expand polynomial expression with substituted values
392
+ latex_result2 = expand_polynomial_expression("(x + y)**2", {"x": 3, "y": 4})
393
+ print(latex_result2) # Output: "49"
394
+
395
+ # Another example with partial substitution
396
+ latex_result3 = expand_polynomial_expression("(x + y)**2", {"x": 3})
397
+ print(latex_result3) # Output: "y^{2} + 6 y + 9"
398
+
399
+ # Handling trigonometric functions with symbolic variables
400
+ latex_result4 = expand_polynomial_expression("sin(x + z**2) + cos(y)", {"x": 55})
401
+ print(latex_result4) # Output: "cos y + sin \\left(z^{2} + 55\\right)"
402
+
403
+ --------------------------------------------------------------------------------
404
+
365
405
  ### 6. `simplify_polynomial_expression`
366
406
 
367
407
  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.
@@ -8,3 +8,4 @@ xgboost
8
8
  requests
9
9
  slack-sdk
10
10
  google-api-python-client
11
+ boto
File without changes