Skip to content

Commit 0b62292

Browse files
committed
REF: Standardize DBN enums
1 parent 168bc2d commit 0b62292

File tree

12 files changed

+1344
-667
lines changed

12 files changed

+1344
-667
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
# Changelog
22

3-
## 0.37.2 - TBD
3+
## 0.38.0 - TBD
4+
5+
### Breaking changes
6+
- Renamed `Compression::ZStd` to `Zstd` for consistency
7+
- Removed duplicated `flags` constants in `enums` module. Use the top-level `flags`
8+
constants instead
9+
- Renamed to `SCHEMA_COUNT` to `Schema::COUNT`
410

511
### Bug fixes
612
- Relaxed requirement of `input_version` parameter to the Python `Transcoder` to only
713
be required when transcoding to CSV without `Metadata`, where previously it was always
814
required when transcoding data without `Metadata`
15+
- Added missing methods to Python for `StatUpdateAction` enum
916

1017
## 0.37.1 - 2025-07-15
1118

python/python/databento_dbn/_lib.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ class Encoding(Enum):
455455
@classmethod
456456
def from_str(cls, value: str) -> Encoding: ...
457457
@classmethod
458+
def from_int(cls, value: int) -> Encoding: ...
459+
@classmethod
458460
def variants(cls) -> Iterable[Encoding]: ...
459461

460462
class Compression(Enum):
@@ -474,6 +476,8 @@ class Compression(Enum):
474476
@classmethod
475477
def from_str(cls, value: str) -> Compression: ...
476478
@classmethod
479+
def from_int(cls, value: int) -> Compression: ...
480+
@classmethod
477481
def variants(cls) -> Iterable[Compression]: ...
478482

479483
class SecurityUpdateAction(Enum):
@@ -909,8 +913,6 @@ class Metadata(SupportsBytes):
909913
version: int | None = None,
910914
) -> None: ...
911915
def __bytes__(self) -> bytes: ...
912-
def __eq__(self, other) -> bool: ...
913-
def __ne__(self, other) -> bool: ...
914916
@property
915917
def version(self) -> int:
916918
"""
@@ -1178,8 +1180,6 @@ class Record(SupportsBytes):
11781180
_timestamp_fields: ClassVar[list[str]]
11791181

11801182
def __bytes__(self) -> bytes: ...
1181-
def __eq__(self, other) -> bool: ...
1182-
def __ne__(self, other) -> bool: ...
11831183
@property
11841184
def hd(self) -> RecordHeader:
11851185
"""

