Skip to content

Commit d41078c

Browse files
committed
[Python] Add type mapping for NPY_LONGLONG
Closes #79 Author: Wes McKinney <wesm@apache.org> Closes #107 from wesm/bug/numpy-long-long and squashes the following commits: 109ab60 [Wes McKinney] Add type mapping for NPY_LONGLONG
1 parent f829c69 commit d41078c

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

python/feather/interop.h

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,28 @@ struct npy_traits<NPY_BOOL> {
4747
}
4848
};
4949

50-
#define NPY_INT_DECL(TYPE, T) \
50+
#define NPY_INT_DECL(TYPE, FTYPE, T) \
5151
template <> \
5252
struct npy_traits<NPY_##TYPE> { \
5353
typedef T value_type; \
54-
static constexpr PrimitiveType::type feather_type = PrimitiveType::TYPE; \
54+
static constexpr PrimitiveType::type feather_type = PrimitiveType::FTYPE; \
5555
static constexpr bool supports_nulls = false; \
5656
static inline bool isnull(T v) { \
5757
return false; \
5858
} \
5959
};
6060

61-
NPY_INT_DECL(INT8, int8_t);
62-
NPY_INT_DECL(INT16, int16_t);
63-
NPY_INT_DECL(INT32, int32_t);
64-
NPY_INT_DECL(INT64, int64_t);
65-
NPY_INT_DECL(UINT8, uint8_t);
66-
NPY_INT_DECL(UINT16, uint16_t);
67-
NPY_INT_DECL(UINT32, uint32_t);
68-
NPY_INT_DECL(UINT64, uint64_t);
61+
NPY_INT_DECL(INT8, INT8, int8_t);
62+
NPY_INT_DECL(INT16, INT16, int16_t);
63+
NPY_INT_DECL(INT32, INT32, int32_t);
64+
NPY_INT_DECL(INT64, INT64, int64_t);
65+
NPY_INT_DECL(LONGLONG, INT64, int64_t);
66+
67+
NPY_INT_DECL(UINT8, UINT8, uint8_t);
68+
NPY_INT_DECL(UINT16, UINT16, uint16_t);
69+
NPY_INT_DECL(UINT32, UINT32, uint32_t);
70+
NPY_INT_DECL(UINT64, UINT64, uint64_t);
71+
NPY_INT_DECL(ULONGLONG, UINT64, uint64_t);
6972

7073
template <>
7174
struct npy_traits<NPY_FLOAT32> {
@@ -414,10 +417,12 @@ Status pandas_masked_to_primitive(PyObject* ao, PyObject* mo,
414417
TO_FEATHER_CASE(INT16);
415418
TO_FEATHER_CASE(INT32);
416419
TO_FEATHER_CASE(INT64);
420+
TO_FEATHER_CASE(LONGLONG);
417421
TO_FEATHER_CASE(UINT8);
418422
TO_FEATHER_CASE(UINT16);
419423
TO_FEATHER_CASE(UINT32);
420424
TO_FEATHER_CASE(UINT64);
425+
TO_FEATHER_CASE(ULONGLONG);
421426
TO_FEATHER_CASE(FLOAT32);
422427
TO_FEATHER_CASE(FLOAT64);
423428
TO_FEATHER_CASE(OBJECT);

python/feather/tests/test_reader.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ def test_float_nulls(self):
116116
def test_integer_no_nulls(self):
117117
data = {}
118118

119-
numpy_dtypes = ['i1', 'i2', 'i4', 'i8', 'u1', 'u2', 'u4', 'u8']
119+
numpy_dtypes = ['i1', 'i2', 'i4', 'i8',
120+
'u1', 'u2', 'u4', 'u8']
120121
num_values = 100
121122

122123
for dtype in numpy_dtypes:
@@ -129,6 +130,19 @@ def test_integer_no_nulls(self):
129130
df = pd.DataFrame(data)
130131
self._check_pandas_roundtrip(df)
131132

133+
def test_platform_numpy_integers(self):
134+
data = {}
135+
136+
numpy_dtypes = ['longlong']
137+
num_values = 100
138+
139+
for dtype in numpy_dtypes:
140+
values = np.random.randint(0, 100, size=num_values)
141+
data[dtype] = values.astype(dtype)
142+
143+
df = pd.DataFrame(data)
144+
self._check_pandas_roundtrip(df)
145+
132146
def test_integer_with_nulls(self):
133147
# pandas requires upcast to float dtype
134148
path = random_path()

0 commit comments

Comments
 (0)