<commit_before>from StringIO import StringIO
import pickle
import sys
import gc
import copy
from os import path
from numpy.testing import *
from numpy.testing.utils import _assert_valid_refcount
from numpy.compat import asbytes, asunicode
import numpy as np

if sys.version_info[0] >= 3:
    import io
    StringIO = io.BytesIO

rlevel = 1

class TestRegression(TestCase):
    def test_invalid_round(self,level=rlevel):
        """Ticket #3"""
        v = 4.7599999999999998
        assert_array_equal(np.array([v]),np.array(v))

    def test_mem_empty(self,level=rlevel):
        """Ticket #7"""
        np.empty((1,),dtype=[('x',np.int64)])

    def test_pickle_transposed(self,level=rlevel):
        """Ticket #16"""
        a = np.transpose(np.array([[2,9],[7,0],[3,8]]))
        f = StringIO()
        pickle.dump(a,f)
        f.seek(0)
        b = pickle.load(f)
        f.close()
        assert_array_equal(a,b)

    def test_typeNA(self,level=rlevel):
        """Ticket #31"""
        assert_equal(np.typeNA[np.int64],'Int64')
        assert_equal(np.typeNA[np.uint64],'UInt64')

    def test_dtype_names(self,level=rlevel):
        """Ticket #35"""
        dt = np.dtype([(('name','label'),np.int32,3)])

    def test_reduce(self,level=rlevel):
        """Ticket #40"""
        assert_almost_equal(np.add.reduce([1.,.5],dtype=None), 1.5)

    def test_zeros_order(self,level=rlevel):
        """Ticket #43"""
        np.zeros([3], int, 'C')
        np.zeros([3], order='C')
        np.zeros([3], int, order='C')

    def test_sort_bigendian(self,level=rlevel):
        """Ticket #47"""
        a = np.linspace(0, 10, 11)
        c = a.astype(np.dtype('<f8'))
        c.sort()
        assert_array_almost_equal(c, a)

    def test_negative_nd_indexing(self,level=rlevel):
        """Ticket #49"""
        c = np.arange(125).reshape((5,5,5))
        origidx = np.array([-1, 0, 1])
        idx = np.array(origidx)
        c[idx]
        assert_array_equal(idx, origidx)

    def test_char_dump(self,level=rlevel):
        """Ticket #50"""
        f = StringIO()
        ca = np.char.array(np.arange(1000,1010),itemsize=4)
        ca.dump(f)
        f.seek(0)
        ca = np.load(f)
        f.close()

    def test_noncontiguous_fill(self,level=rlevel):
        """Ticket #58."""
        a = np.zeros((5,3))
        b = a[:,:2,]
        def rs():
            b.shape = (10,)
        self.failUnlessRaises(AttributeError,rs)

    def test_bool(self,level=rlevel):
        """Ticket #60"""
        x = np.bool_(1)

    def test_indexing1(self,level=rlevel):
        """Ticket #64"""
        descr = [('x', [('y', [('z', 'c16', (2,)),]),]),]
        buffer = ((([6j,4j],),),)
        h = np.array(buffer, dtype=descr)
        h['x']['y']['z']

    def test_indexing2(self,level=rlevel):
        """Ticket #65"""
        descr = [('x', 'i4', (2,))]
        buffer = ([3,2],)
        h = np.array(buffer, dtype=descr)
        h['x']

    def test_round(self,level=rlevel):
        """Ticket #67"""
        x = np.array([1+2j])
        assert_almost_equal(x**(-1), [1/(1+2j)])

    def test_scalar_compare(self,level=rlevel):
        """Ticket #72"""
        a = np.array(['test', 'auto'])
        assert_array_equal(a == 'auto', np.array([False,True]))
        self.assert_(a[1] == 'auto')
        self.assert_(a[0] != 'auto')
        b = np.linspace(0, 10, 11)
        self.assert_(b != 'auto')
        self.assert_(b[0] != 'auto')

    def test_unicode_swapping(self,level=rlevel):
        """Ticket #79"""
        ulen = 1
        ucs_value = u'\U0010FFFF'
        ua = np.array([[[ucs_value*ulen]*2]*3]*4, dtype='U%s' % ulen)
        ua2 = ua.newbyteorder()

    def test_object_array_fill(self,level=rlevel):
        """Ticket #86"""
        x = np.zeros(1, 'O')
        x.fill([])

    def test_mem_dtype_align(self,level=rlevel):
        """Ticket #93"""
        self.failUnlessRaises(TypeError,np.dtype,
                              {'names':['a'],'formats':['foo']},align=1)

    def test_intp(self,level=rlevel):
        """Ticket #99"""
        i_width = np.int_(0).nbytes*2 - 1
        long('0x' + 'f'*i_width,16)
        #self.failUnlessRaises(OverflowError,np.intp,'0x' + 'f'*(i_width+1),16)
        #self.failUnlessRaises(ValueError,np.intp,'0x1',32)
        assert_equal(255,np.long('0xFF',16))
        assert_equal(1024,np.long(1024))

    def test_endian_bool_indexing(self,level=rlevel):
        """Ticket #105"""
        a = np.arange(10.,dtype='>f8')
        b = np.arange(10.,dtype='<f8')
        xa = np.where((a>2) & (a<6))
        xb = np.where((b>2) & (b<6))<commit_msg>ENH: core: Fix the test for #99 -- np.long == raw Python long. The test should test np.intp instead<commit_after>from StringIO import StringIO
