This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Because I couldn't get this to do what I wanted: | |
| # https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.compare.html | |
| import pandas as pd | |
| from typing import Optional, List | |
| def compare_dataframes(df1, df2, drop_indexes=False, ignore_columns: Optional[List]=None): | |
| '''Returns two dataframes: the rows that only show up in each dataframe''' | |
| if drop_indexes: | |
| df1 = df1.reset_index(drop=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ReduceFieldsMixin: | |
| def get_fields(self, *args, **kwargs): | |
| fields = super().get_fields(*args, **kwargs) | |
| query_params = getattr(self.context.get('request', {}), 'query_params', {}) | |
| requested_fields = query_params.get('fields', None) | |
| if requested_fields: | |
| requested_fields = requested_fields.split(',') | |
| fields = {key: value for key, value in fields.items() if key in requested_fields} | |
| return fields |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def set_up_autonumbering(engine, table, prefix): | |
| conn = engine.connect() | |
| try: | |
| logging.info("Creating autonumber sequence for {}".format(table)) | |
| conn.execute("CREATE SEQUENCE {}_ids".format(table)) | |
| except: | |
| logging.info("Autonumber sequence already created".format(table)) | |
| try: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class PerRequestFieldsSerializerMixin(): | |
| def get_field_names(self, *args, **kwargs): | |
| field_names = super().get_field_names(*args, **kwargs) | |
| request_field_names = getattr( | |
| getattr(kwargs.get('context', {}).get('view', None), 'request', None), | |
| 'query_params', {} | |
| ).get('fields', None) | |
| if request_field_names is not None: | |
| request_field_names = request_field_names.split(',') | |
| return list(set(field_names) ^ set(request_field_names)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sqlalchemy import MetaData, create_engine | |
| from sqlalchemy.orm import sessionmaker | |
| from sqlalchemy.ext.automap import automap_base | |
| from sqlalchemy.sql import select | |
| from sqlalchemy import func | |
| engine = create_engine('postgres://db_user@db_host:5432/db_name', client_encoding='utf8') | |
| Session = sessionmaker(bind=engine) | |
| session = Session() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import gc | |
| # inspiration: https://djangosnippets.org/snippets/1949/ | |
| def queryset_memreduce_iterator(queryset, field='pk', queryset_filter='pk__gt', | |
| ordering_function=lambda x, y: x < y, | |
| chunksize=1000): | |
| ''''' | |
| Iterate over a Django Queryset ordered by field (kwarg) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jitsu deploy | |
| info: Welcome to Nodejitsu curiousest | |
| info: jitsu v0.12.10-1, node v0.8.21 | |
| info: It worked if it ends with Nodejitsu ok | |
| info: Executing command deploy | |
| warn: | |
| warn: The package.json file is missing required fields: | |
| warn: | |
| warn: Subdomain name | |
| warn: |