def write_object_to_file(self,<EOL>query_results,<EOL>filename,<EOL>fmt="<STR_LIT>",<EOL>coerce_to_timestamp=False,<EOL>record_time_added=False):
fmt = fmt.lower()<EOL>if fmt not in ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>raise ValueError("<STR_LIT>".format(fmt))<EOL><DEDENT>df = pd.DataFrame.from_records(query_results, exclude=["<STR_LIT>"])<EOL>df.columns = [column.lower() for column in df.columns]<EOL>if coerce_to_timestamp and df.shape[<NUM_LIT:0>] > <NUM_LIT:0>:<EOL><INDENT>object_name = query_results[<NUM_LIT:0>]['<STR_LIT>']['<STR_LIT:type>']<EOL>self.log.info("<STR_LIT>", object_name)<EOL>schema = self.describe_object(object_name)<EOL>possible_timestamp_cols = [<EOL>field['<STR_LIT:name>'].lower()<EOL>for field in schema['<STR_LIT>']<EOL>if field['<STR_LIT:type>'] in ["<STR_LIT:date>", "<STR_LIT>"] and field['<STR_LIT:name>'].lower() in df.columns<EOL>]<EOL>df[possible_timestamp_cols] = df[possible_timestamp_cols].apply(self._to_timestamp)<EOL><DEDENT>if record_time_added:<EOL><INDENT>fetched_time = time.time()<EOL>df["<STR_LIT>"] = fetched_time<EOL><DEDENT>if fmt == "<STR_LIT>":<EOL><INDENT>self.log.info("<STR_LIT>")<EOL>possible_strings = df.columns[df.dtypes == "<STR_LIT:object>"]<EOL>df[possible_strings] = df[possible_strings].apply(<EOL>lambda x: x.str.replace("<STR_LIT:\r\n>", "<STR_LIT>").str.replace("<STR_LIT:\n>", "<STR_LIT>")<EOL>)<EOL>df.to_csv(filename, index=False)<EOL><DEDENT>elif fmt == "<STR_LIT>":<EOL><INDENT>df.to_json(filename, "<STR_LIT>", date_unit="<STR_LIT:s>")<EOL><DEDENT>elif fmt == "<STR_LIT>":<EOL><INDENT>df.to_json(filename, "<STR_LIT>", lines=True, date_unit="<STR_LIT:s>")<EOL><DEDENT>return df<EOL>
Write query results to file.

Acceptable formats are:
    - csv:
        comma-separated-values file. This is the default format.
    - json:
        JSON array. Each element in the array is a different row.
    - ndjson:
        JSON array but each element is new-line delimited instead of comma delimited like in `json`

This requires a significant amount of cleanup.
Pandas doesn't handle output to CSV and json in a uniform way.
This is especially painful for datetime types.
Pandas wants to write them as strings in CSV, but as millisecond Unix timestamps.

By default, this function will try and leave all values as they are represented in Salesforce.
You use the `coerce_to_timestamp` flag to force all datetimes to become Unix timestamps (UTC).
This is can be greatly beneficial as it will make all of your datetime fields look the same,
and makes it easier to work with in other database environments

:param query_results: the results from a SQL query
:type query_results: list of dict
:param filename: the name of the file where the data should be dumped to
:type filename: str
:param fmt: the format you want the output in. Default:  'csv'
:type fmt: str
:param coerce_to_timestamp: True if you want all datetime fields to be converted into Unix timestamps.
    False if you want them to be left in the same format as they were in Salesforce.
    Leaving the value as False will result in datetimes being strings. Default: False
:type coerce_to_timestamp: bool
:param record_time_added: True if you want to add a Unix timestamp field
    to the resulting data that marks when the data was fetched from Salesforce. Default: False
:type record_time_added: bool
:return: the dataframe that gets written to the file.
:rtype: pd.Dataframe