Skip to content

Commit d3401a9

Browse files
committed
added embryonic binop broadcasting test
1 parent 4726d13 commit d3401a9

File tree

1 file changed

+68
-1
lines changed

1 file changed

+68
-1
lines changed

larray/tests/test_la.py

+68-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import larray
1616
from larray import (LArray, Axis, ValueGroup, union, to_ticks, to_key,
1717
srange, larray_equal, read_csv, read_hdf, df_aslarray,
18-
zeros, zeros_like, AxisCollection,
18+
zeros, zeros_like, ndrange, AxisCollection,
1919
DataFrameLArray, SeriesLArray)
2020
from larray.utils import array_equal, array_nan_equal
2121

@@ -1744,6 +1744,73 @@ def test_plot(self):
17441744
#large.hist()
17451745

17461746

1747+
class RangeAxisFactory(object):
1748+
def __init__(self, length, reverse=False):
1749+
self.length = length
1750+
self.reverse = reverse
1751+
1752+
def __getattr__(self, key):
1753+
r = range(self.length)
1754+
if self.reverse:
1755+
r = list(reversed(r))
1756+
return Axis(key, r)
1757+
1758+
1759+
class TestLArrayBroadcasting(TestCase):
1760+
def test_simple(self):
1761+
ax2 = RangeAxisFactory(2)
1762+
ax2r = RangeAxisFactory(2, reverse=True)
1763+
ax3 = RangeAxisFactory(3)
1764+
ax3r = RangeAxisFactory(3, reverse=True)
1765+
1766+
a, b, c, d = ax2.a, ax3.b, ax2.c, ax3.d
1767+
a2, b2, c2, d2 = ax3r.a, ax2r.b, ax3r.c, ax2r.d
1768+
1769+
# OK (except Pandas join direction bug)
1770+
df1 = ndrange((a, b, c), cls=DataFrameLArray)
1771+
df2 = ndrange((b2, c2), cls=DataFrameLArray)
1772+
df1 + df2
1773+
1774+
# OK
1775+
df1 = ndrange((a, b, c), cls=DataFrameLArray)
1776+
df2 = ndrange((a2,), cls=SeriesLArray)
1777+
df1 + df2
1778+
1779+
# OK
1780+
df1 = ndrange((a, b, c), cls=DataFrameLArray)
1781+
df2 = ndrange((a2, b2, c2), cls=SeriesLArray)
1782+
df1 + df2
1783+
1784+
# OK
1785+
df1 = ndrange((a, b, c), cls=DataFrameLArray)
1786+
df2 = ndrange((a2, b2), cls=SeriesLArray)
1787+
df1 + df2
1788+
1789+
# OK
1790+
df1 = ndrange((a, b, c), cls=DataFrameLArray)
1791+
df2 = ndrange((a2, c2), cls=SeriesLArray)
1792+
df1 + df2
1793+
1794+
# OK
1795+
df1 = ndrange((a, b, c, d), cls=DataFrameLArray)
1796+
df2 = ndrange((a2, b2, d2), cls=DataFrameLArray)
1797+
df1 + df2
1798+
1799+
# OK
1800+
df1 = ndrange((a, d, b), cls=DataFrameLArray)
1801+
df2 = ndrange((a2, c2, b2), cls=DataFrameLArray)
1802+
df1 + df2
1803+
1804+
# OK
1805+
df1 = ndrange((a, b, c), cls=DataFrameLArray)
1806+
df2 = ndrange((a2, b2, d2), cls=SeriesLArray)
1807+
df1 + df2
1808+
1809+
# OK
1810+
df1 = ndrange((a, b, c), cls=DataFrameLArray)
1811+
df2 = ndrange((a2, b2, d2), cls=DataFrameLArray)
1812+
df1 + df2
1813+
17471814
if __name__ == "__main__":
17481815
import doctest
17491816
doctest.testmod(larray.core)

0 commit comments

Comments
 (0)