Monday, 1 February 2021

Numpy Where Multiple Conditions , cannot compare a dtyped [object] array with a scalar of type [bool]

I am trying to do multiple conditions in a numpy where but getting the error: cannot compare a dtyped [object] array with a scalar of type [bool]

Here is the line:

d7['CAD'] = np.where(d7['Category'] == 'Stack' & d7['Currency'] == fxratetable['from_currency'],d7['CAD'] * fxratetable['fx_rate'], d7['CAD'])

All dtypes are object except for fx_rate which is float64.

Also another thought is that I am looking for one value with Category = Stack but looking for multiple values with my Currency = from_currency.

Can anyone help with this?

Thanks.

new error

ValueError: Can only compare identically-labeled Series objects now. 

This is my new statement

d7['CAD'] = np.where((d7['Category'] == 'Stack') & 
                     (d7['Currency'] == fxratetable['from_currency']),
                     d7['CAD'] * fxratetable['fx_rate'], 
                     d7['CAD'])

d7:

+--------------+----------+----------+
| CAD          | Currency | Category |
+--------------+----------+----------+
| -4350242.355 | GBP      | Stack    |
+--------------+----------+----------+
| 424223.7584  | AUD      | Stack    |
+--------------+----------+----------+

fxratetable:

+---------------+---------+
| from_currency | fx_rate |
+---------------+---------+
| GBP           | 1.367   |
+---------------+---------+
| AUD           | 0.7706  |
+---------------+---------+

Expected new CAD column.

+----------------+
| CAD (expected) |
+----------------+
| -5948957.275   |
+----------------+
| 326991.5663    |
+----------------+


from Numpy Where Multiple Conditions , cannot compare a dtyped [object] array with a scalar of type [bool]

downloading on DownloadManager and saving file in setDestinationInExternalFilesDir() is not working on Android 10

Im using DownloadManager to save the mp4 that comes from the server. Im saving the file on storage/Emulated/0/Android/data/<packagename>/files/.Videos. I notice that on Android 9 and android 11 is successfully downloading it. But in Android 10 failed. I tried to enclose it on try{}catch{} method but i can't see anything on logs. I also try to add android:requestLegacyExternalStorage="true" on my Android Manifest.xml but the error still occurs. I also refer on this question which he/she using setDestinationUri() but still i can't find a way. BTW, this is my snippet of the DownloadRequest:

val path: String =
            context.getExternalFilesDir(null)?.absolutePath + "/" + ".Videos"

val downloadmanager: DownloadManager =
            context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
        val request: DownloadManager.Request = DownloadManager.Request(uri)
            .setTitle(videoName)
            .setDescription("Downloading")
            .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
            .setDestinationInExternalFilesDir(context, ".Videos", "test1.mp4")
            //.setDestinationUri(Uri.fromFile(File(path, "test.mp4")))
            //.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,videoName)
        val downloadId = downloadmanager.enqueue(request)

All response is deeply appreciated :)



from downloading on DownloadManager and saving file in setDestinationInExternalFilesDir() is not working on Android 10

How to match all domain extensions in content script (firefox)?

I need to match all domain extensions for a simple Firefox extension I am writing. For example, I need to the extension to run on:

I do not want the extension to run on anything that isn't the 'example website, e.g.,

This is important, in part, so that I do not need to get permission to access data on all website for my extension.

Notes:



from How to match all domain extensions in content script (firefox)?