Skip to content

Commit 26cb4ea

Browse files
authored
Clean up neo4j.time public exports (#1191)
Make undocumented internal constants, helper functions, and other items in `neo4j.time` private: * `DATE_ISO_PATTERN` * `TIME_ISO_PATTERN` * `DURATION_ISO_PATTERN` * `NANO_SECONDS` * `AVERAGE_SECONDS_IN_MONTH` * `AVERAGE_SECONDS_IN_DAY` * `FORMAT_F_REPLACE` * `IS_LEAP_YEAR` * `DAYS_IN_YEAR` * `DAYS_IN_MONTH` * `round_half_to_even` * `symmetric_divmod` * `DateTimeType` * `DateType` * `TimeType` * all other indirectly exposed items from imports (e.g. `re` as `neo4j.time.re`) Deprecate `ClockTime` and its accessors * For each `neo4j.time.Date`, `neo4j.time.DateTime`, `neo4j.time.Time` * `from_clock_time` and `to_clock_time` methods * `neo4j.time.ClockTime` itself
1 parent 33c337c commit 26cb4ea

File tree

13 files changed

+535
-291
lines changed

13 files changed

+535
-291
lines changed

CHANGELOG.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ See also https://github.com/neo4j/neo4j-python-driver/wiki for a full changelog.
8181
- Remove `ExperimentalWarning` and turn the few left instances of it into `PreviewWarning`.
8282
- Deprecate importing `PreviewWarning` from `neo4j`.
8383
Import it from `neo4j.warnings` instead.
84-
- Make undocumented internal constants and helper functions private:
84+
- Make undocumented internal constants, helper functions, and other items private:
8585
- `neo4j.api`
8686
- `DRIVER_BOLT`
8787
- `DRIVER_NEO4J`
@@ -98,6 +98,23 @@ See also https://github.com/neo4j/neo4j-python-driver/wiki for a full changelog.
9898
- `ERROR_REWRITE_MAP`
9999
- `client_errors`
100100
- `transient_errors`
101+
- `neo4j.time`
102+
- `DATE_ISO_PATTERN`
103+
- `TIME_ISO_PATTERN`
104+
- `DURATION_ISO_PATTERN`
105+
- `NANO_SECONDS`
106+
- `AVERAGE_SECONDS_IN_MONTH`
107+
- `AVERAGE_SECONDS_IN_DAY`
108+
- `FORMAT_F_REPLACE`
109+
- `IS_LEAP_YEAR`
110+
- `DAYS_IN_YEAR`
111+
- `DAYS_IN_MONTH`
112+
- `round_half_to_even`
113+
- `symmetric_divmod`
114+
- `DateTimeType`
115+
- `DateType`
116+
- `TimeType`
117+
- all other indirectly exposed items from imports (e.g. `re` as `neo4j.time.re`)
101118
- `neo4j.spatial`
102119
- `hydrate_point`
103120
- `dehydrate_point`
@@ -111,6 +128,10 @@ See also https://github.com/neo4j/neo4j-python-driver/wiki for a full changelog.
111128
- `.default_host`
112129
- `.default_port`
113130
- `.default_target`
131+
- Deprecate ClockTime and its accessors
132+
- For each `neo4j.time.Date`, `neo4j.time.DateTime`, `neo4j.time.Time`
133+
- `from_clock_time` and `to_clock_time` methods
134+
- `neo4j.time.ClockTime` itself
114135
- Raise `ConfigurationError` instead of ignoring the routing context (URI query parameters) when creating a direct
115136
driver ("bolt[+s[sc]]://" scheme).
116137
- Change behavior of closed drivers:

src/neo4j/_codec/hydration/v1/temporal.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
pd,
2626
)
2727
from ....time import (
28+
_NANO_SECONDS,
2829
Date,
2930
DateTime,
3031
Duration,
3132
MAX_YEAR,
3233
MIN_YEAR,
33-
NANO_SECONDS,
3434
Time,
3535
)
3636
from ...packstream import Structure
@@ -170,8 +170,8 @@ def seconds_and_nanoseconds(dt):
170170
if isinstance(dt, datetime):
171171
dt = DateTime.from_native(dt)
172172
zone_epoch = DateTime(1970, 1, 1, tzinfo=dt.tzinfo)
173-
dt_clock_time = dt.to_clock_time()
174-
zone_epoch_clock_time = zone_epoch.to_clock_time()
173+
dt_clock_time = dt._to_clock_time()
174+
zone_epoch_clock_time = zone_epoch._to_clock_time()
175175
t = dt_clock_time - zone_epoch_clock_time
176176
return t.seconds, t.nanoseconds
177177

@@ -226,7 +226,8 @@ def dehydrate_np_datetime(value):
226226
)
227227
seconds = value.astype(np.dtype("datetime64[s]")).astype(int)
228228
nanoseconds = (
229-
value.astype(np.dtype("datetime64[ns]")).astype(int) % NANO_SECONDS
229+
value.astype(np.dtype("datetime64[ns]")).astype(int)
230+
% _NANO_SECONDS
230231
)
231232
return Structure(b"d", seconds, nanoseconds)
232233

src/neo4j/_codec/hydration/v2/temporal.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121

2222
from ...._optional_deps import pd
2323
from ....time import (
24+
_NANO_SECONDS,
2425
Date,
2526
DateTime,
26-
NANO_SECONDS,
2727
Time,
2828
)
2929
from ...packstream import Structure
@@ -74,8 +74,8 @@ def seconds_and_nanoseconds(dt):
7474
dt = DateTime.from_native(dt)
7575
dt = dt.astimezone(pytz.UTC)
7676
utc_epoch = DateTime(1970, 1, 1, tzinfo=pytz.UTC)
77-
dt_clock_time = dt.to_clock_time()
78-
utc_epoch_clock_time = utc_epoch.to_clock_time()
77+
dt_clock_time = dt._to_clock_time()
78+
utc_epoch_clock_time = utc_epoch._to_clock_time()
7979
t = dt_clock_time - utc_epoch_clock_time
8080
return t.seconds, t.nanoseconds
8181

@@ -119,7 +119,7 @@ def dehydrate_pandas_datetime(value):
119119
:type value: pandas.Timestamp
120120
:returns:
121121
"""
122-
seconds, nanoseconds = divmod(value.value, NANO_SECONDS)
122+
seconds, nanoseconds = divmod(value.value, _NANO_SECONDS)
123123

124124
tz = value.tzinfo
125125
if tz is None:

0 commit comments

Comments
 (0)