Resolving "AttributeError: module 'dask.bag' has no attribute 'from_filenames'" - python

I am following a simple tutorial to load Reddit comment data from pushshift.io into a dask bag. I am getting the strange error: "Resolving "AttributeError: module 'dask.bag' has no attribute 'from_filenames'", despite the fact that this is standard procedure as described here: http://dask.pydata.org/en/doc-test-build/bag.html
import dask
import dask.bag as db
data = db.from_filenames("reddit_1_28_2018.txt", chunkbytes=100000).map(json.loads)
AttributeError Traceback (most recent call last)
<ipython-input-17-bcbd31affbfb> in <module>()
2 import dask.bag as db
3
----> 4 data = db.from_filenames("reddit_1_28_2018.txt", chunkbytes=100000).map(json.loads)
AttributeError: module 'dask.bag' has no attribute 'from_filenames'

I suspect that the resource you were looking at was very old. I recommend reading the Dask documentation for up-to-date information.
I suspect that you're looking for db.read_text

Related

"TypeError: cannot pickle 'weakref' object" error when loading deep learning h5 model and converting to pickle

I'm trying several ways because I'm stuck with capacity limitations during software deployment. Among them, I try to convert the model file into a pickle file, but an error like this appears.
TypeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_1304/3588776463.py in <module>
----> 1 pickle.dump(model, open('model_t.pkl','wb'))
TypeError: cannot pickle 'weakref' object
The code I ran is this.
import joblib
from keras.models import load_model
import pickle
model = load_model("app/models/model_109600.h5")
pickle.dump(model, open('model_t.pkl','wb'))
I thought it was a file capacity problem and tried other files, but got the same error.
The size of the currently loaded file is 207 MB
If there is a problem and you have a solution, please share.
Or if there is another way, I would appreciate it if you could share it.

Using densenet with fastai

I am trying to train a densenet model using the fast.ai library. I checked the documentation and I managed to make it work for resnet50. However, for densenet, it seems to be unable to find the module.
I tried to use arch=models.dn121 as stated by this forum. But I get the same error.
Can anyone please help?
Here is the code:
learn = create_cnn(data, base_arch=models.densenet201, metrics=accuracy, model_dir="/tmp/model/")
This is the error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-23-cb9ab3a79572> in <module>()
----> 1 learn = create_cnn(data, base_arch=models.densenet201, metrics=accuracy, model_dir="/tmp/model/")
AttributeError: module 'fastai.vision.models' has no attribute 'densenet201'
According to this post on the fast.ai forum, this is the solution to use densenet with fast.ai:
from torchvision.models import densenet121
def dn121(pre): return children(densenet121(pre))[0]
learn = create_cnn(data, dn121)

Attribute Error: folium has no attribute map

The error I am getting is like below:
Traceback (most recent call last)
<ipython-input-37-637818dcbe0d> in <module>
----> 1 mp = folium.map(location=[151.1780,33.7961], zoom_start=10)
2
3 choropleth = folium.Choropleth(
4 geo_data=suburbs,
5 data=rentwpostcode,
AttributeError: module 'folium' has no attribute 'map'
I tried installing folium through both conda and git clone. Both times the error remained. I also tried to removing folium.py but still it didn't work.
The error you're seeing is not related to the installation of folium. Names in Python are case-sensitive so .map() is not the same as .Map(). Change your code to mp = folium.Map(location=[151.1780,33.7961], zoom_start=10) and it'll work fine.

Issue with Pandas and circular reference in import

I am trying to use pandas for the first time and I have copied a very simple program
import pandas as pd
series1 = pd.Series([1,2,3,4])
print(series1)
The issue I am having is that when I try and run the program I am getting the following error
Traceback (most recent call last):
File "C:\Users\faintr\AppData\Local\Programs\Python\Python38-32\pandas.py", line 1, in <module>
import pandas as pd
File "C:\Users\faintr\AppData\Local\Programs\Python\Python38-32\pandas.py", line 2, in <module>
series1 = pd.Series([1,2,3,4])
AttributeError: partially initialized module 'pandas' has no attribute 'Series' (most likely due to a circular import)
Pandas version(1.14.0) is installed.
I have looked into circular imports and whilst I think I understand the concept if this is the cause I do not know how to fix it. I have tried downgrading pandas to an earlier version with no look
Can anyone help please

How can I get CPU temperature in Python? Assuming that I have Windows 32-bits

I have tried with psutil library using sensors_temperatures(), but it is giving me an AttributeError. Here is my code:
import psutil
print(psutil.sensors_temperatures())
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-28-fbefe6006680> in <module>
----> 1 print(psutil.sensors_temperatures())
AttributeError: module 'psutil' has no attribute 'sensors_temperatures'
Moreover, it seems that the function sensors_temperatures() do no longer exist in psutil when I checked it with help(psutil)
Sir you can use simple code for find the CPU temperature using python. And it is not necessary that you should use only 'psutil' for finding the temperature.
You can usethe WMI module + Open Hardware Monitor + its WMI interface described here.
import wmi
w = wmi.WMI(namespace="root\OpenHardwareMonitor")
temperature_infos = w.Sensor()
for sensor in temperature_infos:
if sensor.SensorType==u'Temperature':
print(sensor.Name)
print(sensor.Value)
# This is a simple code to find the temperature of the CPU using Python.

Categories