import pickle
import sys
import gc
import copy
from os import path
from numpy.testing import *
from numpy.testing.utils import _assert_valid_refcount
from numpy.compat import asbytes, asunicode
import numpy as np

if sys.version_info[0] >= 3:
    import io
    StringIO = io.BytesIO

rlevel = 1

class TestRegression(TestCase):
    def test_invalid_round(self,level=rlevel):
        """Ticket #3"""
        v = 4.7599999999999998
        assert_array_equal(np.array([v]),np.array(v))

    def test_mem_empty(self,level=rlevel):
        """Ticket #7"""
        np.empty((1,),dtype=[('x',np.int64)])

    def test_pickle_transposed(self,level=rlevel):
        """Ticket #16"""
        a = np.transpose(np.array([[2,9],[7,0],[3,8]]))
        f = StringIO()
        pickle.dump(a,f)
        f.seek(0)
        b = pickle.load(f)
        f.close()
        assert_array_equal(a,b)

    def test_typeNA(self,level=rlevel):
        """Ticket #31"""
        assert_equal(np.typeNA[np.int64],'Int64')
        assert_equal(np.typeNA[np.uint64],'UInt64')

    def test_dtype_names(self,level=rlevel):
        """Ticket #35"""
        dt = np.dtype([(('name','label'),np.int32,3)])

    def test_reduce(self,level=rlevel):
        """Ticket #40"""
        assert_almost_equal(np.add.reduce([1.,.5],dtype=None), 1.5)

    def test_zeros_order(self,level=rlevel):
        """Ticket #43"""
        np.zeros([3], int, 'C')
        np.zeros([3], order='C')
        np.zeros([3], int, order='C')

    def test_sort_bigendian(self,level=rlevel):
        """Ticket #47"""
        a = np.linspace(0, 10, 11)
        c = a.astype(np.dtype('<f8'))
        c.sort()
        assert_array_almost_equal(c, a)

    def test_negative_nd_indexing(self,level=rlevel):
        """Ticket #49"""
        c = np.arange(125).reshape((5,5,5))
        origidx = np.array([-1, 0, 1])
        idx = np.array(origidx)
        c[idx]
        assert_array_equal(idx, origidx)

    def test_char_dump(self,level=rlevel):
        """Ticket #50"""
        f = StringIO()
        ca = np.char.array(np.arange(1000,1010),itemsize=4)
        ca.dump(f)
        f.seek(0)
        ca = np.load(f)
        f.close()

    def test_noncontiguous_fill(self,level=rlevel):
        """Ticket #58."""
        a = np.zeros((5,3))
        b = a[:,:2,]
        def rs():
            b.shape = (10,)
        self.failUnlessRaises(AttributeError,rs)

    def test_bool(self,level=rlevel):
        """Ticket #60"""
        x = np.bool_(1)

    def test_indexing1(self,level=rlevel):
        """Ticket #64"""
        descr = [('x', [('y', [('z', 'c16', (2,)),]),]),]
        buffer = ((([6j,4j],),),)
        h = np.array(buffer, dtype=descr)
        h['x']['y']['z']

    def test_indexing2(self,level=rlevel):
        """Ticket #65"""
        descr = [('x', 'i4', (2,))]
        buffer = ([3,2],)
        h = np.array(buffer, dtype=descr)
        h['x']

    def test_round(self,level=rlevel):
        """Ticket #67"""
        x = np.array([1+2j])
        assert_almost_equal(x**(-1), [1/(1+2j)])

    def test_scalar_compare(self,level=rlevel):
        """Ticket #72"""
        a = np.array(['test', 'auto'])
        assert_array_equal(a == 'auto', np.array([False,True]))
        self.assert_(a[1] == 'auto')
        self.assert_(a[0] != 'auto')
        b = np.linspace(0, 10, 11)
        self.assert_(b != 'auto')
        self.assert_(b[0] != 'auto')

    def test_unicode_swapping(self,level=rlevel):
        """Ticket #79"""
        ulen = 1
        ucs_value = u'\U0010FFFF'
        ua = np.array([[[ucs_value*ulen]*2]*3]*4, dtype='U%s' % ulen)
        ua2 = ua.newbyteorder()

    def test_object_array_fill(self,level=rlevel):
        """Ticket #86"""
        x = np.zeros(1, 'O')
        x.fill([])

    def test_mem_dtype_align(self,level=rlevel):
        """Ticket #93"""
        self.failUnlessRaises(TypeError,np.dtype,
                              {'names':['a'],'formats':['foo']},align=1)

    def test_intp(self,level=rlevel):
        """Ticket #99"""
        i_width = np.int_(0).nbytes*2 - 1
        np.intp('0x' + 'f'*i_width,16)
        self.failUnlessRaises(OverflowError,np.intp,'0x' + 'f'*(i_width+1),16)
        self.failUnlessRaises(ValueError,np.intp,'0x1',32)
        assert_equal(255,np.intp('0xFF',16))
        assert_equal(1024,np.intp(1024))

    def test_endian_bool_indexing(self,level=rlevel):
        """Ticket #105"""
        a = np.arange(10.,dtype='>f8')
        b = np.arange(10.,dtype='<f8')
        xa = np.where((a>2) & (a<6))
        xb = np.where((b>2) & (b<6))
{'fraction_non_alphanumeric': 0.18927070989981687, 'fraction_numerical': 0.04201228051276527, 'mean_word_length': 2.5260159513862512, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6020396', 'n_tokens_mistral': 3675, 'n_tokens_neox': 3463, 'n_words': 565}