MCPcopy Create free account
hub / github.com/apache/arrow / test_custom_nulls

Method test_custom_nulls

python/pyarrow/tests/test_csv.py:1244–1288  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1242 assert table.to_pydict() == expected
1243
1244 def test_custom_nulls(self):
1245 # Infer nulls with custom values
1246 opts = ConvertOptions(null_values=['Xxx', 'Zzz'])
1247 rows = b"""a,b,c,d\nZzz,"Xxx",1,2\nXxx,#N/A,,Zzz\n"""
1248 table = self.read_bytes(rows, convert_options=opts)
1249 schema = pa.schema([('a', pa.null()),
1250 ('b', pa.string()),
1251 ('c', pa.string()),
1252 ('d', pa.int64())])
1253 assert table.schema == schema
1254 assert table.to_pydict() == {
1255 'a': [None, None],
1256 'b': ["Xxx", "#N/A"],
1257 'c': ["1", ""],
1258 'd': [2, None],
1259 }
1260
1261 opts = ConvertOptions(null_values=['Xxx', 'Zzz'],
1262 strings_can_be_null=True)
1263 table = self.read_bytes(rows, convert_options=opts)
1264 assert table.to_pydict() == {
1265 'a': [None, None],
1266 'b': [None, "#N/A"],
1267 'c': ["1", ""],
1268 'd': [2, None],
1269 }
1270 opts.quoted_strings_can_be_null = False
1271 table = self.read_bytes(rows, convert_options=opts)
1272 assert table.to_pydict() == {
1273 'a': [None, None],
1274 'b': ["Xxx", "#N/A"],
1275 'c': ["1", ""],
1276 'd': [2, None],
1277 }
1278
1279 opts = ConvertOptions(null_values=[])
1280 rows = b"a,b\n#N/A,\n"
1281 table = self.read_bytes(rows, convert_options=opts)
1282 schema = pa.schema([('a', pa.string()),
1283 ('b', pa.string())])
1284 assert table.schema == schema
1285 assert table.to_pydict() == {
1286 'a': ["#N/A"],
1287 'b': [""],
1288 }
1289
1290 def test_custom_bools(self):
1291 # Infer booleans with custom values

Callers

nothing calls this directly

Calls 4

read_bytesMethod · 0.95
ConvertOptionsClass · 0.90
schemaMethod · 0.45
stringMethod · 0.45

Tested by

no test coverage detected