AlessandroLovo / general_purpose

Set of general purpose python functions
MIT License
2 stars 0 forks source link

an update after main@a891a42a causes an error #8

Closed georgemilosh closed 1 year ago

georgemilosh commented 1 year ago

I don't know which version of python you are using but after the update commit hash: main@a891a42a I am having the following error when running the following code:

import numpy as np
import matplotlib
import matplotlib.pyplot as plt
matplotlib.rc('font', size=14)
%matplotlib widget
import pandas as pd
import sys
from tqdm.notebook import tqdm

# log to stdout
import logging
logging.getLogger().level = logging.INFO
logging.getLogger().handlers = [logging.StreamHandler(sys.stdout)]

sys.path.append('../../../PLASIM/')

import Learn2_new as ln
TypeError                                 Traceback (most recent call last)
Cell In[1], line 17
     13 logging.getLogger().handlers = [logging.StreamHandler(sys.stdout)]
     15 sys.path.append('../../../PLASIM/')
---> 17 import Learn2_new as ln
     18 ut = ln.ut
     19 ef = ln.ef

File [/net/nfs/ssd2/gmiloshe/Climate-Learning/CESM/models/cnn/../../../PLASIM/Learn2_new.py:212](https://vscode-remote+ssh-002dremote-002bhal5.vscode-resource.vscode-cdn.net/net/nfs/ssd2/gmiloshe/Climate-Learning/PLASIM/Learn2_new.py:212)
    209 if not path_to_ERA in sys.path:
    210     sys.path.insert(1, path_to_ERA)
--> 212 import ERA.ERA_Fields_New as ef # general routines
    213 import ERA.TF_Fields as tff # tensorflow routines
    214 try:

File [/net/nfs/ssd2/gmiloshe/Climate-Learning/ERA/ERA_Fields_New.py:42](https://vscode-remote+ssh-002dremote-002bhal5.vscode-resource.vscode-cdn.net/net/nfs/ssd2/gmiloshe/Climate-Learning/ERA/ERA_Fields_New.py:42)
     39     sys.path.insert(1, path_to_parent)
     41 try:
---> 42     import general_purpose.utilities as ut
     43 except ImportError:
     44     import ERA.utilities as ut

File [/net/nfs/ssd2/gmiloshe/Climate-Learning/general_purpose/utilities.py:538](https://vscode-remote+ssh-002dremote-002bhal5.vscode-resource.vscode-cdn.net/net/nfs/ssd2/gmiloshe/Climate-Learning/general_purpose/utilities.py:538)
    534         func(**f_kwargs)
    536 #### JSON IO #########
--> 538 def json2dict(filename:str|Path) -> dict:
    539     '''
    540     Reads a json file `filename` as a dictionary
    541 
   (...)
    544     d : dict
    545     '''
    546     with open(filename, 'r') as j:

TypeError: unsupported operand type(s) for |: 'type' and 'type'

This issue was introduced in commit hash: main@a891a42a

AlessandroLovo commented 1 year ago

Yes, I was now using python3.10, which has this new nice features for type hints. I discovered later that it was indeed a feature of python3.10. Would you prefer that I remove this or are you going to update to python3.10 anyways?

AlessandroLovo commented 1 year ago

The new syntax appeared in only 2 instances, so I simply got rid of it