maximum recursion depth exceeded google colab - python

Trying to run some python code on Google colab. I have some preprocessed data that I need to read in:
train, test, unused_feat, target_features, features, cat_idxs, cat_dims = pickle.load(open('/content/drive/My Drive/xxx/data/train_test.pkl', 'rb'))
Then if I call train I get the error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/IPython/core/formatters.py in __call__(self, obj)
697 type_pprinters=self.type_printers,
698 deferred_pprinters=self.deferred_printers)
--> 699 printer.pretty(obj)
700 printer.flush()
701 return stream.getvalue()
8 frames
pandas/_libs/properties.pyx in pandas._libs.properties.AxisProperty.__get__()
/usr/local/lib/python3.6/dist-packages/pandas/core/generic.py in __getattr__(self, name)
5268 or name in self._accessors
5269 ):
-> 5270 return object.__getattribute__(self, name)
5271 else:
5272 if self._info_axis._can_hold_identifiers_and_holds_name(name):
AttributeError: 'DataFrame' object has no attribute '_data'
and when I call
---------------------------------------------------------------------------
RecursionError Traceback (most recent call last)
<ipython-input-35-5e6a15ce28a5> in <module>()
----> 1 train.shape
321 frames
pandas/_libs/properties.pyx in pandas._libs.properties.AxisProperty.__get__()
/usr/local/lib/python3.6/dist-packages/pandas/core/generic.py in __getattr__(self, name)
5268 or name in self._accessors
5269 ):
-> 5270 return object.__getattribute__(self, name)
5271 else:
5272 if self._info_axis._can_hold_identifiers_and_holds_name(name):
RecursionError: maximum recursion depth exceeded while calling a Python object
When I work on my own jupyter notebook I have no problem with this. I wonder what went wrong. Also train contains roughly 250000 rows.

I think you could change the recursion limit if that is your constraint, however, you might be in an endless loop.
This post tells you how to increase your recursion limit.
What is the maximum recursion depth in Python, and how to increase it?
However, I am not sure about the other error you got. Hope it helps a bit.

Related

AttributeError: 'IntervalArray' object has no attribute '_dtype' while reading pickle file to dataframe

I want to read a pickle file into a data frame. However, I get the following error message and I don't know how to solve the issue.
df_batches = pd.read_pickle(folder_in / "batches_and_phases.p")
Error Message:
AttributeError Traceback (most recent call last)
File ~\Master_Thesis\mypython\lib\site-packages\pandas\io\pickle.py:205, in read_pickle(filepath_or_buffer, compression, storage_options)
204 warnings.simplefilter("ignore", Warning)
--> 205 return pickle.load(handles.handle)
206 except excs_to_catch:
207 # e.g.
208 # "No module named 'pandas.core.sparse.series'"
209 # "Can't get attribute '__nat_unpickle' on <module 'pandas._libs.tslib"
File ~\Master_Thesis\mypython\lib\site-packages\pandas\_libs\internals.pyx:750, in pandas._libs.internals.BlockManager.__setstate__()
File ~\Master_Thesis\mypython\lib\site-packages\pandas\_libs\internals.pyx:767, in pandas._libs.internals.BlockManager.__setstate__()
File ~\Master_Thesis\mypython\lib\site-packages\pandas\core\internals\blocks.py:2143, in ensure_block_shape(values, ndim)
2142 if values.ndim < ndim:
-> 2143 if not is_1d_only_ea_dtype(values.dtype):
2144 # TODO(EA2D): https://github.com/pandas-dev/pandas/issues/23023
2145 # block.shape is incorrect for "2D" ExtensionArrays
2146 # We can't, and don't need to, reshape.
2147 values = cast("np.ndarray | DatetimeArray | TimedeltaArray", values)
File ~\Master_Thesis\mypython\lib\site-packages\pandas\core\arrays\interval.py:624, in IntervalArray.dtype(self)
622 #property
623 def dtype(self) -> IntervalDtype:
--> 624 return self._dtype
AttributeError: 'IntervalArray' object has no attribute '_dtype'
Thank you!

can't convert cuda:0 device type tensor to numpy

As metioned in the title, I am getting this TyperError for the following code
I am using google collab and is set to GPU runtime type.
%%time
history = [evaluate(model, valid_dl)]
history
%%time
history += fit_OneCycle(epochs, max_lr, model, train_dl, valid_dl,
grad_clip=grad_clip,
weight_decay=1e-4,
opt_func=opt_func)
def plot_losses(history):
train_losses = [x.get('train_loss') for x in history]
val_losses = [x['val_loss'] for x in history]
plt.plot(train_losses, '-bx')
plt.plot(val_losses, '-rx')
plt.xlabel('epoch')
plt.ylabel('loss')
plt.legend(['Training', 'Validation'])
plt.title('Loss vs. No. of epochs')
for the following line i am getting the error :-
plot_losses(history)
And i am getting the following error message:
AttributeError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/matplotlib/cbook/__init__.py in index_of(y)
1626 try:
-> 1627 return y.index.values, y.values
1628 except AttributeError:
AttributeError: 'builtin_function_or_method' object has no attribute 'values'
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
----------------------------------9 frames------------------------------------------
<__array_function__ internals> in atleast_1d(*args, **kwargs)
/usr/local/lib/python3.7/dist-packages/torch/_tensor.py in __array__(self, dtype)
676 return handle_torch_function(Tensor.__array__, (self,), self, dtype=dtype)
677 if dtype is None:
--> 678 return self.numpy()
679 else:
680 return self.numpy().astype(dtype, copy=False)
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
The line of error is not shown here, however, you can replace the array (if it is an array) which you have with:
Thearray.cpu().numpy()