rust/dbn-cli/src/lib.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl Args {
222222
/// aren't already explicitly set.
223223
pub fn infer_encoding(args: &Args) -> anyhow::Result<(Encoding, Compression, u8)> {
224224
let compression = if args.zstd {
225-
Compression::ZStd
225+
Compression::Zstd
226226
} else {
227227
Compression::None
228228
};
@@ -234,19 +234,19 @@ pub fn infer_encoding(args: &Args) -> anyhow::Result<(Encoding, Compression, u8)
234234
OutputEncoding::Infer => {
235235
if let Some(output) = args.output.as_ref().map(|o| o.to_string_lossy()) {
236236
if output.ends_with(".dbn.zst") {
237-
Ok((Encoding::Dbn, Compression::ZStd, 0))
237+
Ok((Encoding::Dbn, Compression::Zstd, 0))
238238
} else if output.ends_with(".dbn") {
239239
Ok((Encoding::Dbn, Compression::None, 0))
240240
} else if output.ends_with(".csv.zst") {
241-
Ok((Encoding::Csv, Compression::ZStd, b','))
241+
Ok((Encoding::Csv, Compression::Zstd, b','))
242242
} else if output.ends_with(".csv") {
243243
Ok((Encoding::Csv, Compression::None, b','))
244244
} else if output.ends_with(".tsv.zst") || output.ends_with(".xls.zst") {
245-
Ok((Encoding::Csv, Compression::ZStd, b'\t'))
245+
Ok((Encoding::Csv, Compression::Zstd, b'\t'))
246246
} else if output.ends_with(".tsv") || output.ends_with(".xls") {
247247
Ok((Encoding::Csv, Compression::None, b'\t'))
248248
} else if output.ends_with(".json.zst") {
249-
Ok((Encoding::Json, Compression::ZStd, 0))
249+
Ok((Encoding::Json, Compression::Zstd, 0))
250250
} else if output.ends_with(".json") {
251251
Ok((Encoding::Json, Compression::None, 0))
252252
} else {
@@ -321,15 +321,15 @@ mod tests {
321321
b'\t'
322322
)]
323323
#[case(false, false, false, true, false, Encoding::Dbn, Compression::None, 0)]
324-
#[case(true, false, false, false, true, Encoding::Json, Compression::ZStd, 0)]
324+
#[case(true, false, false, false, true, Encoding::Json, Compression::Zstd, 0)]
325325
#[case(
326326
false,
327327
true,
328328
false,
329329
false,
330330
true,
331331
Encoding::Csv,
332-
Compression::ZStd,
332+
Compression::Zstd,
333333
b','
334334
)]
335335
#[case(
@@ -339,10 +339,10 @@ mod tests {
339339
false,
340340
true,
341341
Encoding::Csv,
342-
Compression::ZStd,
342+
Compression::Zstd,
343343
b'\t'
344344
)]
345-
#[case(false, false, false, true, true, Encoding::Dbn, Compression::ZStd, 0)]
345+
#[case(false, false, false, true, true, Encoding::Dbn, Compression::Zstd, 0)]
346346
fn test_infer_encoding_and_compression_explicit(
347347
#[case] json: bool,
348348
#[case] csv: bool,
@@ -370,11 +370,11 @@ mod tests {
370370
#[case("out.tsv", Encoding::Csv, Compression::None, b'\t')]
371371
#[case("out.xls", Encoding::Csv, Compression::None, b'\t')]
372372
#[case("out.dbn", Encoding::Dbn, Compression::None, 0)]
373-
#[case("out.json.zst", Encoding::Json, Compression::ZStd, 0)]
374-
#[case("out.csv.zst", Encoding::Csv, Compression::ZStd, b',')]
375-
#[case("out.tsv.zst", Encoding::Csv, Compression::ZStd, b'\t')]
376-
#[case("out.xls.zst", Encoding::Csv, Compression::ZStd, b'\t')]
377-
#[case("out.dbn.zst", Encoding::Dbn, Compression::ZStd, 0)]
373+
#[case("out.json.zst", Encoding::Json, Compression::Zstd, 0)]
374+
#[case("out.csv.zst", Encoding::Csv, Compression::Zstd, b',')]
375+
#[case("out.tsv.zst", Encoding::Csv, Compression::Zstd, b'\t')]
376+
#[case("out.xls.zst", Encoding::Csv, Compression::Zstd, b'\t')]
377+
#[case("out.dbn.zst", Encoding::Dbn, Compression::Zstd, 0)]
378378
fn test_infer_encoding_and_compression_inference(
379379
#[case] output: &str,
380380
#[case] exp_enc: Encoding,

rust/dbn/src/decode/dbn/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ mod tests {
595595
let mut buffer = Vec::new();
596596

597597
Encoder::new(
598-
DynWriter::new(&mut buffer, Compression::ZStd)?,
598+
DynWriter::new(&mut buffer, Compression::Zstd)?,
599599
&file_metadata,
600600
)?
601601
.encode_records(decoded_records.as_slice())?;

rust/dbn/src/decode/dyn_decoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ where
7878
Compression::None => Ok(Self(DynDecoderImpl::Dbn(
7979
dbn::Decoder::with_upgrade_policy(reader, upgrade_policy)?,
8080
))),
81-
Compression::ZStd => Ok(Self(DynDecoderImpl::ZstdDbn(
81+
Compression::Zstd => Ok(Self(DynDecoderImpl::ZstdDbn(
8282
dbn::Decoder::with_upgrade_policy(
8383
::zstd::stream::Decoder::with_buffer(reader)
8484
.map_err(|e| crate::Error::io(e, "creating zstd decoder"))?,

rust/dbn/src/decode/dyn_reader.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::Compression;
88

99
use super::{zstd, SkipBytes};
1010

11-
/// Type for runtime polymorphism over whether decoding uncompressed or ZStd-compressed
11+
/// Type for runtime polymorphism over whether decoding uncompressed or Zstd-compressed
1212
/// DBN records. Implements [`std::io::Write`].
1313
pub struct DynReader<'a, R>(DynReaderImpl<'a, R>)
1414
where
@@ -19,7 +19,7 @@ where
1919
R: io::BufRead,
2020
{
2121
Uncompressed(R),
22-
ZStd(::zstd::stream::Decoder<'a, R>),
22+
Zstd(::zstd::stream::Decoder<'a, R>),
2323
}
2424

2525
impl<R> DynReader<'_, BufReader<R>>
@@ -60,7 +60,7 @@ where
6060
pub fn with_buffer(reader: R, compression: Compression) -> crate::Result<Self> {
6161
match compression {
6262
Compression::None => Ok(Self(DynReaderImpl::Uncompressed(reader))),
63-
Compression::ZStd => Ok(Self(DynReaderImpl::ZStd(
63+
Compression::Zstd => Ok(Self(DynReaderImpl::Zstd(
6464
::zstd::stream::Decoder::with_buffer(reader)
6565
.map_err(|e| crate::Error::io(e, "creating zstd decoder"))?,
6666
))),
@@ -77,7 +77,7 @@ where
7777
.fill_buf()
7878
.map_err(|e| crate::Error::io(e, "creating buffer to infer encoding"))?;
7979
if zstd::starts_with_prefix(first_bytes) {
80-
Ok(Self(DynReaderImpl::ZStd(
80+
Ok(Self(DynReaderImpl::Zstd(
8181
::zstd::stream::Decoder::with_buffer(reader)
8282
.map_err(|e| crate::Error::io(e, "creating zstd decoder"))?,
8383
)))
@@ -90,15 +90,15 @@ where
9090
pub fn get_mut(&mut self) -> &mut R {
9191
match &mut self.0 {
9292
DynReaderImpl::Uncompressed(reader) => reader,
93-
DynReaderImpl::ZStd(reader) => reader.get_mut(),
93+
DynReaderImpl::Zstd(reader) => reader.get_mut(),
9494
}
9595
}
9696

9797
/// Returns a reference to the inner reader.
9898
pub fn get_ref(&self) -> &R {
9999
match &self.0 {
100100
DynReaderImpl::Uncompressed(reader) => reader,
101-
DynReaderImpl::ZStd(reader) => reader.get_ref(),
101+
DynReaderImpl::Zstd(reader) => reader.get_ref(),
102102
}
103103
}
104104
}
@@ -130,7 +130,7 @@ where
130130
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
131131
match &mut self.0 {
132132
DynReaderImpl::Uncompressed(r) => r.read(buf),
133-
DynReaderImpl::ZStd(r) => r.read(buf),
133+
DynReaderImpl::Zstd(r) => r.read(buf),
134134
}
135135
}
136136
}
@@ -145,7 +145,7 @@ where
145145
DynReaderImpl::Uncompressed(reader) => {
146146
reader.seek_relative(n_bytes as i64).map_err(handle_err)
147147
}
148-
DynReaderImpl::ZStd(reader) => {
148+
DynReaderImpl::Zstd(reader) => {
149149
let mut buf = [0; 1024];
150150
let mut remaining = n_bytes;
151151
while remaining > 0 {
@@ -231,7 +231,7 @@ mod r#async {
231231
R: io::AsyncBufReadExt + Unpin,
232232
{
233233
Uncompressed(R),
234-
ZStd(ZstdDecoder<R>),
234+
Zstd(ZstdDecoder<R>),
235235
}
236236

237237
impl<R> DynReader<BufReader<R>>
@@ -265,7 +265,7 @@ mod r#async {
265265
pub fn with_buffer(reader: R, compression: Compression) -> Self {
266266
match compression {
267267
Compression::None => Self(DynReaderImpl::Uncompressed(reader)),
268-
Compression::ZStd => Self(DynReaderImpl::ZStd(ZstdDecoder::new(reader))),
268+
Compression::Zstd => Self(DynReaderImpl::Zstd(ZstdDecoder::new(reader))),
269269
}
270270
}
271271

@@ -279,7 +279,7 @@ mod r#async {
279279
.await
280280
.map_err(|e| crate::Error::io(e, "creating buffer to infer encoding"))?;
281281
Ok(if super::zstd::starts_with_prefix(first_bytes) {
282-
Self(DynReaderImpl::ZStd(zstd_decoder(reader)))
282+
Self(DynReaderImpl::Zstd(zstd_decoder(reader)))
283283
} else {
284284
Self(DynReaderImpl::Uncompressed(reader))
285285
})
@@ -289,15 +289,15 @@ mod r#async {
289289
pub fn get_mut(&mut self) -> &mut R {
290290
match &mut self.0 {
291291
DynReaderImpl::Uncompressed(reader) => reader,
292-
DynReaderImpl::ZStd(reader) => reader.get_mut(),
292+
DynReaderImpl::Zstd(reader) => reader.get_mut(),
293293
}
294294
}
295295

296296
/// Returns a reference to the inner reader.
297297
pub fn get_ref(&self) -> &R {
298298
match &self.0 {
299299
DynReaderImpl::Uncompressed(reader) => reader,
300-
DynReaderImpl::ZStd(reader) => reader.get_ref(),
300+
DynReaderImpl::Zstd(reader) => reader.get_ref(),
301301
}
302302
}
303303
}
@@ -339,7 +339,7 @@ mod r#async {
339339
DynReaderImpl::Uncompressed(reader) => {
340340
io::AsyncRead::poll_read(Pin::new(reader), cx, buf)
341341
}
342-
DynReaderImpl::ZStd(reader) => io::AsyncRead::poll_read(Pin::new(reader), cx, buf),
342+
DynReaderImpl::Zstd(reader) => io::AsyncRead::poll_read(Pin::new(reader), cx, buf),
343343
}
344344
}
345345
}
@@ -360,7 +360,7 @@ mod r#async {
360360
.await
361361
.map(drop)
362362
.map_err(handle_err),
363-
DynReaderImpl::ZStd(reader) => {
363+
DynReaderImpl::Zstd(reader) => {
364364
let mut buf = [0; 1024];
365365
let mut remaining = n_bytes;
366366
while remaining > 0 {

rust/dbn/src/encode/dyn_writer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::io;
33
use super::{zstd_encoder, zstd_encoder_with_clevel};
44
use crate::{Compression, Result};
55

6-
/// Type for runtime polymorphism over whether encoding uncompressed or ZStd-compressed
6+
/// Type for runtime polymorphism over whether encoding uncompressed or Zstd-compressed
77
/// DBN records. Implements [`std::io::Write`].
88
pub struct DynWriter<'a, W>(DynWriterImpl<'a, W>)
99
where
@@ -28,7 +28,7 @@ where
2828
pub fn new(writer: W, compression: Compression) -> Result<Self> {
2929
match compression {
3030
Compression::None => Ok(Self(DynWriterImpl::Uncompressed(writer))),
31-
Compression::ZStd => zstd_encoder(writer).map(|enc| Self(DynWriterImpl::Zstd(enc))),
31+
Compression::Zstd => zstd_encoder(writer).map(|enc| Self(DynWriterImpl::Zstd(enc))),
3232
}
3333
}
3434

@@ -130,7 +130,7 @@ mod r#async {
130130
Self(match compression {
131131
Compression::None => DynBufWriterImpl::Uncompressed(BufWriter::new(writer)),
132132
// async zstd always wraps the writer in a BufWriter
133-
Compression::ZStd => DynBufWriterImpl::Zstd(async_zstd_encoder(writer)),
133+
Compression::Zstd => DynBufWriterImpl::Zstd(async_zstd_encoder(writer)),
134134
})
135135
}
136136

@@ -200,7 +200,7 @@ mod r#async {
200200
pub fn new(writer: W, compression: Compression) -> Self {
201201
Self(match compression {
202202
Compression::None => DynWriterImpl::Uncompressed(writer),
203-
Compression::ZStd => DynWriterImpl::Zstd(async_zstd_encoder(writer)),
203+
Compression::Zstd => DynWriterImpl::Zstd(async_zstd_encoder(writer)),
204204
})
205205
}
206206

0 commit comments

Comments
 (0)