MCPcopy
hub / github.com/pandas-dev/pandas / create_and_load_postgres_datetz

Function create_and_load_postgres_datetz

pandas/tests/io/test_sql.py:330–372  ·  view source on GitHub ↗
(conn)

Source from the content-addressed store, hash-verified

328
329
330def create_and_load_postgres_datetz(conn):
331 from sqlalchemy import (
332 Column,
333 DateTime,
334 MetaData,
335 Table,
336 insert,
337 )
338 from sqlalchemy.engine import Engine
339
340 metadata = MetaData()
341 datetz = Table("datetz", metadata, Column("DateColWithTz", DateTime(timezone=True)))
342 datetz_data = [
343 {
344 "DateColWithTz": "2000-01-01 00:00:00-08:00",
345 },
346 {
347 "DateColWithTz": "2000-06-01 00:00:00-07:00",
348 },
349 ]
350 stmt = insert(datetz).values(datetz_data)
351 if isinstance(conn, Engine):
352 with conn.connect() as conn:
353 with conn.begin():
354 datetz.drop(conn, checkfirst=True)
355 datetz.create(bind=conn)
356 conn.execute(stmt)
357 else:
358 with conn.begin():
359 datetz.drop(conn, checkfirst=True)
360 datetz.create(bind=conn)
361 conn.execute(stmt)
362
363 # "2000-01-01 00:00:00-08:00" should convert to
364 # "2000-01-01 08:00:00"
365 # "2000-06-01 00:00:00-07:00" should convert to
366 # "2000-06-01 07:00:00"
367 # GH 6415
368 expected_data = [
369 Timestamp("2000-01-01 08:00:00", tz="UTC"),
370 Timestamp("2000-06-01 07:00:00", tz="UTC"),
371 ]
372 return Series(expected_data, name="DateColWithTz").astype("M8[us, UTC]")
373
374
375def check_iris_frame(frame: DataFrame):

Calls 8

SeriesClass · 0.90
TableClass · 0.85
ColumnClass · 0.85
valuesMethod · 0.45
dropMethod · 0.45
createMethod · 0.45
executeMethod · 0.45
astypeMethod · 0.45

Tested by

no test coverage detected