Skip to content

Commit 070a000

Browse files
author
gerrymanoim
authored
ENH: Drop Py2 (#150)
1 parent b5f5a83 commit 070a000

31 files changed

+138
-949
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
os: [ubuntu-18.04, macos-10.15]
19-
python-version: [2.7, 3.5, 3.6, 3.8]
19+
python-version: [3.5, 3.6, 3.8]
2020
compiler: [gcc, clang]
2121
exclude:
2222
- os: macos-10.15
2323
compiler: gcc
2424
include:
25-
- python-version: 2.7
26-
numpy: 1.11.3
2725
- python-version: 3.5
2826
numpy: 1.11.3
2927
- python-version: 3.6

include/libpy/any.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,6 @@ struct to_object<py::any_cref> {
587587
};
588588
} // namespace dispatch
589589

590-
591590
namespace detail {
592591
template<std::size_t max_size, typename T>
593592
struct make_string_vtable_impl;
@@ -601,7 +600,7 @@ struct make_string_vtable_impl<max_size, std::index_sequence<head, tail...>> {
601600
default:
602601
return make_string_vtable_impl<max_size, std::index_sequence<tail...>>::f(
603602
size);
604-
}
603+
}
605604
}
606605
};
607606

@@ -626,8 +625,7 @@ inline any_vtable make_string_vtable(int size) {
626625
@param dtype The runtime numpy dtype.
627626
@return The any_vtable that corresponds to the given dtype.
628627
*/
629-
inline any_vtable
630-
dtype_to_vtable(py::borrowed_ref<PyArray_Descr> dtype) {
628+
inline any_vtable dtype_to_vtable(py::borrowed_ref<PyArray_Descr> dtype) {
631629
switch (dtype->type_num) {
632630
case NPY_BOOL:
633631
return any_vtable::make<py_bool>();

include/libpy/any_vector.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ class any_vector {
155155
std::byte* addr = buf + pos_to_index(ix);
156156
using raw = py::meta::remove_cvref<T>;
157157
if constexpr (std::is_same_v<raw, any_ref> || std::is_same_v<raw, any_cref>) {
158-
construct(addr, value.addr());
159-
}
158+
construct(addr, value.addr());
159+
}
160160
else {
161161
construct(addr, std::addressof(value));
162162
}
@@ -302,8 +302,7 @@ class any_vector {
302302
: m_vtable(vtable),
303303
m_storage(vtable.default_construct_alloc(count)),
304304
m_size(count),
305-
m_capacity(count) {
306-
}
305+
m_capacity(count) {}
307306

308307
private:
309308
template<typename T>
@@ -611,7 +610,6 @@ class any_vector {
611610
}
612611
};
613612

614-
615613
inline owned_ref<> move_to_numpy_array(py::any_vector&& values) {
616614

617615
auto descr = values.vtable().new_dtype();

include/libpy/autoclass.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "libpy/demangle.h"
1212
#include "libpy/detail/autoclass_cache.h"
1313
#include "libpy/detail/autoclass_object.h"
14-
#include "libpy/detail/autoclass_py2.h"
1514
#include "libpy/detail/python.h"
1615
#include "libpy/meta.h"
1716
#include "libpy/scope_guard.h"
@@ -32,6 +31,7 @@ constexpr void zero_non_pyobject_base(T* b) {
3231
}
3332

3433
namespace detail {
34+
3535
template<typename T>
3636
constexpr void nop_clear_base(T*) {}
3737
} // namespace detail
@@ -320,7 +320,7 @@ class autoclass_impl {
320320
@return The `tp_flags` to use for this autoclass generated type.
321321
*/
322322
static unsigned int flags(int extra_flags, py::borrowed_ref<PyTypeObject> base_type) {
323-
unsigned int out = detail::autoclass_base_flags;
323+
unsigned int out = Py_TPFLAGS_DEFAULT;
324324
out |= extra_flags;
325325
if (base_type && base_type->tp_flags & Py_TPFLAGS_HAVE_GC) {
326326
out |= Py_TPFLAGS_HAVE_GC;
@@ -1237,11 +1237,8 @@ class autoclass_impl {
12371237
std::stringstream s;
12381238
s << unbox(self);
12391239
std::string data = s.str();
1240-
#if PY_MAJOR_VERSION == 2
1241-
return PyString_FromStringAndSize(data.data(), data.size());
1242-
#else
1240+
12431241
return PyUnicode_FromStringAndSize(data.data(), data.size());
1244-
#endif
12451242
}
12461243
catch (const std::exception& e) {
12471244
return raise_from_cxx_exception(e);
@@ -1265,11 +1262,8 @@ class autoclass_impl {
12651262
try {
12661263
auto res = std::invoke(impl, unbox(self));
12671264
std::string data(std::begin(res), std::end(res));
1268-
#if PY_MAJOR_VERSION == 2
1269-
return PyString_FromStringAndSize(data.data(), data.size());
1270-
#else
1265+
12711266
return PyUnicode_FromStringAndSize(data.data(), data.size());
1272-
#endif
12731267
}
12741268
catch (const std::exception& e) {
12751269
return raise_from_cxx_exception(e);

include/libpy/datetime64.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,7 @@ write(char* data, char* end, std::ptrdiff_t& ix, char c, std::int64_t count) {
423423
return {};
424424
}
425425

426-
inline no_discard_errc
427-
write(char* data, char* end, std::ptrdiff_t& ix, std::int64_t v) {
426+
inline no_discard_errc write(char* data, char* end, std::ptrdiff_t& ix, std::int64_t v) {
428427
#if defined(_LIBCPP_VERSION)
429428
// XXX: workaround for a bug in libc++ which adds unnecessary leading 0s to
430429
// 64 bit integers with 9, 10, or 11 digits.
@@ -498,7 +497,8 @@ to_chars(char* first, char* last, const datetime64<unit>& dt, bool compress = fa
498497
return detail::formatting::write(first, last, ix, args...);
499498
};
500499

501-
auto zero_pad = [&](int expected_digits, std::int64_t value) -> detail::no_discard_errc {
500+
auto zero_pad = [&](int expected_digits,
501+
std::int64_t value) -> detail::no_discard_errc {
502502
std::int64_t digits = std::floor(std::log10(value));
503503
digits += 1;
504504
if (expected_digits > digits) {
@@ -596,8 +596,7 @@ to_chars(char* first, char* last, const datetime64<unit>& dt, bool compress = fa
596596
return finalize(ec);
597597
}
598598
std::int64_t expected_digits = std::log10(unit::period::den);
599-
if (auto ec = zero_pad(expected_digits, fractional_seconds);
600-
ec != std::errc{}) {
599+
if (auto ec = zero_pad(expected_digits, fractional_seconds); ec != std::errc{}) {
601600
return finalize(ec);
602601
}
603602
if (auto ec = write(fractional_seconds); ec != std::errc{}) {

include/libpy/detail/autoclass_py2.h

Lines changed: 0 additions & 112 deletions
This file was deleted.

include/libpy/detail/numpy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,5 @@
5353
#endif
5454
#endif
5555
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
56-
#include "libpy/detail/python.h" // include this before numpy to silence warnings in py2
56+
#include "libpy/detail/python.h"
5757
#include <numpy/arrayobject.h>

include/libpy/detail/python.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#pragma once
22

3-
// This triggers a warning in Python 2, add a standard place to find this header that
4-
// doesn't trigger this warning.
5-
#if PY_MAJOR_VERSION == 2
6-
#undef _POSIX_C_SOURCE
7-
#undef _XOPEN_SOURCE
8-
#endif
3+
// NOTE: This is a relic of supporting both py2 and py3, but this provides
4+
// A standard place to find this header and make python version dependent
5+
// modifications if necessary.
96
#include <Python.h>

include/libpy/devirtualize.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ struct nwise_nddevirtualize {
143143
template<typename F, typename E>
144144
void for_each_with_ix_helper(F&& f, const std::vector<E>& entries) const {
145145
for (const auto& [views, ix] : entries) {
146-
std::apply([&, &ix = ix](const auto &... args) { f(ix, args...); },
147-
views);
146+
std::apply([&, &ix = ix](const auto&... args) { f(ix, args...); }, views);
148147
}
149148
}
150149

include/libpy/from_object.h

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -304,27 +304,13 @@ struct int_from_object {
304304
static T f(py::borrowed_ref<> value) {
305305
wide_type wide;
306306

307-
#if PY_MAJOR_VERSION == 2
308-
if (PyInt_Check(value.get())) {
309-
if constexpr (std::is_signed_v<T>) {
310-
wide = PyInt_AS_LONG(value.get());
311-
}
312-
else {
313-
wide = static_cast<wide_type>(PyInt_AS_LONG(value.get()));
314-
}
307+
// convert the object to the widest type for the given signedness
308+
if constexpr (std::is_signed_v<T>) {
309+
wide = PyLong_AsLongLong(value.get());
315310
}
316311
else {
317-
#endif
318-
// convert the object to the widest type for the given signedness
319-
if constexpr (std::is_signed_v<T>) {
320-
wide = PyLong_AsLongLong(value.get());
321-
}
322-
else {
323-
wide = PyLong_AsUnsignedLongLong(value.get());
324-
}
325-
#if PY_MAJOR_VERSION == 2
312+
wide = PyLong_AsUnsignedLongLong(value.get());
326313
}
327-
#endif
328314

329315
// check if `value` would overflow `wide_type`
330316
if (PyErr_Occurred()) {

0 commit comments

Comments
 (0)