<commit_before># -*- coding: utf-8 -*-
import getpass
import warnings
import os
import sys
import stat
import pandas as pd
import sqlalchemy as sa

from sys import version_info
py3 = version_info[0] > 2

if not py3:
    input = raw_input  # use raw_input in python 2
    PermissionError = Exception
    FileNotFoundError = Exception

# Sane defaults
WRDS_POSTGRES_HOST = 'wrds-pgdata.wharton.upenn.edu'
WRDS_POSTGRES_PORT = 9737
WRDS_POSTGRES_DB = 'wrds'

class NotSubscribedError(PermissionError):
    pass

class SchemaNotFoundError(FileNotFoundError):
    pass

class Connection(object):
    def __init__(self, **kwargs):
        """
        Establish the connection to the database. 

        Optionally, the user may specify connection parameters:
            *wrds_hostname*: WRDS database hostname
            *wrds_port*: database connection port number
            *wrds_dbname*: WRDS database name
            *wrds_username*: WRDS username 

        The constructor will use the .pgpass file if it exists. 
        If not, it will ask the user for a username and password.
        It will also direct the user to information on setting up .pgpass.

        Additionally, creating the instance will load a list of schemas 
          the user has permission to access.

        :return: None

        Usage::
        >>> db = wrds.Connection()
        Loading library list...
        Done
        """
        self._password = ""
        # If user passed in any of these parameters, override defaults.
        self._username = (kwargs['wrds_username'] 
            if 'wrds_username' in kwargs else None)
        self._hostname = (kwargs['wrds_hostname'] 
            if 'wrds_hostname' in kwargs else WRDS_POSTGRES_HOST)
        self._port = (kwargs['wrds_port'] 
            if 'wrds_port' in kwargs else WRDS_POSTGRES_PORT)
        self._dbname = (kwargs['wrds_dbname'] 
            if 'wrds_dbname' in kwargs else WRDS_POSTGRES_DB)
        # If username was passed in, the URI is different.
        if (self._username):
            pguri = 'postgresql://{usr}@{host}:{port}/{dbname}'
            self.engine = sa.create_engine(
                pguri.format(
                    usr=self._username,
                    host=self._hostname,
                    port=self._port,
                    dbname=self._dbname),
                connect_args={'sslmode': 'require'}) 
        # No username passed in, but other parameters might have been.
        else:<commit_msg>Use kwargs.get() instead of the ternary operator<commit_after># -*- coding: utf-8 -*-
import getpass
import warnings
import os
import sys
import stat
import pandas as pd
import sqlalchemy as sa

from sys import version_info
py3 = version_info[0] > 2

if not py3:
    input = raw_input  # use raw_input in python 2
    PermissionError = Exception
    FileNotFoundError = Exception

# Sane defaults
WRDS_POSTGRES_HOST = 'wrds-pgdata.wharton.upenn.edu'
WRDS_POSTGRES_PORT = 9737
WRDS_POSTGRES_DB = 'wrds'

class NotSubscribedError(PermissionError):
    pass

class SchemaNotFoundError(FileNotFoundError):
    pass

class Connection(object):
    def __init__(self, **kwargs):
        """
        Establish the connection to the database. 

        Optionally, the user may specify connection parameters:
            *wrds_hostname*: WRDS database hostname
            *wrds_port*: database connection port number
            *wrds_dbname*: WRDS database name
            *wrds_username*: WRDS username 

        The constructor will use the .pgpass file if it exists. 
        If not, it will ask the user for a username and password.
        It will also direct the user to information on setting up .pgpass.

        Additionally, creating the instance will load a list of schemas 
          the user has permission to access.

        :return: None

        Usage::
        >>> db = wrds.Connection()
        Loading library list...
        Done
        """
        self._password = ""
        # If user passed in any of these parameters, override defaults.
        self._username = kwargs.get('wrds_username', None)
        self._hostname = kwargs.get('wrds_hostname', WRDS_POSTGRES_HOST)
        self._port = kwargs.get('wrds_port', WRDS_POSTGRES_PORT)
        self._dbname = kwargs.get('wrds_dbname', WRDS_POSTGRES_DB)
        # If username was passed in, the URI is different.
        if (self._username):
            pguri = 'postgresql://{usr}@{host}:{port}/{dbname}'
            self.engine = sa.create_engine(
                pguri.format(
                    usr=self._username,
                    host=self._hostname,
                    port=self._port,
                    dbname=self._dbname),
                connect_args={'sslmode': 'require'}) 
        # No username passed in, but other parameters might have been.
        else:
{'fraction_non_alphanumeric': 0.07937823834196892, 'fraction_numerical': 0.004145077720207254, 'mean_word_length': 2.300957592339261, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1486587', 'n_tokens_mistral': 1365, 'n_tokens_neox': 1323, 'n_words': 435}