<commit_before>from django.db.backends.postgresql_psycopg2.base import DatabaseOperations
from django_chem.db.backends.base import BaseChemOperations
from django_chem.db.backends.util import ChemOperation, ChemFunction

#### Classes used in constructing RDKit chemical SQL ####
class RDKitOperator(ChemOperation):
    "For RDKit operators (e.g. `@>`, `<@`, `#`, `%`, ...)."
    def __init__(self, operator):
        super(RDKitOperator, self).__init__(operator=operator)

    def as_sql(self, col):
        if self.operator != '==': 
            return super(RDKitOperator, self).as_sql(col)

        return super(RDKitOperator, self).as_sql(col, '%s::mol')



class RDKitFunction(ChemFunction):
    "For RDKit function calls (e.g., ``)."
    def __init__(self, function, **kwargs):
        super(RDKitFunction, self).__init__(function, **kwargs)

class RDKitOperations(DatabaseOperations, BaseChemOperations):

    postgresql_rdkit = True

    def __init__(self, connection):
        super(RDKitOperations, self).__init__(connection)

        self.substructure_operators = {
            'contains'  : RDKitOperator('@>'),
            'contained' : RDKitOperator('<@'),
            'exact' : RDKitOperator('@='),
            }

        # Creating a dictionary lookup of all chem terms for the RDKit backend.
        chem_terms = ['isnull']
        chem_terms += self.substructure_operators.keys()
        self.chem_terms = dict([(term, None) for term in chem_terms])

    def chem_db_type(self, field_name):
        try:
            return {
                'MoleculeField':     'mol',
                }[field_name]
        except KeyError:
            raise NotImplementedError('%s is not implemented for this backend.' 
                                      % field_name)
<commit_msg>Remove unneeded ::mol cast on SQL queries<commit_after>from django.db.backends.postgresql_psycopg2.base import DatabaseOperations
from django_chem.db.backends.base import BaseChemOperations
from django_chem.db.backends.util import ChemOperation, ChemFunction

#### Classes used in constructing RDKit chemical SQL ####
class RDKitOperator(ChemOperation):
    "For RDKit operators (e.g. `@>`, `<@`, `#`, `%`, ...)."
    def __init__(self, operator):
        super(RDKitOperator, self).__init__(operator=operator)


class RDKitFunction(ChemFunction):
    "For RDKit function calls (e.g., ``)."
    def __init__(self, function, **kwargs):
        super(RDKitFunction, self).__init__(function, **kwargs)


class RDKitOperations(DatabaseOperations, BaseChemOperations):

    postgresql_rdkit = True

    def __init__(self, connection):
        super(RDKitOperations, self).__init__(connection)

        self.substructure_operators = {
            'contains'  : RDKitOperator('@>'),
            'contained' : RDKitOperator('<@'),
            'exact' : RDKitOperator('@='),
            }

        # Creating a dictionary lookup of all chem terms for the RDKit backend.
        chem_terms = ['isnull']
        chem_terms += self.substructure_operators.keys()
        self.chem_terms = dict([(term, None) for term in chem_terms])

    def chem_db_type(self, field_name):
        try:
            return {
                'MoleculeField':     'mol',
                }[field_name]
        except KeyError:
            raise NotImplementedError('%s is not implemented for this backend.' 
                                      % field_name)

{'fraction_non_alphanumeric': 0.11895692938763551, 'fraction_numerical': 0.0005859947260474656, 'mean_word_length': 2.8060200668896322, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7655781', 'n_tokens_mistral': 1023, 'n_tokens_neox': 952, 'n_words': 226}