Skip to content

Improve PredefinedExpressions and add Python dict to Mathics3 Association conversion#1840

Merged
rocky merged 2 commits into
masterfrom
association-tweaks
Jun 16, 2026
Merged

Improve PredefinedExpressions and add Python dict to Mathics3 Association conversion#1840
rocky merged 2 commits into
masterfrom
association-tweaks

Conversation

@rocky

@rocky rocky commented Jun 14, 2026

Copy link
Copy Markdown
Member
  • Add a way that from_python() can convert a dictionary to an Association.
  • Remove ExpressionInfinity. This is a duplicate of MATHICS3_INFINITY.
  • Fill in more properties for predefined constants; set Python and SymPy corresponding values
  • Define ELEMENTS_FULLY_EVALUATED for use on fully-evaluated constants.

@rocky
rocky force-pushed the association-tweaks branch from 746e9bf to 926041b Compare June 14, 2026 14:19
ExpressionInfinity duplicates MATHIC3_INFINITY.

Add more properties to predefined constants and set conversion values.

define ELEMENTS_FULLY_EVALUATED for use on fully_evaluated constants
@rocky
rocky force-pushed the association-tweaks branch from 926041b to 0370bc2 Compare June 14, 2026 14:21
@rocky
rocky requested a review from mmatera June 14, 2026 14:29
@mmatera

mmatera commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

OK, this does not seem to have any to do with Association, but looks good.

@mmatera mmatera changed the title Association tweaks Improve PredefinedExpressions Jun 16, 2026

@mmatera mmatera left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rocky

rocky commented Jun 16, 2026

Copy link
Copy Markdown
Member Author

OK, this does not seem to have any to do with Association, but looks good.

The association with Association:

def association_from_dict(arg: dict, options: ToPythonOptions) -> BaseElement:
    from mathics.core.expression import Expression

    entries = [
        Expression(
            SymbolRule,
            from_python(key, options),
            from_python(value, options),
        )
        for key, value in arg.items()
    ]
    return Expression(SymbolAssociation, *entries)

This will be used by Import of a ZIP file in showing Summary items. For example:

In[1]:= Import["t1.zip", "Elements"]                                                    
Out[1]= {FileNames, Summary}

In[2]:= Import["t1.zip", "Summary"]                                                     
Out[2]= Dataset[<|Format -> ZIP, FileName -> t1.zip, FileSize -> 5.675 kilobytes|>, 
 >    TypeSystem`Struct[{Format, FileName, FileSize}, 
 >     {TypeSystem`Atom[String], TypeSystem`Atom[String], TypeSystem`Atom[1 kilobyte]}]\
 >     , <||>]

@rocky rocky changed the title Improve PredefinedExpressions Improve PredefinedExpressions and add Python dict to Mathics3 Association conversion Jun 16, 2026
@rocky
rocky merged commit c2af55a into master Jun 16, 2026
18 checks passed
@rocky
rocky deleted the association-tweaks branch June 16, 2026 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants