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

Function test_array_protocol

python/pyarrow/tests/test_pandas.py:4356–4382  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4354
4355
4356def test_array_protocol():
4357 df = pd.DataFrame({'a': pd.Series([1, 2, None], dtype='Int64')})
4358
4359 # __arrow_array__ added to pandas IntegerArray in 0.26.0.dev
4360
4361 # default conversion
4362 result = pa.table(df)
4363 expected = pa.array([1, 2, None], pa.int64())
4364 assert result[0].chunk(0).equals(expected)
4365
4366 # with specifying schema
4367 schema = pa.schema([('a', pa.float64())])
4368 result = pa.table(df, schema=schema)
4369 expected2 = pa.array([1, 2, None], pa.float64())
4370 assert result[0].chunk(0).equals(expected2)
4371
4372 # pass Series to pa.array
4373 result = pa.array(df['a'])
4374 assert result.equals(expected)
4375 result = pa.array(df['a'], type=pa.float64())
4376 assert result.equals(expected2)
4377
4378 # pass actual ExtensionArray to pa.array
4379 result = pa.array(df['a'].values)
4380 assert result.equals(expected)
4381 result = pa.array(df['a'].values, type=pa.float64())
4382 assert result.equals(expected2)
4383
4384
4385class DummyExtensionType(pa.ExtensionType):

Callers

nothing calls this directly

Calls 3

equalsMethod · 0.80
arrayMethod · 0.45
schemaMethod · 0.45

Tested by

no test coverage detected