Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_column(self):
col = Column('b')
self._assert_equal_filter(col > 2, Greater('b', 2))
self._assert_equal_filter(col >= 2, GreaterEqual('b', 2))
self._assert_equal_filter(col < 2, Less('b', 2))
self._assert_equal_filter(col <= 2, LessEqual('b', 2))
self._assert_equal_filter(col == 2, Equal('b', 2))
self._assert_equal_filter(col != 2, ~Equal('b', 2))
self._assert_equal_filter(col.isin([1, 2, 3]), IsIn('b', [1, 2, 3]))
self._assert_equal_filter(col.like('a*b'), Like('b', 'a*b'))
self._assert_equal_filter(col.rlike('a*b'), Rlike('b', 'a*b'))
self._assert_equal_filter(col.startswith('jj'), Startswith('b', 'jj'))
self._assert_equal_filter(col.isnull, IsNull('b'))
self._assert_equal_filter(col.notnull, NotNull('b'))
def __getattr__(self, name):
"""
Returns a :class:`types.Column ` object denoted by ``name``.
"""
if name not in self.columns:
raise AttributeError(
"'%s' object has no attribute '%s'" % (self.__class__.__name__, name))
return Column(name)
def __getitem__(self, item):
if isinstance(item, six.string_types):
if item not in self._columns:
raise ColumnExprException('Column does not exist: [{0}]'.format(item))
return Column(item)
elif isinstance(item, Filter):
self._filter = item
return self
else:
raise ColumnExprException('Unsupported expr: [{0}]'.format(item))
def __getitem__(self, item):
if isinstance(item, six.string_types):
if item not in self.columns:
raise TypeError('Column does not exist: [{0}]'.format(item))
return Column(item)
elif isinstance(item, BooleanFilter):
self._filter = item
return self
else:
raise TypeError('Unsupported expr: [{0}]'.format(item))
def groupby(self, *cols):
"""
Returns a new :class:`DataFrame ` object grouped by the specified column(s).
:param cols: A list of column names, :class:`Column ` or :class:`Grouper ` objects
"""
columns = []
if len(cols) == 1 and isinstance(cols[0], Grouper):
groupby = cols[0].build()
else:
for col in cols:
if isinstance(col, six.string_types):
columns.append(getattr(self, col))
elif isinstance(col, Column):
columns.append(col)
else:
raise TypeError('{0} is supposed to be str or Column'.format(col))
names = [col.field_name() for col in columns]
groupby = Grouper.from_list(names).build()
return DataFrame(client=self._client,
index=self._index,
doc_type=self._doc_type,
mapping=self._mapping,
filter=self._filter,
groupby=groupby,
aggregation=self._aggregation,
projection=self._projection,
sort=self._sort,
limit=self.limit,