null

Weird null checking behaviour by pd.notnull

巧了我就是萌 提交于 2021-01-27 16:07:00
问题 This is essentially a rehashing of the content of my answer here. I came across some weird behaviour when trying to solve this question, using pd.notnull . Consider x = ('A4', nan) I want to check which of these items are null. Using np.isnan directly will throw a TypeError (but I've figured out how to solve that). Using pd.notnull does not work. >>> pd.notnull(x) True It treats the tuple as a single value (rather than an iterable of values). Furthermore, converting this to a list and then

Move null elements for each row in 2d array to the end of that row

落花浮王杯 提交于 2021-01-27 14:01:03
问题 Let's say I have a 2d array which looks like this: [[O, X, null, O, O, null, null], [null, null, O, null, null, O, O]] And I want it to look like this: [[O, X, O, O, null, null, null], [O, O, O, null, null, null, null]] I tried this, but it's not working: String[][] a = new String[row][col]; String[][] b = new String[row][col]; for (int i = 0; i < a.length; i++) { for (int j = 0; j < a.length; j++) { if (a[i][j] != null) { a[i][j] = b[i][j]; } else { b[i][j] = a[i][j + 1]; } } } 回答1: Some

Why does JSON null not cast to SQL null in postgres?

谁都会走 提交于 2021-01-27 05:24:34
问题 So the following PostgreSQL snippet returns null , as it should: select ('{"id": null}'::json->'id') Intuitively, one would expect the following statement to return null or an empty string: select ('{"id": null}'::json->'id')::TEXT Instead it returns the string "null". Why? Additionally, select ('{"id": null}'::json->'id')::INTEGER returns cannot cast type json to integer and select ('{"id": null}'::json->'id')::TEXT::INTEGER returns invalid input syntax for integer: "null" . (The use case

Why does JSON null not cast to SQL null in postgres?

杀马特。学长 韩版系。学妹 提交于 2021-01-27 05:24:09
问题 So the following PostgreSQL snippet returns null , as it should: select ('{"id": null}'::json->'id') Intuitively, one would expect the following statement to return null or an empty string: select ('{"id": null}'::json->'id')::TEXT Instead it returns the string "null". Why? Additionally, select ('{"id": null}'::json->'id')::INTEGER returns cannot cast type json to integer and select ('{"id": null}'::json->'id')::TEXT::INTEGER returns invalid input syntax for integer: "null" . (The use case

Check an replace null values in multiple variables java

戏子无情 提交于 2021-01-27 05:23:49
问题 I'm trying to find an easy way to perform multiple null checks/ replacements in multiple variables in Java. I have an object with about 20 String variables. In the constructor I want to check if any of the variable values are null. If they are null I want to replace them with an empty String. I could perform a series of if statements but I feel like there must be a cleaner way to do this. 回答1: Unless you want to resort to reflection (which I strongly discourage) your best bet is probably to

Why does JSON null not cast to SQL null in postgres?

我的梦境 提交于 2021-01-27 05:23:01
问题 So the following PostgreSQL snippet returns null , as it should: select ('{"id": null}'::json->'id') Intuitively, one would expect the following statement to return null or an empty string: select ('{"id": null}'::json->'id')::TEXT Instead it returns the string "null". Why? Additionally, select ('{"id": null}'::json->'id')::INTEGER returns cannot cast type json to integer and select ('{"id": null}'::json->'id')::TEXT::INTEGER returns invalid input syntax for integer: "null" . (The use case

Count the number of attributes that are NULL for a row

柔情痞子 提交于 2021-01-27 04:38:34
问题 I want to add a new column to a table to record the number of attributes whose value are null for each tuple (row). How can I use SQL to get the number? for example, if a tuple is like this: Name | Age | Sex -----+-----+----- Blice| 100 | null I want to update the tuple as this: Name | Age | Sex | nNULL -----+-----+-----+-------- Blice| 100 | null| 1 Also, because I'm writing a PL/pgSQL function and the table name is obtained from argument, I don't know the schema of a table beforehand. That

Query where foreign key column can be NULL

帅比萌擦擦* 提交于 2021-01-27 04:16:37
问题 I want to get data if orgid = 2 or if there is no row at all for the uid . orgid is an integer . The closest thing I could think of is to do IS NULL but I'm not getting data for the uid that doesn't have an orgid row. Any idea? select u.uid,u.fname,u.lname from u inner join u_org on u.uid = u_org.uid inner join login on u.uid = login.uid where u_org.orgid=2 or u_org.orgid is NULL and login.access != 4; Basically the OR is if u_org.orgid row doesn't exist. 回答1: If there is "no row at all for

Getting MatchError when using a placeholder for an unused variable

泪湿孤枕 提交于 2021-01-23 04:49:37
问题 With Scala 2.13.x, I am getting scala.MatchError: null when I use a placeholder for an unused variable: scala> object Test { | val _: Any = null | } object Test scala> Test scala.MatchError: null ... 41 elided But with Scala 2.12.x, I am not getting scala.MatchError: null : scala> object Test { | val _: Any = null | } defined object Test scala> Test res1: Test.type = Test$@784c5ef5 Any reason? 回答1: As stated in scala 2.13 release notes: Underscore is no longer a legal identifier unless

Exclude null values using JSONBuilder in Groovy

一笑奈何 提交于 2021-01-22 13:56:39
问题 Is it possible to create JSON values in Groovy using the default JsonBuilder library to exclude all the null values of an object? Such as what Jackson does in Java by annotating classes to exclude null values. An example would be: { "userId": "25", "givenName": "John", "familyName": null, "created": 1360080426303 } Which should be printed as: { "userId": "25", "givenName": "John", "created": 1360080426303 } 回答1: Not sure if it's OK for you as my method works on a Map with List properties: def