.idmin() and .idmax() in a Series not working

I am learning about python/pandas attributes in a Series. I can get it to display the min and max values, but I want to display the min and max index values and I get an error message.
google.min()
49.95
google.max()
782.22
google.idmin()
AttributeError Traceback (most recent
call last) in
----> 1 google.idmin(True)
/opt/anaconda3/envs/pandas_playground/lib/python3.8/site-packages/pandas/core/generic.py
in getattr(self, name) 5272 if
self._info_axis._can_hold_identifiers_and_holds_name(name): 5273
return self[name]
-> 5274 return object.getattribute(self, name) 5275 5276 def setattr(self, name: str, value) -> None:
AttributeError: 'Series' object has no attribute 'idmin'
After some searching, I found I was simply using the wrong methods.
idxmin and idxmax work just fine.
google.idxmax()
3011
google.idxmin()
11

Google AdManager getCurrentNetwork() error

I have set up ad manager credentials. I'm trying to access the Admanager API, im getting the following error.
from googleads import ad_manager
client = ad_manager.AdManagerClient.LoadFromStorage()
network_service = client.GetService('NetworkService', version='v201902')
current_network = network_service.getCurrentNetwork()
the error im facing is:
Fault Traceback (most recent call last)
~\Anaconda3\lib\site-packages\googleads\common.py in MakeSoapRequest(*args)
1381 return soap_service_method(
-> 1382 *packed_args, _soapheaders=soap_headers)['body']['rval']
1383 except zeep.exceptions.Fault as e:
~\Anaconda3\lib\site-packages\zeep\proxy.py in __call__(self, *args, **kwargs)
41 self._proxy._client, self._proxy._binding_options,
---> 42 self._op_name, args, kwargs)
43
~\Anaconda3\lib\site-packages\zeep\wsdl\bindings\soap.py in send(self, client, options, operation, args, kwargs)
131
--> 132 return self.process_reply(client, operation_obj, response)
133
~\Anaconda3\lib\site-packages\zeep\wsdl\bindings\soap.py in process_reply(self, client, operation, response)
193 if response.status_code != 200 or fault_node is not None:
--> 194 return self.process_error(doc, operation)
195
~\Anaconda3\lib\site-packages\zeep\wsdl\bindings\soap.py in process_error(self, doc, operation)
287 actor=None,
--> 288 detail=etree_to_string(doc))
289
Fault: Unknown fault occured
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
<ipython-input-16-991c0839fc99> in <module>()
----> 1 current_network = network_service.getCurrentNetwork()
~\Anaconda3\lib\site-packages\googleads\common.py in MakeSoapRequest(*args)
1385 if e.detail is not None:
1386 underlying_exception = e.detail.find(
-> 1387 '{%s}ApiExceptionFault' % self._GetBindingNamespace())
1388 fault_type = self.zeep_client.get_element(
1389 '{%s}ApiExceptionFault' % self._GetBindingNamespace())
TypeError: a bytes-like object is required, not 'str'
You are probably missing permissions with your configured service account. Make sure the account has access to ad-manager and scopes are configured properly.
I suggest to do it this way:
class Adx:
def __init__(self):
self.GOOGLEADS_YAML = 'googleads.yaml'
self.GOOGLEADS_VERSION = 'v202111'
self.google_keys = self.GOOGLEADS_YAML
def activate(self):
ad_manager_client = ad_manager.AdManagerClient.LoadFromStorage(self.google_keys)

TypeError: 'NoneType' object is not iterable occurring only on big data

I get the error: TypeError: 'NoneType' object is not iterable
when i try to geocode over 200K IPs using the following code excerpt. Please note that when I geocode just 100K IPs no errors are occurring:
#writing a function that takes index, geocodes the ip individually for multithreading
def new_geocode_ip_ver2(ipandresponse):
if ipandresponse[1]!='0':
match=geolite2.lookup(ipandresponse[0])
if match is not None:
lat, lng = match.location
else:
lat="GC failed"
lng="GC failed"
else:
lat="Non-pingable, no GC"
lng="Non-pingable, no GC"
return lat, lng
#spawn threads for geocoding IPs
pool=ThreadPool(200)
latlng_result=pool.map(new_geocode_ip_ver2,ip_response)
pool.close()
pool.join()
The error is message is provided below. Can anyone tell me why this error is occuring on over 100k IP only. I am trying to build my program in such a way that I will be able to geocode a million + IPs. Do I have some kind of memory leak by any chance?
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-6-26e36f25645e> in <module>()
32 #spawn threads for geocoding IPs
33 pool=ThreadPool(200)
---> 34 latlng_result=pool.map(new_geocode_ip_ver2,ip_response)
35 pool.close()
36 pool.join()
C:\Users\sibag\Anaconda2\lib\multiprocessing\pool.pyc in map(self, func, iterable, chunksize)
249 '''
250 assert self._state == RUN
--> 251 return self.map_async(func, iterable, chunksize).get()
252
253 def imap(self, func, iterable, chunksize=1):
C:\Users\sibag\Anaconda2\lib\multiprocessing\pool.pyc in get(self, timeout)
565 return self._value
566 else:
--> 567 raise self._value
568
569 def _set(self, i, obj):
TypeError: 'NoneType' object is not iterable

Categories

Resources