Types¶
This module contains type definitions, enums, and data classes used throughout PIPolars.
Type Aliases¶
- pipolars.core.types.PITimestamp¶
Type alias for timestamps:
Union[datetime, str, AFTime]Accepts: - Python
datetimeobjects - PI time expression strings (e.g.,"*-1d","t") -AFTimeobjects
- pipolars.core.types.TagName¶
Type alias for tag names:
str
- pipolars.core.types.TagPath¶
Type alias for AF attribute paths:
str
AFTime Class¶
- class pipolars.AFTime[source]¶
Bases:
objectRepresents a PI AF Time specification.
Supports both absolute timestamps and relative time expressions like “*” (now), “*-1d” (1 day ago), “t” (today), etc.
Examples
>>> AFTime("*") # Now >>> AFTime("*-1h") # 1 hour ago >>> AFTime("2024-01-01") # Absolute date >>> AFTime("t") # Today at midnight >>> AFTime("y") # Yesterday at midnight
Class Methods
- classmethod ago(**kwargs)[source]¶
Create an AFTime relative to now.
- Parameters:
**kwargs (int) – Time units (days, hours, minutes, seconds)
- Returns:
AFTime representing the relative time.
- Return type:
Example
>>> AFTime.ago(days=1, hours=2) # 1 day and 2 hours ago
- classmethod ago(**kwargs)[source]¶
Create an AFTime relative to now.
- Parameters:
**kwargs (int) – Time units (days, hours, minutes, seconds)
- Returns:
AFTime representing the relative time.
- Return type:
Example
>>> AFTime.ago(days=1, hours=2) # 1 day and 2 hours ago
- __init__(expression)¶
Usage:
from pipolars import AFTime
# Create from expression
now = AFTime("*")
yesterday = AFTime("y")
# Use class methods
now = AFTime.now()
today = AFTime.today()
one_hour_ago = AFTime.ago(hours=1)
complex_ago = AFTime.ago(days=1, hours=6, minutes=30)
# From datetime
from datetime import datetime
dt = datetime(2024, 1, 15, 12, 0)
af_time = AFTime.from_datetime(dt)
PIValue Class¶
TimeRange Class¶
- class pipolars.core.types.TimeRange[source]¶
Bases:
objectRepresents a time range for PI queries.
- start¶
Start time of the range
- Type:
- end¶
End time of the range
- Type:
Class Methods
- classmethod last(**kwargs)[source]¶
Create a time range from now to the past.
Example
>>> TimeRange.last(days=7) # Last 7 days >>> TimeRange.last(hours=24) # Last 24 hours
- classmethod last(**kwargs)[source]¶
Create a time range from now to the past.
Example
>>> TimeRange.last(days=7) # Last 7 days >>> TimeRange.last(hours=24) # Last 24 hours
- __init__(start, end)¶
Usage:
from pipolars.core.types import TimeRange, AFTime
# Create time range
time_range = TimeRange(
start=AFTime("*-1d"),
end=AFTime("*")
)
# Use convenience methods
last_week = TimeRange.last(days=7)
today = TimeRange.today()
PointConfig Class¶
SummaryResult Class¶
Enumerations¶
RetrievalMode¶
- class pipolars.RetrievalMode[source]¶
-
Data retrieval modes for PI Point queries.
These modes determine how data is retrieved from the PI Data Archive.
Data retrieval modes for PI queries.
- RECORDED = "recorded"¶
Return actual recorded values as stored in the archive.
- INTERPOLATED = "interpolated"¶
Return interpolated values at regular intervals.
- PLOT = "plot"¶
Return values optimized for plotting (reduced data density).
- SUMMARY = "summary"¶
Return summary statistics (min, max, avg, etc.).
- COMPRESSED = "compressed"¶
Return compressed data using exception/compression settings.
- RECORDED = 'recorded'¶
Return actual recorded values as stored in the archive.
- INTERPOLATED = 'interpolated'¶
Return interpolated values at regular intervals.
- PLOT = 'plot'¶
Return values optimized for plotting (reduced data density).
- SUMMARY = 'summary'¶
Return summary statistics (min, max, avg, etc.).
- COMPRESSED = 'compressed'¶
Return compressed data using exception/compression settings.
- __new__(value)¶
SummaryType¶
- class pipolars.SummaryType[source]¶
Bases:
IntEnumSummary calculation types for PI data.
These correspond to OSIsoft AF SDK AFSummaryTypes enumeration.
Summary calculation types for PI data.
- TOTAL = 1¶
Sum of values.
- AVERAGE = 2¶
Time-weighted average.
- MINIMUM = 4¶
Minimum value.
- MAXIMUM = 8¶
Maximum value.
- RANGE = 16¶
Range (max - min).
- STD_DEV = 32¶
Standard deviation.
- POP_STD_DEV = 64¶
Population standard deviation.
- COUNT = 128¶
Number of values.
- PERCENT_GOOD = 8192¶
Percentage of good values.
- NONE = 0¶
- TOTAL = 1¶
- AVERAGE = 2¶
- MINIMUM = 4¶
- MAXIMUM = 8¶
- RANGE = 16¶
- STD_DEV = 32¶
- POP_STD_DEV = 64¶
- COUNT = 128¶
- PERCENT_GOOD = 8192¶
- TOTAL_WITH_UOM = 16384¶
- ALL = 24831¶
- ALL_FOR_NON_NUMERIC = 8320¶
- __new__(value)¶
Usage:
from pipolars import SummaryType
# Single summary type
df = client.summary("TAG", "*-1d", "*", summary_types=SummaryType.AVERAGE)
# Multiple summary types
df = client.summary(
"TAG", "*-1d", "*",
summary_types=[
SummaryType.AVERAGE,
SummaryType.MINIMUM,
SummaryType.MAXIMUM,
SummaryType.STD_DEV
]
)
TimestampMode¶
- class pipolars.TimestampMode[source]¶
-
Timestamp handling modes for summary calculations.
Timestamp handling modes for summary calculations.
- AUTO = "auto"¶
Automatically determine timestamp placement.
- START = "start"¶
Use interval start time.
- END = "end"¶
Use interval end time.
- MIDDLE = "middle"¶
Use interval midpoint.
- AUTO = 'auto'¶
Automatically determine timestamp placement.
- START = 'start'¶
Use interval start time.
- END = 'end'¶
Use interval end time.
- MIDDLE = 'middle'¶
Use interval midpoint.
- __new__(value)¶
DataQuality¶
- class pipolars.DataQuality[source]¶
Bases:
IntEnumPI data quality flags.
These flags indicate the quality and reliability of PI values.
PI data quality flags.
- GOOD = 0¶
Value is good and reliable.
- SUBSTITUTED = 1¶
Value was manually substituted.
- QUESTIONABLE = 2¶
Value quality is questionable.
- BAD = 3¶
Value is bad or unreliable.
- NO_DATA = 4¶
No data available for the requested time.
- CALC_FAILED = 5¶
Calculation failed to produce a value.
- GOOD = 0¶
Value is good and reliable.
- SUBSTITUTED = 1¶
Value was manually substituted.
- QUESTIONABLE = 2¶
Value quality is questionable.
- BAD = 3¶
Value is bad or unreliable.
- NO_DATA = 4¶
No data available for the requested time.
- CALC_FAILED = 5¶
Calculation failed to produce a value.
- __new__(value)¶
DigitalState¶
- class pipolars.core.types.DigitalState[source]¶
-
Common PI digital states.
- NO_DATA = 'No Data'¶
- BAD_INPUT = 'Bad Input'¶
- CALC_OFF = 'Calc Off'¶
- COMM_FAIL = 'Comm Fail'¶
- CONFIGURE = 'Configure'¶
- I_O_TIMEOUT = 'I/O Timeout'¶
- NO_SAMPLE = 'No Sample'¶
- SHUTDOWN = 'Shutdown'¶
- SCAN_OFF = 'Scan Off'¶
- OVER_RANGE = 'Over Range'¶
- UNDER_RANGE = 'Under Range'¶
- __new__(value)¶
PointType¶
BoundaryType¶
- class pipolars.core.types.BoundaryType[source]¶
-
Boundary handling for time range queries.
- INSIDE = 'inside'¶
Only include values strictly inside the time range.
- OUTSIDE = 'outside'¶
Include boundary values outside the range.
- INTERPOLATED = 'interpolated'¶
Interpolate values at boundaries.
- __new__(value)¶
Schema Definitions¶
PIPolars defines Polars schemas for consistent DataFrame structures:
- pipolars.core.types.PI_VALUE_SCHEMA¶
Schema for single-tag value DataFrames:
{ "timestamp": pl.Datetime("us", "UTC"), "value": pl.Float64(), "quality": pl.Int8(), }
- pipolars.core.types.PI_VALUE_WITH_TAG_SCHEMA¶
Schema for multi-tag value DataFrames:
{ "tag": pl.Utf8(), "timestamp": pl.Datetime("us", "UTC"), "value": pl.Float64(), "quality": pl.Int8(), }
- pipolars.core.types.SUMMARY_SCHEMA¶
Schema for summary DataFrames:
{ "tag": pl.Utf8(), "start": pl.Datetime("us", "UTC"), "end": pl.Datetime("us", "UTC"), "average": pl.Float64(), "minimum": pl.Float64(), "maximum": pl.Float64(), "total": pl.Float64(), "count": pl.Int64(), "std_dev": pl.Float64(), "percent_good": pl.Float64(), }
See Also¶
Time Expressions - Time expression guide
Working with Polars DataFrames - DataFrame output guide