mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-16 11:18:11 +08:00
Changes BcolzDailyBarWriter to not be an abc, data is passed as an iterator of (sid, dataframe) pairs to the write method. Changes the AssetsDBWriter to be a single class which accepts an engine at construction time and has a `write` method for writing dataframes for the various tables. We no longer support writing the various other data types, callers should coerce their data into a dataframe themselves. See zipline.assets.synthetic for some helpers to do this. Adds many new fixtures and updates some existing fixtures to use the new ones: WithDefaultDateBounds A fixture that provides the suite a START_DATE and END_DATE. This is meant to make it easy for other fixtures to synchronize their date ranges without depending on eachother in strange ways. For example, WithBcolzMinuteBarReader and WithBcolzDailyBarReader by default should both have data for the same dates, so they may use depend on WithDefaultDates without forcing a dependency between them. WithTmpDir, WithInstanceTmpDir Provides the suite or individual test case a temporary directory. WithBcolzDailyBarReader Provides the suite a BcolzDailyBarReader which reads from bcolz data written to a temporary directory. The data will be read from dataframes and then converted to bcolz files with BcolzDailyBarWriter.write WithBcolzDailyBarReaderFromCSVs Provides the suite a BcolzDailyBarReader which reads from bcolz data written to a temporary directory. The data will be read from a collection of CSV files and then converted into the bcolz data through BcolzDailyBarWriter.write_csvs WithBcolzMinuteBarReader Provides the suite a BcolzMinuteBarReader which reads from bcolz data written to a temporary directory. The data will be read from dataframes and then converted to bcolz files with BcolzMinuteBarWriter.write WithAdjustmentReader Provides the suite a SQLiteAdjustmentReader which reads from an in memory sqlite database. The data will be read from dataframes and then converted into sqlite with SQLiteAdjustmentWriter.write WithDataPortal Provides each test case a DataPortal object with data from temporary resources.
75 lines
2.1 KiB
Python
75 lines
2.1 KiB
Python
from operator import attrgetter
|
|
|
|
|
|
def compose_types(a, b, *cs):
|
|
"""Compose multiple classes together.
|
|
|
|
Parameters
|
|
----------
|
|
*mcls : tuple[type]
|
|
The classes that you would like to compose
|
|
|
|
Returns
|
|
-------
|
|
cls : type
|
|
A type that subclasses all of the types in ``mcls``.
|
|
|
|
Notes
|
|
-----
|
|
A common use case for this is to build composed metaclasses, for example,
|
|
imagine you have some simple metaclass ``M`` and some instance of ``M``
|
|
named ``C`` like so:
|
|
|
|
.. code-block:: python
|
|
|
|
class M(type):
|
|
def __new__(mcls, name, bases, dict_):
|
|
dict_['ayy'] = 'lmao'
|
|
return super().__new__(mcls, name, bases, dict_)
|
|
|
|
|
|
class C(metaclass=M):
|
|
pass
|
|
|
|
|
|
We now want to create a sublclass of ``C`` that is also an abstract class.
|
|
We can use ``compose_types`` to create a new metaclass that is a subclass
|
|
of ``M`` and ``ABCMeta``. This is needed because a subclass of a class
|
|
with a metaclass must have a metaclass which is a subclass of the metaclass
|
|
of the superclass.
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
class D(C, metaclass=compose_types(M, ABCMeta)):
|
|
@abstractmethod
|
|
def f(self):
|
|
raise NotImplementedError('f')
|
|
|
|
|
|
We can see that this class has both metaclasses applied to it:
|
|
|
|
.. code-block:: python
|
|
|
|
>>> D.ayy
|
|
lmao
|
|
>>> D()
|
|
TypeError: Can't instantiate abstract class D with abstract methods f
|
|
|
|
|
|
An important note here is that ``M`` did not use ``type.__new__`` and
|
|
instead used ``super()``. This is to support cooperative multiple
|
|
inheritence which is needed for ``compose_types`` to work as intended.
|
|
After we have composed these types ``M.__new__``\'s super will actually
|
|
go to ``ABCMeta.__new__`` and not ``type.__new__``.
|
|
|
|
Always using ``super()`` to dispatch to your superclass is best practices
|
|
anyways so most classes should compose without much special considerations.
|
|
"""
|
|
mcls = (a, b) + cs
|
|
return type(
|
|
'compose_types(%s)' % ', '.join(map(attrgetter('__name__'), mcls)),
|
|
mcls,
|
|
{},
|
|
)
|